Handle the readyRead() signal in RemotePeer instead of LegacyPeer
[quassel.git] / src / common / remotepeer.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2014 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 "peer.h"
27 #include "protocol.h"
28 #include "signalproxy.h"
29
30 class QTcpSocket;
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, QObject *parent = 0);
45     virtual ~RemotePeer() {};
46
47     void setSignalProxy(SignalProxy *proxy);
48
49     QString description() const;
50
51     bool isOpen() const;
52     bool isSecure() const;
53     bool isLocal() const;
54
55     int lag() const;
56
57     bool compressionEnabled() const;
58     void setCompressionEnabled(bool enabled);
59
60     QTcpSocket *socket() const;
61
62 public slots:
63     void close(const QString &reason = QString());
64
65 signals:
66     void transferProgress(int current, int max);
67     void socketError(QAbstractSocket::SocketError error, const QString &errorString);
68     void statusMessage(const QString &msg);
69
70 protected:
71     SignalProxy *signalProxy() const;
72
73     // These protocol messages get handled internally and won't reach SignalProxy
74     void handle(const Protocol::HeartBeat &heartBeat);
75     void handle(const Protocol::HeartBeatReply &heartBeatReply);
76     virtual void dispatch(const Protocol::HeartBeat &msg) = 0;
77     virtual void dispatch(const Protocol::HeartBeatReply &msg) = 0;
78
79 protected slots:
80     virtual void onSocketDataAvailable() = 0;
81     virtual void onSocketStateChanged(QAbstractSocket::SocketState state);
82     virtual void onSocketError(QAbstractSocket::SocketError error);
83
84 private slots:
85     void sendHeartBeat();
86     void changeHeartBeatInterval(int secs);
87
88 private:
89     QTcpSocket *_socket;
90     SignalProxy *_signalProxy;
91     QTimer *_heartBeatTimer;
92     int _heartBeatCount;
93     int _lag;
94 };
95
96 #endif