diff options
| author | Sebastian | 2010-05-12 19:42:27 +0200 |
|---|---|---|
| committer | Sebastian | 2010-05-12 19:42:27 +0200 |
| commit | ce3329047d378a14006ce74ec273ac59e3375303 (patch) | |
| tree | 782430f270b4c7aca1b35d5b7813518e3797c555 /src/net/pvsServerConnection.h | |
| download | pvs-ce3329047d378a14006ce74ec273ac59e3375303.tar.gz pvs-ce3329047d378a14006ce74ec273ac59e3375303.tar.xz pvs-ce3329047d378a14006ce74ec273ac59e3375303.zip | |
initial import of latest svn version
Diffstat (limited to 'src/net/pvsServerConnection.h')
| -rw-r--r-- | src/net/pvsServerConnection.h | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/src/net/pvsServerConnection.h b/src/net/pvsServerConnection.h new file mode 100644 index 0000000..0669d88 --- /dev/null +++ b/src/net/pvsServerConnection.h @@ -0,0 +1,99 @@ +/** + * PVSServerConnection + * + * holds and maintains a Connection to a PVSListenServer (or derivate) + * + */ + + + +#ifndef _PVSSERVERCONNECTION_H_ +#define _PVSSERVERCONNECTION_H_ + +#include "src/util/dispatcher.h" +#include <QtNetwork/QSslSocket> + +class PVSMsg; +class PVS; +class PVSDiscoveredServer; + +class PVSServerConnection : public QObject +{ + Q_OBJECT +public: + PVSServerConnection(PVS *parent); + ~PVSServerConnection() {} + bool connectToServer(PVSDiscoveredServer* server, QString passwd = QString()); + void disconnectFromServer(); + bool isConnected() + { + return _socket != NULL && _socket->state() == QAbstractSocket::ConnectedState; + } + + void sendMessage(PVSMsg newMessage); + + void ping(); + QString getServerName(); + + virtual void loadCommands(); + void onID(PVSMsg idmsg); + void onPing(PVSMsg pingmsg); + template<class T> void addLoginHandler(QString ident, T* who, void (T :: *func)(PVSMsg)) + { + _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); + }; + +protected: + void timerEvent(QTimerEvent *event); + +private Q_SLOTS: + void sslErrors(const QList<QSslError> & errors); // triggered for errors that occur during SSL negotiation + void sock_dataArrival(); // triggered if data is available for reading + void sock_closed(); // triggered if the socket is closed + void sock_error(QAbstractSocket::SocketError errcode); // triggered if an error occurs on the socket + void sock_connected(); // triggered if the connection is established and ready to use + +private: + + inline void timerStop(); + void handleClientMsg(PVSMsg receiver); + void handleDisconnectInternal(); + + EventIdentDispatcher<PVSMsg> _commandDispatcher; + EventIdentDispatcher<PVSMsg> _chatDispatcher; + EventIdentDispatcher<PVSMsg> _loginDispatcher; + PVSMsg *_incomplete; + QSslSocket *_socket; + unsigned int _id; + int _timerId; + //QString _host; + //quint16 _port; + int _timer; + PVS *_client; + bool _wasConnected; + QByteArray _expectedFingerprint; + QString _name; + QString _passwd; +}; + +#endif |
