X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Fsignalproxy.h;h=da9657fe08809debc9fd9519ab261c5835f4d7cc;hp=4e59e809c010db7cff4a611b24ae427a43b9c67a;hb=980f7e97e879e2f0493bfcdbe38a292eebbb9068;hpb=924e2c01204da172a071d34485936b379372e497 diff --git a/src/common/signalproxy.h b/src/common/signalproxy.h index 4e59e809..da9657fe 100644 --- a/src/common/signalproxy.h +++ b/src/common/signalproxy.h @@ -1,11 +1,11 @@ /*************************************************************************** - * Copyright (C) 2005-07 by the Quassel IRC Team * + * Copyright (C) 2005-08 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * - * (at your option) any later version. * + * (at your option) version 3. * * * * This program is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * @@ -30,6 +30,7 @@ #include class SignalRelay; +class SyncableObject; class QMetaObject; class SignalProxy : public QObject { @@ -61,33 +62,44 @@ public: bool attachSignal(QObject *sender, const char *signal, const QByteArray& sigName = QByteArray()); bool attachSlot(const QByteArray& sigName, QObject *recv, const char *slot); - void synchronize(QObject *obj); - void synchronizeAsMaster(QObject *obj); - void synchronizeAsSlave(QObject *obj); + void synchronize(SyncableObject *obj); + + void setInitialized(SyncableObject *obj); + bool isInitialized(SyncableObject *obj) const; + void requestInit(SyncableObject *obj); - void setInitialized(QObject *obj); - bool initialized(QObject *obj); - void requestInit(QObject *obj); - 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 + * at the device to reread the item. + */ static void writeDataToDevice(QIODevice *dev, const QVariant &item); + + //! Reads a data item from a device that has been written by writeDataToDevice(). + /** If not enough data bytes are available, the function returns false and the QVariant reference + * remains untouched. + */ static bool readDataFromDevice(QIODevice *dev, quint32 &blockSize, QVariant &item); static QString methodBaseName(const QMetaMethod &method); - + const QList &argTypes(QObject *obj, int methodId); const QByteArray &methodName(QObject *obj, int methodId); - const QHash &syncMap(QObject *obj); + const QHash &syncMap(SyncableObject *obj); + int updatedRemotelyId(SyncableObject *obj); typedef QHash > ArgHash; typedef QHash MethodNameHash; struct ClassInfo { ArgHash argTypes; MethodNameHash methodNames; - QHash syncMap; + int updatedRemotelyId; // id of the updatedRemotely() signal - makes things faster + QHash syncMap; }; void dumpProxyStats(); @@ -103,6 +115,7 @@ signals: void peerRemoved(QIODevice *obj); void connected(); void disconnected(); + void objectInitialized(SyncableObject *); private: void initServer(); @@ -111,7 +124,8 @@ private: void createClassInfo(QObject *obj); void setArgTypes(QObject *obj, int methodId); void setMethodName(QObject *obj, int methodId); - void setSyncMap(QObject *obj); + void setSyncMap(SyncableObject *obj); + void setUpdatedRemotelyId(QObject *obj); bool methodsMatch(const QMetaMethod &signal, const QMetaMethod &slot) const; @@ -124,14 +138,17 @@ private: void handleInitData(QIODevice *sender, const QVariantList ¶ms); void handleSignal(const QByteArray &funcName, const QVariantList ¶ms); - bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms); + bool invokeSlot(QObject *receiver, int methodId, const QVariantList ¶ms = QVariantList()); - QVariantMap initData(QObject *obj) const; - void setInitData(QObject *obj, const QVariantMap &properties); - bool setInitValue(QObject *obj, const QString &property, const QVariant &value); + QVariantMap initData(SyncableObject *obj) const; + void setInitData(SyncableObject *obj, const QVariantMap &properties); - void _detachSignals(QObject *sender); - void _detachSlots(QObject *receiver); +public: + void dumpSyncMap(SyncableObject *object); + +private: + // Hash of used QIODevices + QHash _peerByteCount; // containg a list of argtypes for fast access QHash _classInfo; @@ -145,14 +162,12 @@ private: SlotHash _attachedSlots; // slaves for sync - typedef QHash ObjectId; + typedef QHash ObjectId; QHash _syncSlave; - // Hash of used QIODevices - QHash _peerByteCount; ProxyMode _proxyMode; - + friend class SignalRelay; };