1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
#ifndef _PVSLISTENSERVER_H_
#define _PVSLISTENSERVER_H_
#include <list>
#include <src/util/dispatcher.h>
#include <src/util/consoleLogger.h>
#include <QtNetwork/QSslSocket>
//#include <QtNetwork/QTcpServer>
#include "../setup.h"
class SslServer;
class PVSClientConnection;
class PVSMsg;
class McastConfiguration;
class PVSListenServer : public QObject
{
Q_OBJECT
private:
// internal control functions
std::list<PVSClientConnection*> _clients;
int _numCon;
bool _fresh;
unsigned int _clientsMax;
int _port;
//QTcpServer *_listenSocket;
SslServer *_listenSocket;
int _id;
EventIdentDispatcher<PVSMsg> _loginDispatcher;
EventIdentDispatcher<PVSMsg> _commandDispatcher;
EventIdentDispatcher<PVSMsg> _chatDispatcher;
int _timer;
// obvious init method is obvious
bool init();
unsigned int generateID();
McastConfiguration* _mcastConfig;
void loadMcastConfig();
void saveMcastConfig();
PVSMsg mcastConfigMessage();
protected:
void timerEvent(QTimerEvent *event);
public:
// typedef void (A::*function)(void);
// C'Tor
explicit PVSListenServer(int port = 0, int clients = 0);
virtual ~PVSListenServer();
PVSClientConnection* getConnectionFromId(int id);
void sendToAll(PVSMsg msg);
// control methods
bool startListen(int port);
bool shutdown();
bool isListening();
bool disconnectClient(PVSClientConnection* delinquent);
void onConnectionRemoved(PVSClientConnection* delinquent);
void multicastReconfigure(McastConfiguration const* source);
McastConfiguration const* getMulticastConfiguration();
std::list<PVSClientConnection*>* getClientListPtr()
{
return &_clients;
}
// methods which can/should be overwritten by derivates
virtual void onClientConnected(PVSClientConnection* connected); // you can hook up additional services on client connection here
virtual void onClientDisconnected(PVSClientConnection* disconnected); // deletes the client, but you can hook up stuff here too
void handleClientMsg(unsigned int clientID, PVSMsg msg); ///< called by a clientconnection if a msg was received
template<class T> void addLoginHandler(QString ident, T* who, void (T :: *func)(PVSMsg))
{
qDebug("Listener got added to LoginHandler");
_loginDispatcher.addListener(ident, who, func);
};
template<class T> void removeLoginHandler(QString ident, T* who, void (T :: *func)(PVSMsg))
{
_loginDispatcher.removeListener(ident, who, func);
};
template<class T> void addChatHandler(QString ident, T* who, void (T :: *func)(PVSMsg))
{
_chatDispatcher.addListener(ident, who, func);
};
template<class T> void removeChatHandler(QString ident, T* who, void (T :: *func)(PVSMsg))
{
_chatDispatcher.removeListener(ident, who, func);
};
template<class T> void addCommandHandler(QString ident, T* who, void (T :: *func)(PVSMsg))
{
_commandDispatcher.addListener(ident, who, func);
};
template<class T> void removeCommandHandler(QString ident, T* who, void (T :: *func)(PVSMsg))
{
_commandDispatcher.removeListener(ident, who, func);
};
PVSClientConnection* getConnectionFromSocket(QSslSocket* sock);
PVSClientConnection* getConnectionFromID(int id);
private Q_SLOTS:
void server_connectionRequest();
};
#endif
|