1 /***************************************************************************
2 * Copyright (C) 2005-2013 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 ***************************************************************************/
24 #include <QAbstractSocket>
27 #include "signalproxy.h"
29 class Peer : public QObject
34 Peer(QObject *parent = 0) : QObject(parent) {}
36 virtual QString description() const = 0;
38 virtual SignalProxy *signalProxy() const = 0;
39 virtual void setSignalProxy(SignalProxy *proxy) = 0;
41 virtual bool isOpen() const = 0;
42 virtual bool isSecure() const = 0;
43 virtual bool isLocal() const = 0;
45 virtual int lag() const = 0;
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;
53 virtual void close(const QString &reason = QString()) = 0;
57 void error(QAbstractSocket::SocketError);
58 void secureStateChanged(bool secure = true);
59 void lagUpdated(int msecs);
63 void handle(const T &protoMessage);
67 // Template method needed in the header
68 template<class T> inline
69 void Peer::handle(const T &protoMessage)
71 switch(protoMessage.handler()) {
72 case Protocol::SignalProxy:
74 qWarning() << Q_FUNC_INFO << "Cannot handle message without a SignalProxy!";
77 signalProxy()->handle(this, protoMessage);
81 qWarning() << Q_FUNC_INFO << "Unknown handler for protocol message!";