2006-02-13 John (J5) Palmieri <johnp@redhat.com>
[platform/upstream/dbus.git] / qt / qdbusconnection_p.h
1 /* qdbusconnection_p.h QDBusConnection private object
2  *
3  * Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
4  *
5  * Licensed under the Academic Free License version 2.1
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  *
21  */
22
23 //
24 //  W A R N I N G
25 //  -------------
26 //
27 // This file is not part of the public API.  This header file may
28 // change from version to version without notice, or even be
29 // removed.
30 //
31 // We mean it.
32 //
33 //
34
35 #ifndef QDBUSCONNECTION_P_H
36 #define QDBUSCONNECTION_P_H
37
38 #include "qdbuserror.h"
39
40 #include <QtCore/qatomic.h>
41 #include <QtCore/qhash.h>
42 #include <QtCore/qobject.h>
43 #include <QtCore/qpointer.h>
44 #include <QtCore/qvarlengtharray.h>
45
46 #include <dbus/dbus.h>
47
48 class QDBusMessage;
49 class QSocketNotifier;
50 class QTimerEvent;
51
52 typedef struct DBusConnection;
53 typedef struct DBusServer;
54
55 class QDBusConnectionPrivate: public QObject
56 {
57     Q_OBJECT
58 public:
59     QDBusConnectionPrivate(QObject *parent = 0);
60     ~QDBusConnectionPrivate();
61
62     void bindToApplication();
63
64     void setConnection(DBusConnection *connection);
65     void setServer(DBusServer *server);
66     void closeConnection();
67     void timerEvent(QTimerEvent *e);
68
69     bool handleSignal(DBusMessage *msg) const;
70     bool handleObjectCall(DBusMessage *message) const;
71     bool handleError();
72
73 public slots:
74     void socketRead(int);
75     void socketWrite(int);
76     void objectDestroyed(QObject *o);
77
78 public:
79     DBusError error;
80     QDBusError lastError;
81
82     enum ConnectionMode { InvalidMode, ServerMode, ClientMode };
83
84     QAtomic ref;
85     ConnectionMode mode;
86     DBusConnection *connection;
87     DBusServer *server;
88
89     static int messageMetaType;
90     static int registerMessageMetaType();
91     bool handleSignal(const QString &path, const QDBusMessage &msg) const;
92     int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
93                            const char *method) const;
94
95     struct Watcher
96     {
97         Watcher(): watch(0), read(0), write(0) {}
98         DBusWatch *watch;
99         QSocketNotifier *read;
100         QSocketNotifier *write;
101     };
102     typedef QMultiHash<int, Watcher> WatcherHash;
103     WatcherHash watchers;
104
105     typedef QHash<int, DBusTimeout *> TimeoutHash;
106     TimeoutHash timeouts;
107
108     struct SignalHook
109     {
110         QString interface, name;
111         QPointer<QObject> obj;
112         int midx;
113         QVarLengthArray<int, 10> params;
114
115         bool setSlot(const char *slotName);
116     };
117
118     typedef QMultiHash<QString, SignalHook> SignalHookHash;
119     SignalHookHash signalHooks;
120
121     struct ObjectHook
122     {
123         QString interface;
124         QPointer<QObject> obj;
125     };
126     typedef QMultiHash<QString, ObjectHook> ObjectHookHash;
127     ObjectHookHash objectHooks;
128     QList<DBusTimeout *> pendingTimeouts;
129 };
130
131 #endif