1 /***************************************************************************
2 * Copyright (C) 2005-07 by the Quassel IRC Team *
3 * devel@quassel-irc.org *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************
20 * SignalProxy has been inspired by QxtRPCPeer, part of libqxt, *
21 * the Qt eXTension Library <http://www.libqxt.org>. We would like to *
22 * thank Arvid "aep" Picciani and Adam "ahigerd" Higerd for providing *
23 * QxtRPCPeer, valuable input and the genius idea to (ab)use Qt's *
24 * Meta Object System for transmitting signals over the network. *
26 * To make contribution back into libqxt possible, redistribution and *
27 * modification of this file is additionally allowed under the terms of *
28 * the Common Public License, version 1.0, as published by IBM. *
29 ***************************************************************************/
31 #ifndef _SIGNALPROXY_H_
32 #define _SIGNALPROXY_H_
43 class SignalProxy : public QObject {
52 SignalProxy(QObject* parent);
53 SignalProxy(ProxyMode mode, QObject* parent);
54 SignalProxy(ProxyMode mode, QIODevice* device, QObject* parent);
55 virtual ~SignalProxy();
57 void setProxyMode(ProxyMode mode);
58 ProxyMode proxyMode() const;
60 bool addPeer(QIODevice *iodev);
61 void removePeer(QIODevice *iodev = 0);
63 bool attachSignal(QObject* sender, const char* signal, const QByteArray& sigName = QByteArray());
64 bool attachSlot(const QByteArray& sigName, QObject* recv, const char* slot);
66 void detachObject(QObject *obj);
67 void detachSignals(QObject *sender);
68 void detachSlots(QObject *receiver);
70 void call(const char *signal , QVariant p1, QVariant p2, QVariant p3, QVariant p4,
71 QVariant p5, QVariant p6, QVariant p7, QVariant p8, QVariant p9);
72 void call(const QByteArray &funcName, const QVariantList ¶ms);
74 static void writeDataToDevice(QIODevice *dev, const QVariant &item);
75 static bool readDataFromDevice(QIODevice *dev, quint32 &blockSize, QVariant &item);
77 const QList<int> &argTypes(QObject* obj, int methodId);
78 const QByteArray &methodName(QObject* obj, int methodId);
80 typedef QHash<int, QList<int> > ArgHash;
81 typedef QHash<int, QByteArray> MethodNameHash;
84 MethodNameHash methodNames;
85 // QHash<int, int> syncMap
88 void dumpProxyStats();
93 void removePeerBySender();
96 void peerRemoved(QIODevice* obj);
101 void createClassInfo(QObject *obj);
102 void setArgTypes(QObject* obj, int methodId);
103 void setMethodName(QObject* obj, int methodId);
105 void receivePeerSignal(const QVariant &packedFunc);
107 void _detachSignals(QObject *sender);
108 void _detachSlots(QObject *receiver);
110 // containg a list of argtypes for fast access
111 QHash<QByteArray, ClassInfo*> _classInfo;
113 // we use one SignalRelay per QObject
114 QHash<QObject*, SignalRelay *> _relayHash;
116 // RPC function -> (object, slot ID)
117 typedef QPair<QObject*, int> MethodId;
118 typedef QMultiHash<QByteArray, MethodId> SlotHash;
119 SlotHash _attachedSlots;
122 // Hash of used QIODevices
123 QHash<QIODevice*, quint32> _peerByteCount;
125 ProxyMode _proxyMode;