Quassel IRC  Pre-Release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
remotepeer.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2015 by the Quassel Project *
3  * devel@quassel-irc.org *
4  * *
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. *
9  * *
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. *
14  * *
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  ***************************************************************************/
20 
21 #ifndef REMOTEPEER_H
22 #define REMOTEPEER_H
23 
24 #include <QDateTime>
25 
26 #include "compressor.h"
27 #include "peer.h"
28 #include "protocol.h"
29 #include "signalproxy.h"
30 
31 class QTimer;
32 
33 class AuthHandler;
34 
35 class RemotePeer : public Peer
36 {
37  Q_OBJECT
38 
39 public:
40  // import the virtuals from the baseclass
41  using Peer::handle;
42  using Peer::dispatch;
43 
44  RemotePeer(AuthHandler *authHandler, QTcpSocket *socket, Compressor::CompressionLevel level, QObject *parent = 0);
45 
46  void setSignalProxy(SignalProxy *proxy);
47 
48  virtual QString protocolName() const = 0;
49  virtual QString description() const;
50  virtual quint16 enabledFeatures() const { return 0; }
51 
52  bool isOpen() const;
53  bool isSecure() const;
54  bool isLocal() const;
55 
56  int lag() const;
57 
58  bool compressionEnabled() const;
59  void setCompressionEnabled(bool enabled);
60 
61  QTcpSocket *socket() const;
62 
63 public slots:
64  void close(const QString &reason = QString());
65 
66 signals:
67  void transferProgress(int current, int max);
68  void socketError(QAbstractSocket::SocketError error, const QString &errorString);
69  void statusMessage(const QString &msg);
70 
71 protected:
72  SignalProxy *signalProxy() const;
73 
74  void writeMessage(const QByteArray &msg);
75  virtual void processMessage(const QByteArray &msg) = 0;
76 
77  // These protocol messages get handled internally and won't reach SignalProxy
78  void handle(const Protocol::HeartBeat &heartBeat);
79  void handle(const Protocol::HeartBeatReply &heartBeatReply);
80  virtual void dispatch(const Protocol::HeartBeat &msg) = 0;
81  virtual void dispatch(const Protocol::HeartBeatReply &msg) = 0;
82 
83 protected slots:
84  virtual void onSocketStateChanged(QAbstractSocket::SocketState state);
85  virtual void onSocketError(QAbstractSocket::SocketError error);
86 
87 private slots:
88  void onReadyRead();
90 
91  void sendHeartBeat();
92  void changeHeartBeatInterval(int secs);
93 
94 private:
95  bool readMessage(QByteArray &msg);
96 
97 private:
98  QTcpSocket *_socket;
103  int _lag;
104  quint32 _msgSize;
105 };
106 
107 #endif