/***************************************************************************
- * 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 *
// ==================================================
// SignalProxy
// ==================================================
+
+thread_local SignalProxy *SignalProxy::_current{nullptr};
+
SignalProxy::SignalProxy(QObject *parent)
: QObject(parent)
{
_syncSlave.clear();
removeAllPeers();
+
+ _current = nullptr;
}
initClient();
}
-thread_local SignalProxy *SignalProxy::_current;
-
-
void SignalProxy::init()
{
_heartBeatInterval = 0;
template<class T>
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;
}
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();
data["remoteAddress"] = peer->address();
data["connectedSince"] = peer->connectedSince();
data["secure"] = peer->isSecure();
+ data["features"] = static_cast<quint32>(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<Peer*> peers, std::function<void()> closure)