X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsignalproxy.h;h=a985d0dcdba79de4a8ac97a634e6ce807760008d;hp=9f31f6f270551aacfeb6566e3f0000602c167f55;hb=b1b970e71618cb2d2cf372ba55234000c6324d7f;hpb=61bf66635f5b50100aabc6e8ad11d62a21e47589 diff --git a/src/common/signalproxy.h b/src/common/signalproxy.h index 9f31f6f2..a985d0dc 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 * @@ -27,6 +27,7 @@ #include "protocol.h" struct QMetaObject; +class QIODevice; class Peer; class SyncableObject; @@ -76,7 +77,23 @@ public: bool isSecure() const { return _secure; } void dumpProxyStats(); void dumpSyncMap(SyncableObject *object); + + /** + * This method allows to send a signal only to a limited set of peers + * @param peerIds A list of peers that should receive it + * @param closure Code you want to execute within of that restricted environment + */ + void restrictTargetPeers(std::initializer_list peerIds, std::function closure); + inline int peerCount() const { return _peers.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,8 +133,14 @@ private: void removePeer(Peer *peer); void removeAllPeers(); + int nextPeerId() { + return _lastPeerId++; + } + template void dispatch(const T &protoMessage); + template + void dispatch(Peer *peer, const T &protoMessage); void handle(Peer *peer, const Protocol::SyncMessage &syncMessage); void handle(Peer *peer, const Protocol::RpcCall &rpcCall); @@ -125,10 +148,10 @@ private: void handle(Peer *peer, const Protocol::InitData &initData); template - void handle(Peer *peer, T) { Q_UNUSED(peer); Q_ASSERT(0); } + void handle(Peer *, T) { Q_ASSERT(0); } - bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, QVariant &returnValue); - bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms = QVariantList()); + bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms, QVariant &returnValue, Peer *peer = 0); + bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms = QVariantList(), Peer *peer = 0); void requestInit(SyncableObject *obj); QVariantMap initData(SyncableObject *obj) const; @@ -137,6 +160,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; @@ -159,6 +183,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; + friend class SignalRelay; friend class SyncableObject; friend class Peer;