X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fremoteconnection.h;fp=src%2Fcommon%2Fremoteconnection.h;h=198627a061416d91310036a9db3176b4e63f9cbd;hp=0000000000000000000000000000000000000000;hb=0e1b154f362e13c2c9009f842e3fd6d8e7c346fc;hpb=c9e3e41c9446e58073225db379d28e1a08e15cd8 diff --git a/src/common/remoteconnection.h b/src/common/remoteconnection.h new file mode 100644 index 00000000..198627a0 --- /dev/null +++ b/src/common/remoteconnection.h @@ -0,0 +1,138 @@ +/*************************************************************************** + * Copyright (C) 2005-2012 by the Quassel Project * + * devel@quassel-irc.org * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) version 3. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef REMOTECONNECTION_H +#define REMOTECONNECTION_H + +#include +#include + +#include "signalproxy.h" + +class QTimer; + +class RemoteConnection : public SignalProxy::AbstractPeer +{ + Q_OBJECT + +public: + RemoteConnection(QTcpSocket *socket, QObject *parent = 0); + virtual ~RemoteConnection() {}; + + void setSignalProxy(SignalProxy *proxy); + + QString description() const; + + bool isOpen() const; + bool isSecure() const; + bool isLocal() const; + + int lag() const; + + bool compressionEnabled() const; + void setCompressionEnabled(bool enabled); + + QTcpSocket *socket() const; + + // this is only used for the auth phase and should be replaced by something more generic + virtual void writeSocketData(const QVariant &item) = 0; + +public slots: + void close(const QString &reason = QString()); + +signals: + // this is only used for the auth phase and should be replaced by something more generic + void dataReceived(const QVariant &item); + + void disconnected(); + void error(QAbstractSocket::SocketError); + + void transferProgress(int current, int max); + +protected: + class HeartBeat; + class HeartBeatReply; + + SignalProxy *signalProxy() const; + + template + void handle(const T &protoMessage); + + void handle(const HeartBeat &heartBeat); + void handle(const HeartBeatReply &heartBeatReply); + + virtual void dispatch(const HeartBeat &msg) = 0; + virtual void dispatch(const HeartBeatReply &msg) = 0; + +private slots: + void sendHeartBeat(); + void changeHeartBeatInterval(int secs); + +private: + QTcpSocket *_socket; + SignalProxy *_signalProxy; + QTimer *_heartBeatTimer; + int _heartBeatCount; + int _lag; +}; + + +// These protocol messages get handled internally and won't reach SignalProxy + +class RemoteConnection::HeartBeat +{ +public: + inline HeartBeat(const QDateTime ×tamp) : _timestamp(timestamp) {} + + inline QDateTime timestamp() const { return _timestamp; } + +private: + QDateTime _timestamp; +}; + + +class RemoteConnection::HeartBeatReply +{ +public: + inline HeartBeatReply(const QDateTime ×tamp) : _timestamp(timestamp) {} + + inline QDateTime timestamp() const { return _timestamp; } + +private: + QDateTime _timestamp; +}; + + +// Template methods we need in the header +template inline +void RemoteConnection::handle(const T &protoMessage) +{ + if (!signalProxy()) { + qWarning() << Q_FUNC_INFO << "Cannot handle messages without a SignalProxy!"; + return; + } + + // _heartBeatCount = 0; + + signalProxy()->handle(this, protoMessage); +} + + +#endif