Remove unused cipher map.
[quassel.git] / src / common / peer.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 PEER_H
22 #define PEER_H
23
24 #include <QAbstractSocket>
25
26 #include "protocol.h"
27 #include "signalproxy.h"
28
29 class Peer : public QObject
30 {
31     Q_OBJECT
32
33 public:
34     Peer(QObject *parent = 0) : QObject(parent) {}
35
36     virtual QString description() const = 0;
37
38     virtual SignalProxy *signalProxy() const = 0;
39     virtual void setSignalProxy(SignalProxy *proxy) = 0;
40
41     virtual bool isOpen() const = 0;
42     virtual bool isSecure() const = 0;
43     virtual bool isLocal() const = 0;
44
45     virtual int lag() const = 0;
46
47 public slots:
48     virtual void dispatch(const Protocol::SyncMessage &msg) = 0;
49     virtual void dispatch(const Protocol::RpcCall &msg) = 0;
50     virtual void dispatch(const Protocol::InitRequest &msg) = 0;
51     virtual void dispatch(const Protocol::InitData &msg) = 0;
52
53     virtual void close(const QString &reason = QString()) = 0;
54
55 signals:
56     void disconnected();
57     void error(QAbstractSocket::SocketError);
58     void secureStateChanged(bool secure = true);
59     void lagUpdated(int msecs);
60
61 protected:
62     template<class T>
63     void handle(const T &protoMessage);
64 };
65
66
67 // Template method needed in the header
68 template<class T> inline
69 void Peer::handle(const T &protoMessage)
70 {
71     switch(protoMessage.handler()) {
72         case Protocol::SignalProxy:
73             if (!signalProxy()) {
74                 qWarning() << Q_FUNC_INFO << "Cannot handle message without a SignalProxy!";
75                 return;
76             }
77             signalProxy()->handle(this, protoMessage);
78             break;
79
80         default:
81             qWarning() << Q_FUNC_INFO << "Unknown handler for protocol message!";
82             return;
83     }
84 }
85
86 #endif