Fix virtual overloads
[quassel.git] / src / common / remotepeer.h
1 /***************************************************************************
2  *   Copyright (C) 2005-2013 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 RemotePeer : public Peer
34 {
35     Q_OBJECT
36
37 public:
38     RemotePeer(QTcpSocket *socket, QObject *parent = 0);
39     virtual ~RemotePeer() {};
40
41     void setSignalProxy(SignalProxy *proxy);
42
43     QString description() const;
44
45     bool isOpen() const;
46     bool isSecure() const;
47     bool isLocal() const;
48
49     int lag() const;
50
51     bool compressionEnabled() const;
52     void setCompressionEnabled(bool enabled);
53
54     QTcpSocket *socket() const;
55
56     // this is only used for the auth phase and should be replaced by something more generic
57     virtual void writeSocketData(const QVariant &item) = 0;
58
59 public slots:
60     void close(const QString &reason = QString());
61
62 signals:
63     // this is only used for the auth phase and should be replaced by something more generic
64     void dataReceived(const QVariant &item);
65
66     void transferProgress(int current, int max);
67
68 protected:
69     SignalProxy *signalProxy() const;
70
71     using Peer::handle;
72     using Peer::dispatch;
73
74     // These protocol messages get handled internally and won't reach SignalProxy
75     void handle(const Protocol::HeartBeat &heartBeat);
76     void handle(const Protocol::HeartBeatReply &heartBeatReply);
77     virtual void dispatch(const Protocol::HeartBeat &msg) = 0;
78     virtual void dispatch(const Protocol::HeartBeatReply &msg) = 0;
79
80 private slots:
81     void sendHeartBeat();
82     void changeHeartBeatInterval(int secs);
83
84 private:
85     QTcpSocket *_socket;
86     SignalProxy *_signalProxy;
87     QTimer *_heartBeatTimer;
88     int _heartBeatCount;
89     int _lag;
90 };
91
92 #endif