X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsignalproxy.h;h=63d3438a98b896ecf9dfc490b1a0853a504d3026;hp=9297ae8127d1505733249e953fdc7875547430f1;hb=28cee4568aeb1ce3014d11234e40f19e7aeae5bd;hpb=2a89d1b0c473f92c5cf9fb803d99e8b51b2c68e7 diff --git a/src/common/signalproxy.h b/src/common/signalproxy.h index 9297ae81..63d3438a 100644 --- a/src/common/signalproxy.h +++ b/src/common/signalproxy.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-2013 by the Quassel Project * + * Copyright (C) 2005-2016 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -24,9 +24,12 @@ #include #include +#include + #include "protocol.h" struct QMetaObject; +class QIODevice; class Peer; class SyncableObject; @@ -76,7 +79,39 @@ public: bool isSecure() const { return _secure; } void dumpProxyStats(); void dumpSyncMap(SyncableObject *object); - inline int peerCount() const { return _peers.size(); } + + /**@{*/ + /** + * This method allows to send a signal only to a limited set of peers + * @param peers A list of peers that should receive it + * @param closure Code you want to execute within of that restricted environment + */ + void restrictTargetPeers(QSet peers, std::function closure); + void restrictTargetPeers(Peer *peer, std::function closure) { + QSet set; + set.insert(peer); + restrictTargetPeers(set, std::move(closure)); + } + + //A better version, but only implemented on Qt5 if Initializer Lists exist +#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0) +#ifdef Q_COMPILER_INITIALIZER_LISTS + void restrictTargetPeers(std::initializer_list peers, std::function closure) { + restrictTargetPeers(QSet(peers), std::move(closure)); + } +#endif +#endif + /**}@*/ + + inline int peerCount() const { return _peerMap.size(); } + QVariantList peerData(); + + Peer *peerById(int peerId); + + /** + * @return If handling a signal, the Peer from which the current signal originates + */ + Peer *sourcePeer() { return _sourcePeer; } public slots: void detachObject(QObject *obj); @@ -116,6 +151,10 @@ private: void removePeer(Peer *peer); void removeAllPeers(); + int nextPeerId() { + return _lastPeerId++; + } + template void dispatch(const T &protoMessage); template @@ -138,7 +177,7 @@ private: static void disconnectDevice(QIODevice *dev, const QString &reason = QString()); - QSet _peers; + QHash _peerMap; // containg a list of argtypes for fast access QHash _extendedMetaObjects; @@ -161,6 +200,13 @@ private: bool _secure; // determines if all connections are in a secured state (using ssl or internal connections) + int _lastPeerId = 0; + + QSet _restrictedTargets; + bool _restrictMessageTarget = false; + + Peer *_sourcePeer = nullptr; + friend class SignalRelay; friend class SyncableObject; friend class Peer;