X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsignalproxy.h;h=9bae6364685f8265da8876c3abcb1f62d59c322b;hp=584626e0ff4089e1eb136373ea77ee1a957faf60;hb=f6b9eeda207d42c99fc3e9085631722cf2ec83dc;hpb=d5095471627f6399b277d7c6d06b6bbcb915c57f diff --git a/src/common/signalproxy.h b/src/common/signalproxy.h index 584626e0..9bae6364 100644 --- a/src/common/signalproxy.h +++ b/src/common/signalproxy.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005-08 by the Quassel Project * + * Copyright (C) 2005-09 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -31,7 +31,6 @@ #include #include -class SignalRelay; class SyncableObject; struct QMetaObject; @@ -42,6 +41,8 @@ class SignalProxy : public QObject { class IODevicePeer; class SignalProxyPeer; + class SignalRelay; + public: enum ProxyMode { Server, @@ -85,13 +86,6 @@ public: void synchronize(SyncableObject *obj); -// void setInitialized(SyncableObject *obj); -// bool isInitialized(SyncableObject *obj) const; - void detachObject(QObject *obj); - void detachSignals(QObject *sender); - void detachSlots(QObject *receiver); - void stopSync(SyncableObject *obj); - //! Writes a QVariant to a device. /** The data item is prefixed with the resulting blocksize, * so the corresponding function readDataFromDevice() can check if enough data is available @@ -106,18 +100,26 @@ public: static bool readDataFromDevice(QIODevice *dev, quint32 &blockSize, QVariant &item, bool compressed = false); class ExtendedMetaObject; - ExtendedMetaObject *extendedMetaObject(const QObject *obj) const; - void createExtendedMetaObject(const QObject *obj); + ExtendedMetaObject *extendedMetaObject(const QMetaObject *meta) const; + ExtendedMetaObject *createExtendedMetaObject(const QMetaObject *meta); + inline ExtendedMetaObject *extendedMetaObject(const QObject *obj) const { return extendedMetaObject(metaObject(obj)); } + inline ExtendedMetaObject *createExtendedMetaObject(const QObject *obj) { return createExtendedMetaObject(metaObject(obj)); } bool isSecure() const { return _secure; } void dumpProxyStats(); +public slots: + void detachObject(QObject *obj); + void detachSignals(QObject *sender); + void detachSlots(QObject *receiver); + void stopSync(QObject *obj); + protected: void customEvent(QEvent *event); + void sync_call__(const SyncableObject *obj, ProxyMode modeType, const char *funcname, va_list ap); private slots: void dataAvailable(); - void detachSender(); void removePeerBySender(); void objectRenamed(const QString &newname, const QString &oldname); void objectRenamed(const QByteArray &classname, const QString &newname, const QString &oldname); @@ -178,8 +180,8 @@ private: // containg a list of argtypes for fast access QHash _extendedMetaObjects; - // we use one SignalRelay per QObject - QHash _relayHash; + // SignalRelay for all manually attached signals + SignalRelay *_signalRelay; // RPC function -> (object, slot ID) typedef QPair MethodId; @@ -197,6 +199,7 @@ private: bool _secure; // determines if all connections are in a secured state (using ssl or internal connections) friend class SignalRelay; + friend class SyncableObject; }; @@ -204,33 +207,55 @@ private: // 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 &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 _argTypes; + int _returnType; + int _minArgCount; + SignalProxy::ProxyMode _receiverMode; // Only acceptable as a Sync Call if the receiving SignalProxy is in this mode. + }; + public: ExtendedMetaObject(const QMetaObject *meta); - const QList &argTypes(int methodId); - const int &returnType(int methodId); - const int &minArgCount(int methodId); - const QByteArray &methodName(int methodId); - const QHash &syncMap(); + inline const QByteArray &methodName(int methodId) { return methodDescriptor(methodId).methodName(); } + inline const QList &argTypes(int methodId) { return methodDescriptor(methodId).argTypes(); } + inline int returnType(int methodId) { return methodDescriptor(methodId).returnType(); } + inline int minArgCount(int methodId) { return methodDescriptor(methodId).minArgCount(); } + inline SignalProxy::ProxyMode receiverMode(int methodId) { return methodDescriptor(methodId).receiverMode(); } + + inline int methodId(const QByteArray &methodName) { return _methodIds.contains(methodName) ? _methodIds[methodName] : -1; } + + inline int updatedRemotelyId() { return _updatedRemotelyId; } + + inline const QHash &slotMap() { return _methodIds; } const QHash &receiveMap(); - int updatedRemotelyId(); + + const QMetaObject *metaObject() const { return _meta; } static QByteArray methodName(const QMetaMethod &method); - static bool methodsMatch(const QMetaMethod &signal, const QMetaMethod &slot); - static QString methodBaseName(const QMetaMethod &method); + static QString ExtendedMetaObject::methodBaseName(const QMetaMethod &method); private: - typedef QHash > ArgHash; - typedef QHash MethodNameHash; + const MethodDescriptor &methodDescriptor(int methodId); const QMetaObject *_meta; - ArgHash _argTypes; - QHash _returnType; - QHash _minArgCount; - MethodNameHash _methodNames; int _updatedRemotelyId; // id of the updatedRemotely() signal - makes things faster - QHash _syncMap; - QHash _receiveMap; + + QHash _methods; + QHash _methodIds; + QHash _receiveMap; // if slot x is called then hand over the result to slot y };