- enum RPCTypes {
- Server,
- Client,
- Peer
- };
-
- SignalProxy(QObject* parent);
- SignalProxy(RPCTypes type, QObject* parent);
- SignalProxy(RPCTypes type, QIODevice* device, QObject* parent);
- virtual ~SignalProxy();
-
- void setRPCType(RPCTypes type);
- RPCTypes rpcType() const;
-
- bool maxPeersReached();
-
- bool addPeer(QIODevice *iodev);
- void removePeer(QIODevice *iodev = 0);
-
- bool attachSignal(QObject* sender, const char* signal, const QByteArray& rpcFunction = QByteArray());
- bool attachSlot(const QByteArray& rpcFunction, QObject* recv, const char* slot);
-
- void detachObject(QObject *obj);
- void detachSignals(QObject *sender);
- void detachSlots(QObject *receiver);
-
- void call(const char *signal , QVariant p1, QVariant p2, QVariant p3, QVariant p4,
- QVariant p5, QVariant p6, QVariant p7, QVariant p8, QVariant p9);
- void call(const QByteArray &funcName, const QVariantList ¶ms);
-
- static void writeDataToDevice(QIODevice *dev, const QVariant &item);
- static bool readDataFromDevice(QIODevice *dev, quint32 &blockSize, QVariant &item);
-
- const QList<int> &argTypes(QObject* obj, int methodId);
- const QByteArray &methodName(QObject* obj, int methodId);
-
- typedef QHash<int, QList<int> > ArgHash;
- typedef QHash<int, QByteArray> MethodNameHash;
- struct ClassInfo {
- ArgHash argTypes;
- MethodNameHash methodNames;
- // QHash<int, int> syncMap
- };
-
+ enum ProxyMode {
+ Server,
+ Client
+ };
+
+ enum EventType {
+ RemovePeerEvent = QEvent::User
+ };
+
+ SignalProxy(QObject *parent);
+ SignalProxy(ProxyMode mode, QObject *parent);
+ virtual ~SignalProxy();
+
+ void setProxyMode(ProxyMode mode);
+ inline ProxyMode proxyMode() const { return _proxyMode; }
+
+ void setHeartBeatInterval(int secs);
+ inline int heartBeatInterval() const { return _heartBeatInterval; }
+ void setMaxHeartBeatCount(int max);
+ inline int maxHeartBeatCount() const { return _maxHeartBeatCount; }
+
+ bool addPeer(Peer *peer);
+
+ bool attachSignal(QObject *sender, const char *signal, const QByteArray &sigName = QByteArray());
+ bool attachSlot(const QByteArray &sigName, QObject *recv, const char *slot);
+
+ void synchronize(SyncableObject *obj);
+ void stopSynchronize(SyncableObject *obj);
+
+ class ExtendedMetaObject;
+ ExtendedMetaObject *extendedMetaObject(const QMetaObject *meta) const;
+ ExtendedMetaObject *createExtendedMetaObject(const QMetaObject *meta, bool checkConflicts = false);
+ inline ExtendedMetaObject *extendedMetaObject(const QObject *obj) const { return extendedMetaObject(metaObject(obj)); }
+ inline ExtendedMetaObject *createExtendedMetaObject(const QObject *obj, bool checkConflicts = false) { return createExtendedMetaObject(metaObject(obj), checkConflicts); }
+
+ bool isSecure() const { return _secure; }
+ void dumpProxyStats();
+ void dumpSyncMap(SyncableObject *object);
+
+ static SignalProxy *current();
+
+ /**@{*/
+ /**
+ * 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<Peer*> peers, std::function<void()> closure);
+ void restrictTargetPeers(Peer *peer, std::function<void()> closure) {
+ QSet<Peer*> set;
+ set.insert(peer);
+ restrictTargetPeers(set, std::move(closure));
+ }
+
+ //A better version, but only implemented on Qt5 if Initializer Lists exist
+#ifdef Q_COMPILER_INITIALIZER_LISTS
+ void restrictTargetPeers(std::initializer_list<Peer*> peers, std::function<void()> closure) {
+ restrictTargetPeers(QSet<Peer*>(peers), std::move(closure));
+ }
+#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();
+ void setSourcePeer(Peer *sourcePeer);
+
+ /**
+ * @return If sending a signal, the Peer to which the current signal is directed
+ */
+ Peer *targetPeer();
+ void setTargetPeer(Peer *targetPeer);
+
+public slots:
+ void detachObject(QObject *obj);
+ void detachSignals(QObject *sender);
+ void detachSlots(QObject *receiver);
+
+protected:
+ void customEvent(QEvent *event);
+ void sync_call__(const SyncableObject *obj, ProxyMode modeType, const char *funcname, va_list ap);
+ void renameObject(const SyncableObject *obj, const QString &newname, const QString &oldname);
+