d1fd9c7433c8d9403ea147e596c27a74dcf42040
[quassel.git] / core / coreproxy.h
1 /***************************************************************************
2  *   Copyright (C) 2005/06 by The Quassel 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 _COREPROXY_H_
22 #define _COREPROXY_H_
23
24 #include "proxy_common.h"
25 #include "message.h"
26
27 #include <QtCore>
28 #include <QTcpSocket>
29 #include <QTcpServer>
30
31 /** This class is the Core side of the proxy. The Core connects its signals and slots to it,
32  *  and the calls are marshalled and sent to (or received and unmarshalled from) the GUIProxy.
33  *  The connection functions are defined in main/main_core.cpp or main/main_mono.cpp.
34  */
35 class CoreProxy : public QObject {
36   Q_OBJECT
37
38   public:
39     CoreProxy();
40
41   public slots:
42     inline void csUpdateGlobalData(QString key, QVariant data)          { send(CS_UPDATE_GLOBAL_DATA, key, data); }
43     inline void csSendMessage(QString net, QString buf, Message msg)    { send(CS_SEND_MESSAGE, net, buf, QVariant::fromValue(msg)); }
44     inline void csSendStatusMsg(QString net, QString msg)               { send(CS_SEND_STATUS_MSG, net, msg); }
45     inline void csSetTopic(QString net, QString buf, QString topic)     { send(CS_SET_TOPIC, net, buf, topic); }
46     inline void csSetNicks(QString net, QString buf, QStringList nicks) { send(CS_SET_NICKS, net, buf, nicks); }
47
48   signals:
49     void gsPutGlobalData(QString, QVariant);
50     void gsUserInput(QString, QString, QString);
51     void gsRequestConnect(QStringList networks);
52
53   private:
54     void send(CoreSignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
55     void recv(GUISignal, QVariant arg1 = QVariant(), QVariant arg2 = QVariant(), QVariant arg3 = QVariant());
56     void sendToGUI(CoreSignal, QVariant arg1, QVariant arg2, QVariant arg3);
57
58     void processClientInit(QTcpSocket *socket, const QVariant &v);
59     void processClientUpdate(QTcpSocket *, QString key, QVariant data);
60
61   private slots:
62     void incomingConnection();
63     void clientHasData();
64     void clientDisconnected();
65     void updateGlobalData(QString key);
66
67   private:
68     QTcpServer server;
69     QList<QTcpSocket *> clients;
70     QHash<QTcpSocket *, quint32> blockSizes;
71
72   friend class GUIProxy;
73 };
74
75 extern CoreProxy *coreProxy;
76
77
78
79 #endif