1 /* qdbusconnection_p.h QDBusConnection private object
3 * Copyright (C) 2005 Harald Fernengel <harry@kdevelop.org>
4 * Copyright (C) 2006 Trolltech AS. All rights reserved.
5 * Author: Thiago Macieira <thiago.macieira@trolltech.com>
7 * Licensed under the Academic Free License version 2.1
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software Foundation
21 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
29 // This file is not part of the public API. This header file may
30 // change from version to version without notice, or even be
37 #ifndef QDBUSCONNECTION_P_H
38 #define QDBUSCONNECTION_P_H
40 #include "qdbuserror.h"
42 #include <QtCore/qatomic.h>
43 #include <QtCore/qeventloop.h>
44 #include <QtCore/qhash.h>
45 #include <QtCore/qmutex.h>
46 #include <QtCore/qobject.h>
47 #include <QtCore/qpointer.h>
48 #include <QtCore/qreadwritelock.h>
49 #include <QtCore/qvarlengtharray.h>
50 #include <QtCore/qvector.h>
52 #include <dbus/dbus.h>
54 #include "qdbusmessage.h"
57 class QSocketNotifier;
59 class QDBusObjectPrivate;
60 class CallDeliveryEvent;
62 class QDBusInterfacePrivate;
63 class QDBusMetaObject;
64 class QDBusAbstractInterface;
65 class QDBusBusService;
67 typedef struct DBusConnection;
68 typedef struct DBusServer;
70 class QDBusConnectionPrivate: public QObject
75 enum ConnectionMode { InvalidMode, ServerMode, ClientMode };
79 Watcher(): watch(0), read(0), write(0) {}
81 QSocketNotifier *read;
82 QSocketNotifier *write;
87 inline SignalHook() : obj(0), midx(-1) { }
88 QString sender, path, signature;
101 inline bool operator<(const QString &other) const
102 { return name < other; }
105 inline ObjectTreeNode() : obj(0), flags(0) { }
106 inline ~ObjectTreeNode() { clear(); }
109 foreach (const Data &entry, children) {
118 QVector<Data> children;
123 typedef QMultiHash<int, Watcher> WatcherHash;
124 typedef QHash<int, DBusTimeout *> TimeoutHash;
125 typedef QMultiHash<QString, SignalHook> SignalHookHash;
126 typedef QHash<QString, QDBusMetaObject* > MetaObjectHash;
130 QDBusConnectionPrivate(QObject *parent = 0);
131 ~QDBusConnectionPrivate();
133 void bindToApplication();
135 void setConnection(DBusConnection *connection);
136 void setServer(DBusServer *server);
137 void closeConnection();
138 void timerEvent(QTimerEvent *e);
140 QString getNameOwner(const QString &service);
142 int send(const QDBusMessage &message) const;
143 QDBusMessage sendWithReply(const QDBusMessage &message, int mode);
144 int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
146 void connectSignal(const QString &key, const SignalHook &hook);
147 void registerObject(const ObjectTreeNode *node);
148 void connectRelay(const QString &service, const QString &path, const QString &interface,
149 QDBusAbstractInterface *receiver, const char *signal);
150 void disconnectRelay(const QString &service, const QString &path, const QString &interface,
151 QDBusAbstractInterface *receiver, const char *signal);
153 bool handleSignal(const QString &key, const QDBusMessage &msg);
154 bool handleSignal(const QDBusMessage &msg);
155 bool handleObjectCall(const QDBusMessage &message);
158 bool activateSignal(const SignalHook& hook, const QDBusMessage &msg);
159 bool activateCall(QObject* object, int flags, const QDBusMessage &msg);
160 bool activateObject(const ObjectTreeNode *node, const QDBusMessage &msg);
161 bool activateInternalFilters(const ObjectTreeNode *node, const QDBusMessage &msg);
163 void postCallDeliveryEvent(CallDeliveryEvent *data);
164 CallDeliveryEvent *postedCallDeliveryEvent();
165 void deliverCall(const CallDeliveryEvent &data) const;
167 QDBusInterfacePrivate *findInterface(const QString &service, const QString &path,
168 const QString &interface);
171 virtual void customEvent(QEvent *event);
174 QDBusMetaObject *findMetaObject(const QString &service, const QString &path,
175 const QString &interface);
180 void socketRead(int);
181 void socketWrite(int);
182 void objectDestroyed(QObject *o);
183 void relaySignal(QObject *obj, const char *interface, const char *name, const QVariantList &args);
186 // public member variables
187 QString name; // this connection's name
190 QDBusError lastError;
195 DBusConnection *connection;
197 QDBusBusService *busService;
199 WatcherHash watchers;
200 TimeoutHash timeouts;
201 SignalHookHash signalHooks;
202 QList<DBusTimeout *> pendingTimeouts;
204 ObjectTreeNode rootNode;
205 MetaObjectHash cachedMetaObjects;
207 QMutex callDeliveryMutex;
208 CallDeliveryEvent *callDeliveryState; // protected by the callDeliveryMutex mutex
212 static int messageMetaType;
213 static int registerMessageMetaType();
214 static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<int>& params);
215 static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
216 const QString &service, const QString &path,
217 const QString &interface, const QString &name,
218 QObject *receiver, const char *signal, int minMIdx,
219 bool buildSignature);
220 static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *);
221 static void messageResultReceived(DBusPendingCall *, void *);
224 class QDBusReplyWaiter: public QEventLoop
228 QDBusMessage replyMsg;
231 void reply(const QDBusMessage &msg);
235 extern int qDBusParametersForMethod(const QMetaMethod &mm, QList<int>& metaTypes);
236 extern int qDBusNameToTypeId(const char *name);
237 extern bool qDBusCheckAsyncTag(const char *tag);
239 // in qdbusinternalfilters.cpp
240 extern QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode *node);
241 extern void qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode *node,
242 const QDBusMessage &msg);
243 extern void qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode *node,
244 const QDBusMessage &msg);
245 extern void qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode *node,
246 const QDBusMessage &msg);