Moving the message format code (i.e. msg -> formatted string) from Style into Message.
[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 detachSender();
47     void detachObject(QObject *);
48
49   signals:
50     void peerDisconnected();
51
52   private slots:
53     void socketDisconnected();
54
55   private:
56     struct Connection {
57       QPointer<QxtRPCPeer> peer;
58       QPointer<QIODevice> device;
59     };
60
61     struct SignalDesc {
62       QObject *sender;
63       QByteArray signal;
64       QByteArray rpcFunction;
65
66       SignalDesc(QObject *sndr, const char *sig, const QByteArray &func) : sender(sndr), signal(sig), rpcFunction(func) {}
67     };
68
69     struct SlotDesc {
70       QByteArray rpcFunction;
71       QObject *recv;
72       QByteArray slot;
73
74       SlotDesc(const QByteArray& func, QObject* r, const char* s) : rpcFunction(func), recv(r), slot(s) {}
75     };
76
77     ProxyType type;
78     QList<Connection> peers;
79     QList<SignalDesc> attachedSignals;
80     QList<SlotDesc> attachedSlots;
81
82 };
83
84
85
86 #endif