Moved detachObject(QObject *) to public slots
[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     void detachObject(QObject* obj);
43   
44     void sendSignal(const char *signal, QVariant p1 = QVariant(), QVariant p2 = QVariant(), QVariant p3 = QVariant(), QVariant p4 = QVariant(),
45               QVariant p5 = QVariant(), QVariant p6 = QVariant(), QVariant p7 = QVariant(), QVariant p8 = QVariant(), QVariant p9 = QVariant());
46
47     void detachObject(QObject* obj);
48
49     //void detachSender();
50
51   signals:
52     void peerDisconnected();
53
54   private slots:
55     void socketDisconnected();
56
57   private:
58     struct Connection {
59       QPointer<QxtRPCPeer> peer;
60       QPointer<QIODevice> device;
61     };
62
63     struct SignalDesc {
64       QObject *sender;
65       const char *signal;
66       QByteArray rpcFunction;
67
68       SignalDesc(QObject *sndr, const char *sig, const QByteArray &func) : sender(sndr), signal(sig), rpcFunction(func) {}
69     };
70
71     struct SlotDesc {
72       QByteArray rpcFunction;
73       QObject *recv;
74       const char *slot;
75
76       SlotDesc(const QByteArray& func, QObject* r, const char* s) : rpcFunction(func), recv(r), slot(s) {}
77     };
78
79     ProxyType type;
80     QList<Connection> peers;
81     QList<SignalDesc> attachedSignals;
82     QList<SlotDesc> attachedSlots;
83
84 };
85
86
87
88 #endif