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<QPointer<InternalPeer>>();
30 qRegisterMetaType<Protocol::SyncMessage>();
31 qRegisterMetaType<Protocol::RpcCall>();
32 qRegisterMetaType<Protocol::InitRequest>();
33 qRegisterMetaType<Protocol::InitData>();
38 setFeatures(Quassel::Features{});
42 InternalPeer::~InternalPeer()
50 QString InternalPeer::description() const
52 return tr("internal connection");
56 QString InternalPeer::address() const
58 return tr("internal connection");
62 quint16 InternalPeer::port() const
68 bool InternalPeer::isOpen() const
74 bool InternalPeer::isSecure() const
80 bool InternalPeer::isLocal() const
86 void InternalPeer::close(const QString &reason)
93 int InternalPeer::lag() const
99 ::SignalProxy *InternalPeer::signalProxy() const
105 void InternalPeer::setSignalProxy(::SignalProxy *proxy)
107 if (!proxy && _proxy) {
116 if (proxy && !_proxy) {
122 qWarning() << Q_FUNC_INFO << "Changing the SignalProxy is not supported!";
126 void InternalPeer::setPeer(InternalPeer *peer)
128 connect(peer, SIGNAL(dispatchMessage(Protocol::SyncMessage)), SLOT(handleMessage(Protocol::SyncMessage)));
129 connect(peer, SIGNAL(dispatchMessage(Protocol::RpcCall)) , SLOT(handleMessage(Protocol::RpcCall)));
130 connect(peer, SIGNAL(dispatchMessage(Protocol::InitRequest)), SLOT(handleMessage(Protocol::InitRequest)));
131 connect(peer, SIGNAL(dispatchMessage(Protocol::InitData)) , SLOT(handleMessage(Protocol::InitData)));
133 connect(peer, SIGNAL(disconnected()), SLOT(peerDisconnected()));
139 void InternalPeer::peerDisconnected()
141 disconnect(sender(), nullptr, this, nullptr);
149 void InternalPeer::dispatch(const SyncMessage &msg)
151 emit dispatchMessage(msg);
155 void InternalPeer::dispatch(const RpcCall &msg)
157 emit dispatchMessage(msg);
161 void InternalPeer::dispatch(const InitRequest &msg)
163 emit dispatchMessage(msg);
167 void InternalPeer::dispatch(const InitData &msg)
169 emit dispatchMessage(msg);
173 void InternalPeer::handleMessage(const Protocol::SyncMessage &msg)
179 void InternalPeer::handleMessage(const Protocol::RpcCall &msg)
185 void InternalPeer::handleMessage(const Protocol::InitRequest &msg)
191 void InternalPeer::handleMessage(const Protocol::InitData &msg)
198 void InternalPeer::handle(const T &msg)
200 static auto setSourcePeer = [](Peer *peer) {
201 auto p = SignalProxy::current();
203 p->setSourcePeer(peer);
209 setSourcePeer(nullptr);