1 /***************************************************************************
2 * Copyright (C) 2005-2012 by the Quassel Project *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) version 3. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 ***************************************************************************/
21 #ifndef REMOTECONNECTION_H
22 #define REMOTECONNECTION_H
27 #include "signalproxy.h"
31 class RemoteConnection : public SignalProxy::AbstractPeer
36 RemoteConnection(QTcpSocket *socket, QObject *parent = 0);
37 virtual ~RemoteConnection() {};
39 void setSignalProxy(SignalProxy *proxy);
41 QString description() const;
44 bool isSecure() const;
49 bool compressionEnabled() const;
50 void setCompressionEnabled(bool enabled);
52 QTcpSocket *socket() const;
54 // this is only used for the auth phase and should be replaced by something more generic
55 virtual void writeSocketData(const QVariant &item) = 0;
58 void close(const QString &reason = QString());
61 // this is only used for the auth phase and should be replaced by something more generic
62 void dataReceived(const QVariant &item);
65 void error(QAbstractSocket::SocketError);
67 void transferProgress(int current, int max);
73 SignalProxy *signalProxy() const;
76 void handle(const T &protoMessage);
78 void handle(const HeartBeat &heartBeat);
79 void handle(const HeartBeatReply &heartBeatReply);
81 virtual void dispatch(const HeartBeat &msg) = 0;
82 virtual void dispatch(const HeartBeatReply &msg) = 0;
86 void changeHeartBeatInterval(int secs);
90 SignalProxy *_signalProxy;
91 QTimer *_heartBeatTimer;
97 // These protocol messages get handled internally and won't reach SignalProxy
99 class RemoteConnection::HeartBeat
102 inline HeartBeat(const QDateTime ×tamp) : _timestamp(timestamp) {}
104 inline QDateTime timestamp() const { return _timestamp; }
107 QDateTime _timestamp;
111 class RemoteConnection::HeartBeatReply
114 inline HeartBeatReply(const QDateTime ×tamp) : _timestamp(timestamp) {}
116 inline QDateTime timestamp() const { return _timestamp; }
119 QDateTime _timestamp;
123 // Template methods we need in the header
124 template<class T> inline
125 void RemoteConnection::handle(const T &protoMessage)
127 if (!signalProxy()) {
128 qWarning() << Q_FUNC_INFO << "Cannot handle messages without a SignalProxy!";
132 // _heartBeatCount = 0;
134 signalProxy()->handle(this, protoMessage);