X-Git-Url: https://git.quassel-irc.org/?a=blobdiff_plain;f=src%2Fcommon%2Fsignalproxy.cpp;h=3ac73bc0bc10aaf9808374c1a114a1686d4e7b0f;hb=ce221dcdce9f39596adf115b05057023c31bde4e;hp=bcc639fad7979d53c017b0854e20234d179efc8e;hpb=53861faa5551606eea31588b65ba501b24fb2e1a;p=quassel.git diff --git a/src/common/signalproxy.cpp b/src/common/signalproxy.cpp index bcc639fa..3ac73bc0 100644 --- a/src/common/signalproxy.cpp +++ b/src/common/signalproxy.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2016 by the Quassel Project * + * Copyright (C) 2005-2018 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -173,6 +173,9 @@ int SignalProxy::SignalRelay::qt_metacall(QMetaObject::Call _c, int _id, void ** // ================================================== // SignalProxy // ================================================== + +thread_local SignalProxy *SignalProxy::_current{nullptr}; + SignalProxy::SignalProxy(QObject *parent) : QObject(parent) { @@ -204,6 +207,8 @@ SignalProxy::~SignalProxy() _syncSlave.clear(); removeAllPeers(); + + _current = nullptr; } @@ -221,9 +226,6 @@ void SignalProxy::setProxyMode(ProxyMode mode) initClient(); } -thread_local SignalProxy *SignalProxy::_current; - - void SignalProxy::init() { _heartBeatInterval = 0; @@ -516,15 +518,9 @@ void SignalProxy::stopSynchronize(SyncableObject *obj) template void SignalProxy::dispatch(const T &protoMessage) { - for (auto peer : _peerMap.values()) { - _targetPeer = peer; - - if (peer->isOpen()) - peer->dispatch(protoMessage); - else - QCoreApplication::postEvent(this, new ::RemovePeerEvent(peer)); + for (auto&& peer : _peerMap.values()) { + dispatch(peer, protoMessage); } - _targetPeer = nullptr; } @@ -833,7 +829,7 @@ void SignalProxy::updateSecureState() QVariantList SignalProxy::peerData() { QVariantList result; - for (auto peer : _peerMap.values()) { + for (auto &&peer : _peerMap.values()) { QVariantMap data; data["id"] = peer->id(); data["clientVersion"] = peer->clientVersion(); @@ -843,13 +839,18 @@ QVariantList SignalProxy::peerData() { data["remoteAddress"] = peer->address(); data["connectedSince"] = peer->connectedSince(); data["secure"] = peer->isSecure(); + data["features"] = static_cast(peer->features().toLegacyFeatures()); + data["featureList"] = peer->features().toStringList(); result << data; } return result; } Peer *SignalProxy::peerById(int peerId) { - return _peerMap[peerId]; + // We use ::value() here instead of the [] operator because the latter has the side-effect + // of automatically inserting a null value with the passed key into the map. See + // https://doc.qt.io/qt-5/qhash.html#operator-5b-5d and https://doc.qt.io/qt-5/qhash.html#value. + return _peerMap.value(peerId); } void SignalProxy::restrictTargetPeers(QSet peers, std::function closure)