#ifndef _PVSLISTENSERVER_H_ #define _PVSLISTENSERVER_H_ #include #include #include #include //#include #include "../setup.h" class SslServer; class PVSClientConnection; class PVSMsg; class McastConfiguration; class PVSListenServer : public QObject { Q_OBJECT private: // internal control functions std::list _clients; int _numCon; bool _fresh; unsigned int _clientsMax; int _port; //QTcpServer *_listenSocket; SslServer *_listenSocket; int _id; EventIdentDispatcher _loginDispatcher; EventIdentDispatcher _commandDispatcher; EventIdentDispatcher _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* 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 void addLoginHandler(QString ident, T* who, void (T :: *func)(PVSMsg)) { qDebug("Listener got added to LoginHandler"); _loginDispatcher.addListener(ident, who, func); }; template void removeLoginHandler(QString ident, T* who, void (T :: *func)(PVSMsg)) { _loginDispatcher.removeListener(ident, who, func); }; template void addChatHandler(QString ident, T* who, void (T :: *func)(PVSMsg)) { _chatDispatcher.addListener(ident, who, func); }; template void removeChatHandler(QString ident, T* who, void (T :: *func)(PVSMsg)) { _chatDispatcher.removeListener(ident, who, func); }; template void addCommandHandler(QString ident, T* who, void (T :: *func)(PVSMsg)) { _commandDispatcher.addListener(ident, who, func); }; template 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