1 /***************************************************************************
2 * Copyright (C) 2005-2018 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 ***************************************************************************/
21 #include "internalpeer.h"
23 using namespace Protocol;
25 InternalPeer::InternalPeer(QObject *parent)
26 : Peer(nullptr, parent)
28 static bool registered = []() {
29 qRegisterMetaType<Protocol::SyncMessage>();
30 qRegisterMetaType<Protocol::RpcCall>();
31 qRegisterMetaType<Protocol::InitRequest>();
32 qRegisterMetaType<Protocol::InitData>();
37 setFeatures(Quassel::Features{});
41 InternalPeer::~InternalPeer()
49 QString InternalPeer::description() const
51 return tr("internal connection");
55 QString InternalPeer::address() const
57 return tr("internal connection");
61 quint16 InternalPeer::port() const
67 bool InternalPeer::isOpen() const
73 bool InternalPeer::isSecure() const
79 bool InternalPeer::isLocal() const
85 void InternalPeer::close(const QString &reason)
89 qWarning() << "closing not implemented!";
93 int InternalPeer::lag() const
99 ::SignalProxy *InternalPeer::signalProxy() const
105 void InternalPeer::setSignalProxy(::SignalProxy *proxy)
107 if (!proxy && _proxy) {
116 if (proxy && !_proxy) {
121 qWarning() << Q_FUNC_INFO << "Changing the SignalProxy is not supported!";
125 void InternalPeer::setPeer(InternalPeer *peer)
127 connect(peer, SIGNAL(dispatchMessage(Protocol::SyncMessage)), SLOT(handleMessage(Protocol::SyncMessage)));
128 connect(peer, SIGNAL(dispatchMessage(Protocol::RpcCall)) , SLOT(handleMessage(Protocol::RpcCall)));
129 connect(peer, SIGNAL(dispatchMessage(Protocol::InitRequest)), SLOT(handleMessage(Protocol::InitRequest)));
130 connect(peer, SIGNAL(dispatchMessage(Protocol::InitData)) , SLOT(handleMessage(Protocol::InitData)));
132 connect(peer, SIGNAL(disconnected()), SLOT(peerDisconnected()));
138 void InternalPeer::peerDisconnected()
140 disconnect(sender(), nullptr, this, nullptr);
148 void InternalPeer::dispatch(const SyncMessage &msg)
150 emit dispatchMessage(msg);
154 void InternalPeer::dispatch(const RpcCall &msg)
156 emit dispatchMessage(msg);
160 void InternalPeer::dispatch(const InitRequest &msg)
162 emit dispatchMessage(msg);
166 void InternalPeer::dispatch(const InitData &msg)
168 emit dispatchMessage(msg);
172 void InternalPeer::handleMessage(const Protocol::SyncMessage &msg)
178 void InternalPeer::handleMessage(const Protocol::RpcCall &msg)
184 void InternalPeer::handleMessage(const Protocol::InitRequest &msg)
190 void InternalPeer::handleMessage(const Protocol::InitData &msg)
197 void InternalPeer::handle(const T &msg)
199 static auto setSourcePeer = [](Peer *peer) {
200 auto p = SignalProxy::current();
202 p->setSourcePeer(peer);
208 setSourcePeer(nullptr);