1 /****************************************************************************
3 ** Copyright (C) Qxt Foundation. Some rights reserved.
5 ** This file is part of the QxtNetwork module of the Qt eXTension library
7 ** This library is free software; you can redistribute it and/or modify it
8 ** under the terms of th Common Public License, version 1.0, as published by
11 ** This file is provided "AS IS", without WARRANTIES OR CONDITIONS OF ANY
12 ** KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, ANY
13 ** WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
14 ** FITNESS FOR A PARTICULAR PURPOSE.
16 ** You should have received a copy of the CPL along with this file.
17 ** See the LICENSE file and the cpl1.0.txt file included with the source
18 ** distribution for more information. If you did not receive a copy of the
19 ** license, contact the Qxt Foundation.
21 ** <http://libqxt.sourceforge.net> <foundation@libqxt.org>
23 ****************************************************************************/
25 #ifndef _SIGNALPROXY_H_
26 #define _SIGNALPROXY_H_
36 class ClassIntrospector;
38 class SignalProxy : public QObject {
48 SignalProxy(QObject* parent);
49 SignalProxy(RPCTypes type, QObject* parent);
50 SignalProxy(RPCTypes type, QIODevice* device, QObject* parent);
51 virtual ~SignalProxy();
53 void setRPCType(RPCTypes type);
54 RPCTypes rpcType() const;
56 bool maxPeersReached();
58 bool addPeer(QIODevice *iodev);
59 void removePeer(QIODevice *iodev = 0);
61 bool attachSignal(QObject* sender, const char* signal, const QByteArray& rpcFunction = QByteArray());
62 bool attachSlot(const QByteArray& rpcFunction, QObject* recv, const char* slot);
64 void detachObject(QObject *obj);
65 void detachSignals(QObject *sender);
66 void detachSlots(QObject *receiver);
68 void call(const char *signal , QVariant p1, QVariant p2, QVariant p3, QVariant p4,
69 QVariant p5, QVariant p6, QVariant p7, QVariant p8, QVariant p9);
70 void call(const QByteArray &funcName, const QVariantList ¶ms);
72 static void writeDataToDevice(QIODevice *dev, const QVariant &item);
73 static bool readDataFromDevice(QIODevice *dev, quint32 &blockSize, QVariant &item);
75 const QList<int> &argTypes(QObject* obj, int methodId);
76 const QByteArray &methodName(QObject* obj, int methodId);
78 typedef QHash<int, QList<int> > ArgHash;
79 typedef QHash<int, QByteArray> MethodNameHash;
82 MethodNameHash methodNames;
83 // QHash<int, int> syncMap
89 void removePeerBySender();
92 void peerRemoved(QIODevice* obj);
97 void createClassInfo(QObject *obj);
98 void setArgTypes(QObject* obj, int methodId);
99 void setMethodName(QObject* obj, int methodId);
101 void receivePeerSignal(const QVariant &packedFunc);
103 void _detachSignals(QObject *sender);
104 void _detachSlots(QObject *receiver);
106 // containg a list of argtypes for fast access
107 QHash<QByteArray, ClassInfo*> _classInfo;
109 // we use one introSpector per QObject
110 QHash<QObject*, ClassIntrospector*> _specHash;
112 // RPC function -> (object, slot ID)
113 typedef QPair<QObject*, int> MethodId;
114 typedef QMultiHash<QByteArray, MethodId> SlotHash;
115 SlotHash _attachedSlots;
118 // Hash of used QIODevices
119 QHash<QIODevice*, quint32> _peerByteCount;