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 struct QDBusMetaObject;
64 class QDBusAbstractInterface;
65 class QDBusBusService;
67 class QDBusConnectionPrivate: public QObject
72 enum ConnectionMode { InvalidMode, ServerMode, ClientMode };
76 Watcher(): watch(0), read(0), write(0) {}
78 QSocketNotifier *read;
79 QSocketNotifier *write;
84 inline SignalHook() : obj(0), midx(-1) { }
85 QString sender, path, signature;
98 inline bool operator<(const QString &other) const
99 { return name < other; }
102 inline ObjectTreeNode() : obj(0), flags(0) { }
103 inline ~ObjectTreeNode() { clear(); }
106 foreach (const Data &entry, children) {
115 QVector<Data> children;
120 typedef QMultiHash<int, Watcher> WatcherHash;
121 typedef QHash<int, DBusTimeout *> TimeoutHash;
122 typedef QMultiHash<QString, SignalHook> SignalHookHash;
123 typedef QHash<QString, QDBusMetaObject* > MetaObjectHash;
127 QDBusConnectionPrivate(QObject *parent = 0);
128 ~QDBusConnectionPrivate();
130 void bindToApplication();
132 void setConnection(DBusConnection *connection);
133 void setServer(DBusServer *server);
134 void closeConnection();
135 void timerEvent(QTimerEvent *e);
137 QString getNameOwner(const QString &service);
139 int send(const QDBusMessage &message) const;
140 QDBusMessage sendWithReply(const QDBusMessage &message, int mode);
141 int sendWithReplyAsync(const QDBusMessage &message, QObject *receiver,
143 void connectSignal(const QString &key, const SignalHook &hook);
144 void registerObject(const ObjectTreeNode *node);
145 void connectRelay(const QString &service, const QString &path, const QString &interface,
146 QDBusAbstractInterface *receiver, const char *signal);
147 void disconnectRelay(const QString &service, const QString &path, const QString &interface,
148 QDBusAbstractInterface *receiver, const char *signal);
150 bool handleSignal(const QString &key, const QDBusMessage &msg);
151 bool handleSignal(const QDBusMessage &msg);
152 bool handleObjectCall(const QDBusMessage &message);
155 bool activateSignal(const SignalHook& hook, const QDBusMessage &msg);
156 bool activateCall(QObject* object, int flags, const QDBusMessage &msg);
157 bool activateObject(const ObjectTreeNode *node, const QDBusMessage &msg);
158 bool activateInternalFilters(const ObjectTreeNode *node, const QDBusMessage &msg);
160 void postCallDeliveryEvent(CallDeliveryEvent *data);
161 CallDeliveryEvent *postedCallDeliveryEvent();
162 void deliverCall(const CallDeliveryEvent &data) const;
164 QDBusInterfacePrivate *findInterface(const QString &service, const QString &path,
165 const QString &interface);
168 virtual void customEvent(QEvent *event);
171 QDBusMetaObject *findMetaObject(const QString &service, const QString &path,
172 const QString &interface);
177 void socketRead(int);
178 void socketWrite(int);
179 void objectDestroyed(QObject *o);
180 void relaySignal(QObject *obj, const char *interface, const char *name, const QVariantList &args);
183 // public member variables
184 QString name; // this connection's name
187 QDBusError lastError;
192 DBusConnection *connection;
194 QDBusBusService *busService;
196 WatcherHash watchers;
197 TimeoutHash timeouts;
198 SignalHookHash signalHooks;
199 QList<DBusTimeout *> pendingTimeouts;
201 ObjectTreeNode rootNode;
202 MetaObjectHash cachedMetaObjects;
204 QMutex callDeliveryMutex;
205 CallDeliveryEvent *callDeliveryState; // protected by the callDeliveryMutex mutex
209 static int messageMetaType;
210 static int registerMessageMetaType();
211 static int findSlot(QObject *obj, const QByteArray &normalizedName, QList<int>& params);
212 static bool prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key,
213 const QString &service, const QString &path,
214 const QString &interface, const QString &name,
215 QObject *receiver, const char *signal, int minMIdx,
216 bool buildSignature);
217 static DBusHandlerResult messageFilter(DBusConnection *, DBusMessage *, void *);
218 static void messageResultReceived(DBusPendingCall *, void *);
221 class QDBusReplyWaiter: public QEventLoop
225 QDBusMessage replyMsg;
228 void reply(const QDBusMessage &msg);
232 extern int qDBusParametersForMethod(const QMetaMethod &mm, QList<int>& metaTypes);
233 extern int qDBusNameToTypeId(const char *name);
234 extern bool qDBusCheckAsyncTag(const char *tag);
236 // in qdbusinternalfilters.cpp
237 extern QString qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode *node);
238 extern void qDBusIntrospectObject(const QDBusConnectionPrivate::ObjectTreeNode *node,
239 const QDBusMessage &msg);
240 extern void qDBusPropertyGet(const QDBusConnectionPrivate::ObjectTreeNode *node,
241 const QDBusMessage &msg);
242 extern void qDBusPropertySet(const QDBusConnectionPrivate::ObjectTreeNode *node,
243 const QDBusMessage &msg);