1 | /*********************************************************************
|
---|
2 | // created: 2012/03/01 - 14:06
|
---|
3 | // filename: PacpusUDPSocket.h
|
---|
4 | //
|
---|
5 | // author: Pierre Hudelaine
|
---|
6 | // Copyright Heudiasyc UMR UTC/CNRS 7253
|
---|
7 | //
|
---|
8 | // version: $Id: $
|
---|
9 | //
|
---|
10 | // purpose: Create network socket if needed in Pacpus
|
---|
11 | //
|
---|
12 | *********************************************************************/
|
---|
13 |
|
---|
14 | #include <qudpsocket.h>
|
---|
15 |
|
---|
16 | #include "Pacpus/kernel/Log.h"
|
---|
17 | #include "Pacpus/kernel/ComponentBase.h"
|
---|
18 | #include "Pacpus/kernel/ComponentFactory.h"
|
---|
19 |
|
---|
20 | // Export macro for PacpusSocket DLL for Windows only
|
---|
21 | #ifdef WIN32
|
---|
22 | # ifdef PACPUSSOCKET_EXPORTS
|
---|
23 | // make DLL
|
---|
24 | # define PACPUSSOCKET_API __declspec(dllexport)
|
---|
25 | # else
|
---|
26 | // use DLL
|
---|
27 | # define PACPUSSOCKET_API __declspec(dllimport)
|
---|
28 | # endif
|
---|
29 | #else
|
---|
30 | // On other platforms, simply ignore this
|
---|
31 | # define PACPUSSOCKET_API
|
---|
32 | #endif
|
---|
33 |
|
---|
34 | class QByteArray;
|
---|
35 |
|
---|
36 | namespace pacpus {
|
---|
37 |
|
---|
38 | class PACPUSSOCKET_API Client
|
---|
39 | {
|
---|
40 | public:
|
---|
41 | /// Constructor
|
---|
42 | Client();
|
---|
43 | Client(QHostAddress address, quint16 port) {address_ = address; port_ = port;};
|
---|
44 | /// Destructor
|
---|
45 | ~Client();
|
---|
46 |
|
---|
47 | QHostAddress address_;
|
---|
48 | quint16 port_;
|
---|
49 |
|
---|
50 | QHostAddress getAddress() {return address_;};
|
---|
51 | quint16 getPort() {return port_;};
|
---|
52 | };
|
---|
53 |
|
---|
54 | class PACPUSSOCKET_API PacpusUDPSocket
|
---|
55 | : public QObject
|
---|
56 | , public ComponentBase
|
---|
57 | {
|
---|
58 | Q_OBJECT
|
---|
59 |
|
---|
60 | public:
|
---|
61 | /// Constructor
|
---|
62 | PacpusUDPSocket(QString name);
|
---|
63 |
|
---|
64 | /// Destructor
|
---|
65 | ~PacpusUDPSocket();
|
---|
66 | PacpusUDPSocket * getSocket() {return this;}
|
---|
67 |
|
---|
68 | public Q_SLOTS:
|
---|
69 | /// Slot de lecture des paquets envoys pour tests
|
---|
70 | void readPendingDatagrams();
|
---|
71 |
|
---|
72 | /// Slot d'envoie des paquets
|
---|
73 | void sendDatagrams(QString frame);
|
---|
74 | void sendDatagrams(QByteArray frame);
|
---|
75 |
|
---|
76 | Q_SIGNALS:
|
---|
77 | void newDatagram(QByteArray datagram);
|
---|
78 | void newQString(QString string);
|
---|
79 |
|
---|
80 | protected:
|
---|
81 | // The 3 virtual methods relative to the ComponentBase inheritance
|
---|
82 | virtual void startActivity();
|
---|
83 | virtual void stopActivity();
|
---|
84 | virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
|
---|
85 |
|
---|
86 | virtual void addInputs();
|
---|
87 | virtual void addOutputs();
|
---|
88 |
|
---|
89 | OutputInterface<QString, PacpusUDPSocket>* udpSocketOutput_;
|
---|
90 |
|
---|
91 | QUdpSocket * udpSocket_;
|
---|
92 |
|
---|
93 | quint16 port2bind_;
|
---|
94 | quint16 port2send_;
|
---|
95 | QHostAddress address2send_;
|
---|
96 | QString socketType_;
|
---|
97 |
|
---|
98 | QList <Client *> listClients;
|
---|
99 | };
|
---|
100 |
|
---|
101 | } // namespace pacpus
|
---|