cb1fcbf0f823a2911cbfe677f43c03feec63be48
[quassel.git] / src / common / signalproxy.h
1 /***************************************************************************
2  *   Copyright (C) 2005-07 by The Quassel IRC Development Team             *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
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.                                   *
9  *                                                                         *
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.                          *
14  *                                                                         *
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
21 #ifndef _RPCPEER_H_
22 #define _RPCPEER_H_
23
24 #include "qxtrpcpeer.h"
25 #include <QtCore>
26
27 class SignalProxy : public QObject {
28   Q_OBJECT
29
30   public:
31
32     enum ProxyType { Client, Server };
33
34     SignalProxy(ProxyType type, QIODevice *device = 0, QObject *parent = 0);
35     ~SignalProxy();
36
37     void attachSignal(QObject* sender, const char* signal, const QByteArray& rpcFunction = QByteArray());
38     void attachSlot(const QByteArray& rpcFunction, QObject* recv, const char* slot);
39
40   public slots:
41     void addPeer(QIODevice *device);
42
43     void sendSignal(const char *signal, QVariant p1 = QVariant(), QVariant p2 = QVariant(), QVariant p3 = QVariant(), QVariant p4 = QVariant(),
44               QVariant p5 = QVariant(), QVariant p6 = QVariant(), QVariant p7 = QVariant(), QVariant p8 = QVariant(), QVariant p9 = QVariant());
45
46     void detachObject(QObject* obj);
47
48     //void detachSender();
49
50   signals:
51     void peerDisconnected();
52
53   private slots:
54     void socketDisconnected();
55
56   private:
57     struct Connection {
58       QPointer<QxtRPCPeer> peer;
59       QPointer<QIODevice> device;
60     };
61
62     struct SignalDesc {
63       QObject *sender;
64       const char *signal;
65       QByteArray rpcFunction;
66
67       SignalDesc(QObject *sndr, const char *sig, const QByteArray &func) : sender(sndr), signal(sig), rpcFunction(func) {}
68     };
69
70     struct SlotDesc {
71       QByteArray rpcFunction;
72       QObject *recv;
73       const char *slot;
74
75       SlotDesc(const QByteArray& func, QObject* r, const char* s) : rpcFunction(func), recv(r), slot(s) {}
76     };
77
78     ProxyType type;
79     QList<Connection> peers;
80     QList<SignalDesc> attachedSignals;
81     QList<SlotDesc> attachedSlots;
82
83 };
84
85
86
87 #endif