Introducing SignalProxy NG! We're no longer using
[quassel.git] / src / common / signalproxy.h
index 4e59e80..da9657f 100644 (file)
@@ -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 <QByteArray>
 
 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<int> &argTypes(QObject *obj, int methodId);
   const QByteArray &methodName(QObject *obj, int methodId);
-  const QHash<int, int> &syncMap(QObject *obj);
+  const QHash<QByteArray, int> &syncMap(SyncableObject *obj);
+  int updatedRemotelyId(SyncableObject *obj);
 
   typedef QHash<int, QList<int> > ArgHash;
   typedef QHash<int, QByteArray> MethodNameHash;
   struct ClassInfo {
     ArgHash argTypes;
     MethodNameHash methodNames;
-    QHash<int, int> syncMap;
+    int updatedRemotelyId; // id of the updatedRemotely() signal - makes things faster
+    QHash<QByteArray, int> 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 &params);
   void handleSignal(const QByteArray &funcName, const QVariantList &params);
 
-  bool invokeSlot(QObject *receiver, int methodId, const QVariantList &params);
+  bool invokeSlot(QObject *receiver, int methodId, const QVariantList &params = 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<QIODevice*, quint32> _peerByteCount;
 
   // containg a list of argtypes for fast access
   QHash<const QMetaObject *, ClassInfo*> _classInfo;
@@ -145,14 +162,12 @@ private:
   SlotHash _attachedSlots;
 
   // slaves for sync
-  typedef QHash<QString, QObject *> ObjectId;
+  typedef QHash<QString, SyncableObject *> ObjectId;
   QHash<QByteArray, ObjectId> _syncSlave;
 
-  // Hash of used QIODevices
-  QHash<QIODevice*, quint32> _peerByteCount;
 
   ProxyMode _proxyMode;
-
+  
   friend class SignalRelay;
 };