- void initServer();
- void initClient();
-
- void createClassInfo(QObject *obj);
- void setArgTypes(QObject *obj, int methodId);
- void setMinArgCount(QObject *obj, int methodId);
- void setMethodName(QObject *obj, int methodId);
- void setSyncMap(SyncableObject *obj);
- void setUpdatedRemotelyId(QObject *obj);
-
- bool methodsMatch(const QMetaMethod &signal, const QMetaMethod &slot) const;
-
- void dispatchSignal(QIODevice *receiver, const RequestType &requestType, const QVariantList ¶ms);
- void dispatchSignal(const RequestType &requestType, const QVariantList ¶ms);
-
- void receivePeerSignal(QIODevice *sender, const QVariant &packedFunc);
- void handleSync(QVariantList params);
- void handleInitRequest(QIODevice *sender, const QVariantList ¶ms);
- void handleInitData(QIODevice *sender, const QVariantList ¶ms);
- void handleSignal(const QByteArray &funcName, const QVariantList ¶ms);
-
- bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms = QVariantList());
-
- QVariantMap initData(SyncableObject *obj) const;
- void setInitData(SyncableObject *obj, const QVariantMap &properties);
+ template<class T>
+ class PeerMessageEvent;
+
+ void init();
+ void initServer();
+ void initClient();
+
+ static const QMetaObject *metaObject(const QObject *obj);
+
+ void removePeer(Peer *peer);
+ void removeAllPeers();
+
+ template<class T>
+ void dispatch(const T &protoMessage);
+ template<class T>
+ void dispatch(Peer *peer, const T &protoMessage);
+
+ void handle(Peer *peer, const Protocol::SyncMessage &syncMessage);
+ void handle(Peer *peer, const Protocol::RpcCall &rpcCall);
+ void handle(Peer *peer, const Protocol::InitRequest &initRequest);
+ void handle(Peer *peer, const Protocol::InitData &initData);
+
+ template<class T>
+ void handle(Peer *, T) { Q_ASSERT(0); }
+
+ 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;
+ void setInitData(SyncableObject *obj, const QVariantMap &properties);
+
+ static void disconnectDevice(QIODevice *dev, const QString &reason = QString());
+
+ QSet<Peer *> _peers;
+
+ // containg a list of argtypes for fast access
+ QHash<const QMetaObject *, ExtendedMetaObject *> _extendedMetaObjects;
+
+ // SignalRelay for all manually attached signals
+ SignalRelay *_signalRelay;
+
+ // RPC function -> (object, slot ID)
+ typedef QPair<QObject *, int> MethodId;
+ typedef QMultiHash<QByteArray, MethodId> SlotHash;
+ SlotHash _attachedSlots;
+
+ // slaves for sync
+ typedef QHash<QString, SyncableObject *> ObjectId;
+ QHash<QByteArray, ObjectId> _syncSlave;
+
+ ProxyMode _proxyMode;
+ int _heartBeatInterval;
+ int _maxHeartBeatCount;
+
+ bool _secure; // determines if all connections are in a secured state (using ssl or internal connections)
+
+ friend class SignalRelay;
+ friend class SyncableObject;
+ friend class Peer;
+};
+
+
+// ==================================================
+// ExtendedMetaObject
+// ==================================================
+class SignalProxy::ExtendedMetaObject
+{
+ class MethodDescriptor
+ {
+ public:
+ MethodDescriptor(const QMetaMethod &method);
+ MethodDescriptor() : _returnType(-1), _minArgCount(-1), _receiverMode(SignalProxy::Client) {}
+
+ inline const QByteArray &methodName() const { return _methodName; }
+ inline const QList<int> &argTypes() const { return _argTypes; }
+ inline int returnType() const { return _returnType; }
+ inline int minArgCount() const { return _minArgCount; }
+ inline SignalProxy::ProxyMode receiverMode() const { return _receiverMode; }
+
+ private:
+ QByteArray _methodName;
+ QList<int> _argTypes;
+ int _returnType;
+ int _minArgCount;
+ SignalProxy::ProxyMode _receiverMode; // Only acceptable as a Sync Call if the receiving SignalProxy is in this mode.
+ };
+