author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Wed, 21 Apr 2010 11:15:19 +0300 | |
branch | RCL_3 |
changeset 11 | 25a739ee40f4 |
parent 7 | 3f74d0d4af4c |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtDBus module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#include <qcoreapplication.h> |
|
43 |
#include <qdebug.h> |
|
44 |
#include <qmetaobject.h> |
|
45 |
#include <qobject.h> |
|
46 |
#include <qsocketnotifier.h> |
|
47 |
#include <qstringlist.h> |
|
48 |
#include <qtimer.h> |
|
49 |
#include <qthread.h> |
|
50 |
||
51 |
#include "qdbusargument.h" |
|
52 |
#include "qdbusconnection_p.h" |
|
53 |
#include "qdbusinterface_p.h" |
|
54 |
#include "qdbusmessage.h" |
|
55 |
#include "qdbusmetatype.h" |
|
56 |
#include "qdbusmetatype_p.h" |
|
57 |
#include "qdbusabstractadaptor.h" |
|
58 |
#include "qdbusabstractadaptor_p.h" |
|
59 |
#include "qdbusutil_p.h" |
|
60 |
#include "qdbusmessage_p.h" |
|
61 |
#include "qdbuscontext_p.h" |
|
62 |
#include "qdbuspendingcall_p.h" |
|
63 |
#include "qdbusintegrator_p.h" |
|
64 |
||
65 |
#include "qdbusthreaddebug_p.h" |
|
66 |
||
67 |
QT_BEGIN_NAMESPACE |
|
68 |
||
69 |
static bool isDebugging; |
|
70 |
#define qDBusDebug if (!::isDebugging); else qDebug |
|
71 |
||
72 |
static inline QDebug operator<<(QDebug dbg, const QThread *th) |
|
73 |
{ |
|
74 |
dbg.nospace() << "QThread(ptr=" << (void*)th; |
|
75 |
if (th && !th->objectName().isEmpty()) |
|
76 |
dbg.nospace() << ", name=" << th->objectName(); |
|
77 |
dbg.nospace() << ')'; |
|
78 |
return dbg.space(); |
|
79 |
} |
|
80 |
||
81 |
#if QDBUS_THREAD_DEBUG |
|
82 |
static inline QDebug operator<<(QDebug dbg, const QDBusConnectionPrivate *conn) |
|
83 |
{ |
|
84 |
dbg.nospace() << "QDBusConnection(" |
|
85 |
<< "ptr=" << (void*)conn |
|
86 |
<< ", name=" << conn->name |
|
87 |
<< ", baseService=" << conn->baseService |
|
88 |
<< ", thread="; |
|
89 |
if (conn->thread() == QThread::currentThread()) |
|
90 |
dbg.nospace() << "same thread"; |
|
91 |
else |
|
92 |
dbg.nospace() << conn->thread(); |
|
93 |
dbg.nospace() << ')'; |
|
94 |
return dbg.space(); |
|
95 |
} |
|
96 |
||
97 |
Q_AUTOTEST_EXPORT void qdbusDefaultThreadDebug(int action, int condition, QDBusConnectionPrivate *conn) |
|
98 |
{ |
|
99 |
qDBusDebug() << QThread::currentThread() |
|
100 |
<< "QtDBus threading action" << action |
|
101 |
<< (condition == QDBusLockerBase::BeforeLock ? "before lock" : |
|
102 |
condition == QDBusLockerBase::AfterLock ? "after lock" : |
|
103 |
condition == QDBusLockerBase::BeforeUnlock ? "before unlock" : |
|
104 |
condition == QDBusLockerBase::AfterUnlock ? "after unlock" : |
|
105 |
condition == QDBusLockerBase::BeforePost ? "before event posting" : |
|
106 |
condition == QDBusLockerBase::AfterPost ? "after event posting" : |
|
107 |
condition == QDBusLockerBase::BeforeDeliver ? "before event delivery" : |
|
108 |
condition == QDBusLockerBase::AfterDeliver ? "after event delivery" : |
|
109 |
condition == QDBusLockerBase::BeforeAcquire ? "before acquire" : |
|
110 |
condition == QDBusLockerBase::AfterAcquire ? "after acquire" : |
|
111 |
condition == QDBusLockerBase::BeforeRelease ? "before release" : |
|
112 |
condition == QDBusLockerBase::AfterRelease ? "after release" : |
|
113 |
"condition unknown") |
|
114 |
<< "in connection" << conn; |
|
115 |
} |
|
116 |
Q_AUTOTEST_EXPORT qdbusThreadDebugFunc qdbusThreadDebug = 0; |
|
117 |
#endif |
|
118 |
||
119 |
typedef void (*QDBusSpyHook)(const QDBusMessage&); |
|
120 |
typedef QVarLengthArray<QDBusSpyHook, 4> QDBusSpyHookList; |
|
121 |
Q_GLOBAL_STATIC(QDBusSpyHookList, qDBusSpyHookList) |
|
122 |
||
123 |
extern "C" { |
|
124 |
||
125 |
// libdbus-1 callbacks |
|
126 |
||
127 |
static bool qDBusRealAddTimeout(QDBusConnectionPrivate *d, DBusTimeout *timeout, int ms); |
|
128 |
static dbus_bool_t qDBusAddTimeout(DBusTimeout *timeout, void *data) |
|
129 |
{ |
|
130 |
Q_ASSERT(timeout); |
|
131 |
Q_ASSERT(data); |
|
132 |
||
133 |
// qDebug("addTimeout %d", q_dbus_timeout_get_interval(timeout)); |
|
134 |
||
135 |
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); |
|
136 |
||
137 |
if (!q_dbus_timeout_get_enabled(timeout)) |
|
138 |
return true; |
|
139 |
||
140 |
QDBusWatchAndTimeoutLocker locker(AddTimeoutAction, d); |
|
141 |
if (QCoreApplication::instance() && QThread::currentThread() == d->thread()) { |
|
142 |
// correct thread |
|
143 |
return qDBusRealAddTimeout(d, timeout, q_dbus_timeout_get_interval(timeout)); |
|
144 |
} else { |
|
145 |
// wrong thread: sync back |
|
146 |
QDBusConnectionCallbackEvent *ev = new QDBusConnectionCallbackEvent; |
|
147 |
ev->subtype = QDBusConnectionCallbackEvent::AddTimeout; |
|
148 |
d->timeoutsPendingAdd.append(qMakePair(timeout, q_dbus_timeout_get_interval(timeout))); |
|
149 |
d->postEventToThread(AddTimeoutAction, d, ev); |
|
150 |
return true; |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
static bool qDBusRealAddTimeout(QDBusConnectionPrivate *d, DBusTimeout *timeout, int ms) |
|
155 |
{ |
|
156 |
Q_ASSERT(d->timeouts.keys(timeout).isEmpty()); |
|
157 |
||
158 |
int timerId = d->startTimer(ms); |
|
159 |
if (!timerId) |
|
160 |
return false; |
|
161 |
||
162 |
d->timeouts[timerId] = timeout; |
|
163 |
return true; |
|
164 |
} |
|
165 |
||
166 |
static void qDBusRemoveTimeout(DBusTimeout *timeout, void *data) |
|
167 |
{ |
|
168 |
Q_ASSERT(timeout); |
|
169 |
Q_ASSERT(data); |
|
170 |
||
171 |
// qDebug("removeTimeout"); |
|
172 |
||
173 |
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); |
|
174 |
||
175 |
QDBusWatchAndTimeoutLocker locker(RemoveTimeoutAction, d); |
|
176 |
||
177 |
// is it pending addition? |
|
178 |
QDBusConnectionPrivate::PendingTimeoutList::iterator pit = d->timeoutsPendingAdd.begin(); |
|
179 |
while (pit != d->timeoutsPendingAdd.end()) { |
|
180 |
if (pit->first == timeout) |
|
181 |
pit = d->timeoutsPendingAdd.erase(pit); |
|
182 |
else |
|
183 |
++pit; |
|
184 |
} |
|
185 |
||
186 |
// is it a running timer? |
|
187 |
bool correctThread = QCoreApplication::instance() && QThread::currentThread() == d->thread(); |
|
188 |
QDBusConnectionPrivate::TimeoutHash::iterator it = d->timeouts.begin(); |
|
189 |
while (it != d->timeouts.end()) { |
|
190 |
if (it.value() == timeout) { |
|
191 |
if (correctThread) { |
|
192 |
// correct thread |
|
193 |
d->killTimer(it.key()); |
|
194 |
} else { |
|
195 |
// incorrect thread or no application, post an event for later |
|
196 |
QDBusConnectionCallbackEvent *ev = new QDBusConnectionCallbackEvent; |
|
197 |
ev->subtype = QDBusConnectionCallbackEvent::KillTimer; |
|
198 |
ev->timerId = it.key(); |
|
199 |
d->postEventToThread(KillTimerAction, d, ev); |
|
200 |
} |
|
201 |
it = d->timeouts.erase(it); |
|
202 |
break; |
|
203 |
} else { |
|
204 |
++it; |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
static void qDBusToggleTimeout(DBusTimeout *timeout, void *data) |
|
210 |
{ |
|
211 |
Q_ASSERT(timeout); |
|
212 |
Q_ASSERT(data); |
|
213 |
||
214 |
//qDebug("ToggleTimeout"); |
|
215 |
||
216 |
qDBusRemoveTimeout(timeout, data); |
|
217 |
qDBusAddTimeout(timeout, data); |
|
218 |
} |
|
219 |
||
220 |
static bool qDBusRealAddWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int flags, int fd); |
|
221 |
static dbus_bool_t qDBusAddWatch(DBusWatch *watch, void *data) |
|
222 |
{ |
|
223 |
Q_ASSERT(watch); |
|
224 |
Q_ASSERT(data); |
|
225 |
||
226 |
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); |
|
227 |
||
228 |
int flags = q_dbus_watch_get_flags(watch); |
|
229 |
int fd = q_dbus_watch_get_fd(watch); |
|
230 |
||
231 |
if (QCoreApplication::instance() && QThread::currentThread() == d->thread()) { |
|
232 |
return qDBusRealAddWatch(d, watch, flags, fd); |
|
233 |
} else { |
|
234 |
QDBusConnectionCallbackEvent *ev = new QDBusConnectionCallbackEvent; |
|
235 |
ev->subtype = QDBusConnectionCallbackEvent::AddWatch; |
|
236 |
ev->watch = watch; |
|
237 |
ev->fd = fd; |
|
238 |
ev->extra = flags; |
|
239 |
d->postEventToThread(AddWatchAction, d, ev); |
|
240 |
return true; |
|
241 |
} |
|
242 |
} |
|
243 |
||
244 |
static bool qDBusRealAddWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int flags, int fd) |
|
245 |
{ |
|
246 |
QDBusConnectionPrivate::Watcher watcher; |
|
247 |
||
248 |
QDBusWatchAndTimeoutLocker locker(AddWatchAction, d); |
|
249 |
if (flags & DBUS_WATCH_READABLE) { |
|
250 |
//qDebug("addReadWatch %d", fd); |
|
251 |
watcher.watch = watch; |
|
252 |
if (QCoreApplication::instance()) { |
|
253 |
watcher.read = new QSocketNotifier(fd, QSocketNotifier::Read, d); |
|
254 |
watcher.read->setEnabled(q_dbus_watch_get_enabled(watch)); |
|
255 |
d->connect(watcher.read, SIGNAL(activated(int)), SLOT(socketRead(int))); |
|
256 |
} |
|
257 |
} |
|
258 |
if (flags & DBUS_WATCH_WRITABLE) { |
|
259 |
//qDebug("addWriteWatch %d", fd); |
|
260 |
watcher.watch = watch; |
|
261 |
if (QCoreApplication::instance()) { |
|
262 |
watcher.write = new QSocketNotifier(fd, QSocketNotifier::Write, d); |
|
263 |
watcher.write->setEnabled(q_dbus_watch_get_enabled(watch)); |
|
264 |
d->connect(watcher.write, SIGNAL(activated(int)), SLOT(socketWrite(int))); |
|
265 |
} |
|
266 |
} |
|
267 |
d->watchers.insertMulti(fd, watcher); |
|
268 |
||
269 |
return true; |
|
270 |
} |
|
271 |
||
272 |
static void qDBusRemoveWatch(DBusWatch *watch, void *data) |
|
273 |
{ |
|
274 |
Q_ASSERT(watch); |
|
275 |
Q_ASSERT(data); |
|
276 |
||
277 |
//qDebug("remove watch"); |
|
278 |
||
279 |
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); |
|
280 |
int fd = q_dbus_watch_get_fd(watch); |
|
281 |
||
282 |
QDBusWatchAndTimeoutLocker locker(RemoveWatchAction, d); |
|
283 |
QDBusConnectionPrivate::WatcherHash::iterator i = d->watchers.find(fd); |
|
284 |
while (i != d->watchers.end() && i.key() == fd) { |
|
285 |
if (i.value().watch == watch) { |
|
286 |
if (QCoreApplication::instance() && QThread::currentThread() == d->thread()) { |
|
287 |
// correct thread, delete the socket notifiers |
|
288 |
delete i.value().read; |
|
289 |
delete i.value().write; |
|
290 |
} else { |
|
291 |
// incorrect thread or no application, use delete later |
|
292 |
if (i->read) |
|
293 |
i->read->deleteLater(); |
|
294 |
if (i->write) |
|
295 |
i->write->deleteLater(); |
|
296 |
} |
|
297 |
i = d->watchers.erase(i); |
|
298 |
} else { |
|
299 |
++i; |
|
300 |
} |
|
301 |
} |
|
302 |
} |
|
303 |
||
304 |
static void qDBusRealToggleWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int fd); |
|
305 |
static void qDBusToggleWatch(DBusWatch *watch, void *data) |
|
306 |
{ |
|
307 |
Q_ASSERT(watch); |
|
308 |
Q_ASSERT(data); |
|
309 |
||
310 |
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); |
|
311 |
int fd = q_dbus_watch_get_fd(watch); |
|
312 |
||
313 |
if (QCoreApplication::instance() && QThread::currentThread() == d->thread()) { |
|
314 |
qDBusRealToggleWatch(d, watch, fd); |
|
315 |
} else { |
|
316 |
QDBusConnectionCallbackEvent *ev = new QDBusConnectionCallbackEvent; |
|
317 |
ev->subtype = QDBusConnectionCallbackEvent::ToggleWatch; |
|
318 |
ev->watch = watch; |
|
319 |
ev->fd = fd; |
|
320 |
d->postEventToThread(ToggleWatchAction, d, ev); |
|
321 |
} |
|
322 |
} |
|
323 |
||
324 |
static void qDBusRealToggleWatch(QDBusConnectionPrivate *d, DBusWatch *watch, int fd) |
|
325 |
{ |
|
326 |
QDBusWatchAndTimeoutLocker locker(ToggleWatchAction, d); |
|
327 |
||
328 |
QDBusConnectionPrivate::WatcherHash::iterator i = d->watchers.find(fd); |
|
329 |
while (i != d->watchers.end() && i.key() == fd) { |
|
330 |
if (i.value().watch == watch) { |
|
331 |
bool enabled = q_dbus_watch_get_enabled(watch); |
|
332 |
int flags = q_dbus_watch_get_flags(watch); |
|
333 |
||
334 |
//qDebug("toggle watch %d to %d (write: %d, read: %d)", q_dbus_watch_get_fd(watch), enabled, flags & DBUS_WATCH_WRITABLE, flags & DBUS_WATCH_READABLE); |
|
335 |
||
336 |
if (flags & DBUS_WATCH_READABLE && i.value().read) |
|
337 |
i.value().read->setEnabled(enabled); |
|
338 |
if (flags & DBUS_WATCH_WRITABLE && i.value().write) |
|
339 |
i.value().write->setEnabled(enabled); |
|
340 |
return; |
|
341 |
} |
|
342 |
++i; |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
static void qDBusUpdateDispatchStatus(DBusConnection *connection, DBusDispatchStatus new_status, void *data) |
|
347 |
{ |
|
348 |
Q_ASSERT(connection); |
|
349 |
Q_UNUSED(connection); |
|
350 |
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); |
|
351 |
||
352 |
static int slotId; // 0 is QObject::deleteLater() |
|
353 |
if (!slotId) { |
|
354 |
// it's ok to do this: there's no race condition because the store is atomic |
|
355 |
// and we always set to the same value |
|
356 |
slotId = QDBusConnectionPrivate::staticMetaObject.indexOfSlot("doDispatch()"); |
|
357 |
} |
|
358 |
||
359 |
//qDBusDebug() << "Updating dispatcher status" << slotId; |
|
360 |
if (new_status == DBUS_DISPATCH_DATA_REMAINS) |
|
361 |
QDBusConnectionPrivate::staticMetaObject.method(slotId). |
|
362 |
invoke(d, Qt::QueuedConnection); |
|
363 |
} |
|
364 |
||
365 |
static void qDBusNewConnection(DBusServer *server, DBusConnection *connection, void *data) |
|
366 |
{ |
|
367 |
// ### We may want to separate the server from the QDBusConnectionPrivate |
|
368 |
Q_ASSERT(server); Q_UNUSED(server); |
|
369 |
Q_ASSERT(connection); |
|
370 |
Q_ASSERT(data); |
|
371 |
||
372 |
// keep the connection alive |
|
373 |
q_dbus_connection_ref(connection); |
|
374 |
QDBusConnectionPrivate *d = new QDBusConnectionPrivate; |
|
375 |
||
376 |
// setConnection does the error handling for us |
|
377 |
QDBusErrorInternal error; |
|
378 |
d->setPeer(connection, error); |
|
379 |
||
380 |
QDBusConnection retval = QDBusConnectionPrivate::q(d); |
|
381 |
d->setBusService(retval); |
|
382 |
||
383 |
//d->name = QString::number(reinterpret_cast<int>(d)); |
|
384 |
//d->setConnection(d->name, d); |
|
385 |
||
386 |
// make QDBusServer emit the newConnection signal |
|
387 |
QDBusConnectionPrivate *server_d = static_cast<QDBusConnectionPrivate *>(data); |
|
388 |
server_d->serverConnection(retval); |
|
389 |
} |
|
390 |
||
391 |
} // extern "C" |
|
392 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
393 |
static QByteArray buildMatchRule(const QString &service, |
0 | 394 |
const QString &objectPath, const QString &interface, |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
395 |
const QString &member, const QStringList &argMatch, const QString & /*signature*/) |
0 | 396 |
{ |
397 |
QString result = QLatin1String("type='signal',"); |
|
398 |
QString keyValue = QLatin1String("%1='%2',"); |
|
399 |
||
400 |
if (!service.isEmpty()) |
|
401 |
result += keyValue.arg(QLatin1String("sender"), service); |
|
402 |
if (!objectPath.isEmpty()) |
|
403 |
result += keyValue.arg(QLatin1String("path"), objectPath); |
|
404 |
if (!interface.isEmpty()) |
|
405 |
result += keyValue.arg(QLatin1String("interface"), interface); |
|
406 |
if (!member.isEmpty()) |
|
407 |
result += keyValue.arg(QLatin1String("member"), member); |
|
408 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
409 |
// add the argument string-matching now |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
410 |
if (!argMatch.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
411 |
keyValue = QLatin1String("arg%1='%2',"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
412 |
for (int i = 0; i < argMatch.count(); ++i) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
413 |
if (!argMatch.at(i).isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
414 |
result += keyValue.arg(i).arg(argMatch.at(i)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
415 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
416 |
|
0 | 417 |
result.chop(1); // remove ending comma |
418 |
return result.toLatin1(); |
|
419 |
} |
|
420 |
||
421 |
static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root, |
|
422 |
const QString &fullpath, int &usedLength, |
|
423 |
QDBusConnectionPrivate::ObjectTreeNode &result) |
|
424 |
{ |
|
425 |
int start = 0; |
|
426 |
int length = fullpath.length(); |
|
427 |
if (fullpath.at(0) == QLatin1Char('/')) |
|
428 |
start = 1; |
|
429 |
||
430 |
// walk the object tree |
|
431 |
const QDBusConnectionPrivate::ObjectTreeNode *node = root; |
|
432 |
while (start < length && node && !(node->flags & QDBusConnection::ExportChildObjects)) { |
|
433 |
int end = fullpath.indexOf(QLatin1Char('/'), start); |
|
434 |
end = (end == -1 ? length : end); |
|
435 |
QStringRef pathComponent(&fullpath, start, end - start); |
|
436 |
||
437 |
QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it = |
|
438 |
qLowerBound(node->children.constBegin(), node->children.constEnd(), pathComponent); |
|
439 |
if (it != node->children.constEnd() && it->name == pathComponent) |
|
440 |
// match |
|
441 |
node = it; |
|
442 |
else |
|
443 |
node = 0; |
|
444 |
||
445 |
start = end + 1; |
|
446 |
} |
|
447 |
||
448 |
// found our object |
|
449 |
usedLength = (start > length ? length : start); |
|
450 |
if (node) { |
|
451 |
if (node->obj || !node->children.isEmpty()) |
|
452 |
result = *node; |
|
453 |
else |
|
454 |
// there really is no object here |
|
455 |
// we're just looking at an unused space in the QVector |
|
456 |
node = 0; |
|
457 |
} |
|
458 |
return node; |
|
459 |
} |
|
460 |
||
461 |
static QObject *findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *root, |
|
462 |
const QString &fullpath, int start) |
|
463 |
{ |
|
464 |
int length = fullpath.length(); |
|
465 |
||
466 |
// any object in the tree can tell us to switch to its own object tree: |
|
467 |
const QDBusConnectionPrivate::ObjectTreeNode *node = root; |
|
468 |
if (node && node->flags & QDBusConnection::ExportChildObjects) { |
|
469 |
QObject *obj = node->obj; |
|
470 |
||
471 |
while (obj) { |
|
472 |
if (start >= length) |
|
473 |
// we're at the correct level |
|
474 |
return obj; |
|
475 |
||
476 |
int pos = fullpath.indexOf(QLatin1Char('/'), start); |
|
477 |
pos = (pos == -1 ? length : pos); |
|
478 |
QStringRef pathComponent(&fullpath, start, pos - start); |
|
479 |
||
480 |
const QObjectList children = obj->children(); |
|
481 |
||
482 |
// find a child with the proper name |
|
483 |
QObject *next = 0; |
|
484 |
QObjectList::ConstIterator it = children.constBegin(); |
|
485 |
QObjectList::ConstIterator end = children.constEnd(); |
|
486 |
for ( ; it != end; ++it) |
|
487 |
if ((*it)->objectName() == pathComponent) { |
|
488 |
next = *it; |
|
489 |
break; |
|
490 |
} |
|
491 |
||
492 |
if (!next) |
|
493 |
break; |
|
494 |
||
495 |
obj = next; |
|
496 |
start = pos + 1; |
|
497 |
} |
|
498 |
} |
|
499 |
||
500 |
// object not found |
|
501 |
return 0; |
|
502 |
} |
|
503 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
504 |
static bool shouldWatchService(const QString &service) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
505 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
506 |
return !service.isEmpty() && !service.startsWith(QLatin1Char(':')); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
507 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
508 |
|
0 | 509 |
extern QDBUS_EXPORT void qDBusAddSpyHook(QDBusSpyHook); |
510 |
void qDBusAddSpyHook(QDBusSpyHook hook) |
|
511 |
{ |
|
512 |
qDBusSpyHookList()->append(hook); |
|
513 |
} |
|
514 |
||
515 |
extern "C" { |
|
516 |
static DBusHandlerResult |
|
517 |
qDBusSignalFilter(DBusConnection *connection, DBusMessage *message, void *data) |
|
518 |
{ |
|
519 |
Q_ASSERT(data); |
|
520 |
Q_UNUSED(connection); |
|
521 |
QDBusConnectionPrivate *d = static_cast<QDBusConnectionPrivate *>(data); |
|
522 |
if (d->mode == QDBusConnectionPrivate::InvalidMode) |
|
523 |
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
|
524 |
||
525 |
QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(message); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
526 |
qDBusDebug() << d << "got message:" << amsg; |
0 | 527 |
|
528 |
return d->handleMessage(amsg) ? |
|
529 |
DBUS_HANDLER_RESULT_HANDLED : |
|
530 |
DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
bool QDBusConnectionPrivate::handleMessage(const QDBusMessage &amsg) |
|
535 |
{ |
|
536 |
const QDBusSpyHookList *list = qDBusSpyHookList(); |
|
537 |
for (int i = 0; i < list->size(); ++i) { |
|
538 |
qDBusDebug() << "calling the message spy hook"; |
|
539 |
(*(*list)[i])(amsg); |
|
540 |
} |
|
541 |
||
542 |
switch (amsg.type()) { |
|
543 |
case QDBusMessage::SignalMessage: |
|
544 |
handleSignal(amsg); |
|
545 |
return true; |
|
546 |
break; |
|
547 |
case QDBusMessage::MethodCallMessage: |
|
548 |
handleObjectCall(amsg); |
|
549 |
return true; |
|
550 |
case QDBusMessage::ReplyMessage: |
|
551 |
case QDBusMessage::ErrorMessage: |
|
552 |
return false; // we don't handle those here |
|
553 |
case QDBusMessage::InvalidMessage: |
|
554 |
Q_ASSERT_X(false, "QDBusConnection", "Invalid message found when processing"); |
|
555 |
break; |
|
556 |
} |
|
557 |
||
558 |
return false; |
|
559 |
} |
|
560 |
||
561 |
static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNode &haystack) |
|
562 |
{ |
|
563 |
QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator it = haystack.children.begin(); |
|
564 |
QDBusConnectionPrivate::ObjectTreeNode::DataList::Iterator end = haystack.children.end(); |
|
565 |
for ( ; it != end; ++it) |
|
566 |
huntAndDestroy(needle, *it); |
|
567 |
||
568 |
if (needle == haystack.obj) { |
|
569 |
haystack.obj = 0; |
|
570 |
haystack.flags = 0; |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
static void huntAndEmit(DBusConnection *connection, DBusMessage *msg, |
|
575 |
QObject *needle, const QDBusConnectionPrivate::ObjectTreeNode &haystack, |
|
576 |
bool isScriptable, bool isAdaptor, const QString &path = QString()) |
|
577 |
{ |
|
578 |
QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it = haystack.children.constBegin(); |
|
579 |
QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator end = haystack.children.constEnd(); |
|
580 |
for ( ; it != end; ++it) |
|
581 |
huntAndEmit(connection, msg, needle, *it, isScriptable, isAdaptor, path + QLatin1Char('/') + it->name); |
|
582 |
||
583 |
if (needle == haystack.obj) { |
|
584 |
// is this a signal we should relay? |
|
585 |
if (isAdaptor && (haystack.flags & QDBusConnection::ExportAdaptors) == 0) |
|
586 |
return; // no: it comes from an adaptor and we're not exporting adaptors |
|
587 |
else if (!isAdaptor) { |
|
588 |
int mask = isScriptable |
|
589 |
? QDBusConnection::ExportScriptableSignals |
|
590 |
: QDBusConnection::ExportNonScriptableSignals; |
|
591 |
if ((haystack.flags & mask) == 0) |
|
592 |
return; // signal was not exported |
|
593 |
} |
|
594 |
||
595 |
QByteArray p = path.toLatin1(); |
|
596 |
if (p.isEmpty()) |
|
597 |
p = "/"; |
|
598 |
qDBusDebug() << QThread::currentThread() << "emitting signal at" << p; |
|
599 |
DBusMessage *msg2 = q_dbus_message_copy(msg); |
|
600 |
q_dbus_message_set_path(msg2, p); |
|
601 |
q_dbus_connection_send(connection, msg2, 0); |
|
602 |
q_dbus_message_unref(msg2); |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
static int findSlot(const QMetaObject *mo, const QByteArray &name, int flags, |
|
607 |
const QString &signature_, QList<int>& metaTypes) |
|
608 |
{ |
|
609 |
QByteArray msgSignature = signature_.toLatin1(); |
|
610 |
||
611 |
for (int idx = mo->methodCount() - 1 ; idx >= QObject::staticMetaObject.methodCount(); --idx) { |
|
612 |
QMetaMethod mm = mo->method(idx); |
|
613 |
||
614 |
// check access: |
|
615 |
if (mm.access() != QMetaMethod::Public) |
|
616 |
continue; |
|
617 |
||
618 |
// check type: |
|
619 |
if (mm.methodType() != QMetaMethod::Slot) |
|
620 |
continue; |
|
621 |
||
622 |
// check name: |
|
623 |
QByteArray slotname = mm.signature(); |
|
624 |
int paren = slotname.indexOf('('); |
|
625 |
if (paren != name.length() || !slotname.startsWith(name)) |
|
626 |
continue; |
|
627 |
||
628 |
int returnType = qDBusNameToTypeId(mm.typeName()); |
|
629 |
bool isAsync = qDBusCheckAsyncTag(mm.tag()); |
|
630 |
bool isScriptable = mm.attributes() & QMetaMethod::Scriptable; |
|
631 |
||
632 |
// consistency check: |
|
633 |
if (isAsync && returnType != QMetaType::Void) |
|
634 |
continue; |
|
635 |
||
636 |
int inputCount = qDBusParametersForMethod(mm, metaTypes); |
|
637 |
if (inputCount == -1) |
|
638 |
continue; // problem parsing |
|
639 |
||
640 |
metaTypes[0] = returnType; |
|
641 |
bool hasMessage = false; |
|
642 |
if (inputCount > 0 && |
|
643 |
metaTypes.at(inputCount) == QDBusMetaTypeId::message) { |
|
644 |
// "no input parameters" is allowed as long as the message meta type is there |
|
645 |
hasMessage = true; |
|
646 |
--inputCount; |
|
647 |
} |
|
648 |
||
649 |
// try to match the parameters |
|
650 |
int i; |
|
651 |
QByteArray reconstructedSignature; |
|
652 |
for (i = 1; i <= inputCount; ++i) { |
|
653 |
const char *typeSignature = QDBusMetaType::typeToSignature( metaTypes.at(i) ); |
|
654 |
if (!typeSignature) |
|
655 |
break; // invalid |
|
656 |
||
657 |
reconstructedSignature += typeSignature; |
|
658 |
if (!msgSignature.startsWith(reconstructedSignature)) |
|
659 |
break; |
|
660 |
} |
|
661 |
||
662 |
if (reconstructedSignature != msgSignature) |
|
663 |
continue; // we didn't match them all |
|
664 |
||
665 |
if (hasMessage) |
|
666 |
++i; |
|
667 |
||
668 |
// make sure that the output parameters have signatures too |
|
669 |
if (returnType != 0 && QDBusMetaType::typeToSignature(returnType) == 0) |
|
670 |
continue; |
|
671 |
||
672 |
bool ok = true; |
|
673 |
for (int j = i; ok && j < metaTypes.count(); ++j) |
|
674 |
if (QDBusMetaType::typeToSignature(metaTypes.at(i)) == 0) |
|
675 |
ok = false; |
|
676 |
if (!ok) |
|
677 |
continue; |
|
678 |
||
679 |
// consistency check: |
|
680 |
if (isAsync && metaTypes.count() > i + 1) |
|
681 |
continue; |
|
682 |
||
683 |
if (isScriptable && (flags & QDBusConnection::ExportScriptableSlots) == 0) |
|
684 |
continue; // not exported |
|
685 |
if (!isScriptable && (flags & QDBusConnection::ExportNonScriptableSlots) == 0) |
|
686 |
continue; // not exported |
|
687 |
||
688 |
// if we got here, this slot matched |
|
689 |
return idx; |
|
690 |
} |
|
691 |
||
692 |
// no slot matched |
|
693 |
return -1; |
|
694 |
} |
|
695 |
||
696 |
QDBusCallDeliveryEvent* QDBusConnectionPrivate::prepareReply(QDBusConnectionPrivate *target, |
|
697 |
QObject *object, int idx, |
|
698 |
const QList<int> &metaTypes, |
|
699 |
const QDBusMessage &msg) |
|
700 |
{ |
|
701 |
Q_ASSERT(object); |
|
702 |
Q_UNUSED(object); |
|
703 |
||
704 |
int n = metaTypes.count() - 1; |
|
705 |
if (metaTypes[n] == QDBusMetaTypeId::message) |
|
706 |
--n; |
|
707 |
||
708 |
// check that types match |
|
709 |
for (int i = 0; i < n; ++i) |
|
710 |
if (metaTypes.at(i + 1) != msg.arguments().at(i).userType() && |
|
711 |
msg.arguments().at(i).userType() != qMetaTypeId<QDBusArgument>()) |
|
712 |
return 0; // no match |
|
713 |
||
714 |
// we can deliver |
|
715 |
// prepare for the call |
|
716 |
return new QDBusCallDeliveryEvent(QDBusConnection(target), idx, target, msg, metaTypes); |
|
717 |
} |
|
718 |
||
719 |
void QDBusConnectionPrivate::activateSignal(const QDBusConnectionPrivate::SignalHook& hook, |
|
720 |
const QDBusMessage &msg) |
|
721 |
{ |
|
722 |
// This is called by QDBusConnectionPrivate::handleSignal to deliver a signal |
|
723 |
// that was received from D-Bus |
|
724 |
// |
|
725 |
// Signals are delivered to slots if the parameters match |
|
726 |
// Slots can have less parameters than there are on the message |
|
727 |
// Slots can optionally have one final parameter that is a QDBusMessage |
|
728 |
// Slots receive read-only copies of the message (i.e., pass by value or by const-ref) |
|
729 |
QDBusCallDeliveryEvent *call = prepareReply(this, hook.obj, hook.midx, hook.params, msg); |
|
730 |
if (call) |
|
731 |
postEventToThread(ActivateSignalAction, hook.obj, call); |
|
732 |
} |
|
733 |
||
734 |
bool QDBusConnectionPrivate::activateCall(QObject* object, int flags, const QDBusMessage &msg) |
|
735 |
{ |
|
736 |
// This is called by QDBusConnectionPrivate::handleObjectCall to place a call |
|
737 |
// to a slot on the object. |
|
738 |
// |
|
739 |
// The call is delivered to the first slot that matches the following conditions: |
|
740 |
// - has the same name as the message's target member |
|
741 |
// - ALL of the message's types are found in slot's parameter list |
|
742 |
// - optionally has one more parameter of type QDBusMessage |
|
743 |
// If none match, then the slot of the same name as the message target and with |
|
744 |
// the first type of QDBusMessage is delivered. |
|
745 |
// |
|
746 |
// The D-Bus specification requires that all MethodCall messages be replied to, unless the |
|
747 |
// caller specifically waived this requirement. This means that we inspect if the user slot |
|
748 |
// generated a reply and, if it didn't, we will. Obviously, if the user slot doesn't take a |
|
749 |
// QDBusMessage parameter, it cannot generate a reply. |
|
750 |
// |
|
751 |
// When a return message is generated, the slot's return type, if any, will be placed |
|
752 |
// in the message's first position. If there are non-const reference parameters to the |
|
753 |
// slot, they must appear at the end and will be placed in the subsequent message |
|
754 |
// positions. |
|
755 |
||
756 |
static const char cachePropertyName[] = "_qdbus_slotCache"; |
|
757 |
||
758 |
if (!object) |
|
759 |
return false; |
|
760 |
||
761 |
Q_ASSERT_X(QThread::currentThread() == object->thread(), |
|
762 |
"QDBusConnection: internal threading error", |
|
763 |
"function called for an object that is in another thread!!"); |
|
764 |
||
765 |
QDBusSlotCache slotCache = |
|
766 |
qvariant_cast<QDBusSlotCache>(object->property(cachePropertyName)); |
|
767 |
QString cacheKey = msg.member(), signature = msg.signature(); |
|
768 |
if (!signature.isEmpty()) { |
|
769 |
cacheKey.reserve(cacheKey.length() + 1 + signature.length()); |
|
770 |
cacheKey += QLatin1Char('.'); |
|
771 |
cacheKey += signature; |
|
772 |
} |
|
773 |
||
774 |
QDBusSlotCache::Hash::ConstIterator cacheIt = slotCache.hash.constFind(cacheKey); |
|
775 |
while (cacheIt != slotCache.hash.constEnd() && cacheIt->flags != flags && |
|
776 |
cacheIt.key() == cacheKey) |
|
777 |
++cacheIt; |
|
778 |
if (cacheIt == slotCache.hash.constEnd() || cacheIt.key() != cacheKey) |
|
779 |
{ |
|
780 |
// not cached, analyse the meta object |
|
781 |
const QMetaObject *mo = object->metaObject(); |
|
782 |
QByteArray memberName = msg.member().toUtf8(); |
|
783 |
||
784 |
// find a slot that matches according to the rules above |
|
785 |
QDBusSlotCache::Data slotData; |
|
786 |
slotData.flags = flags; |
|
787 |
slotData.slotIdx = ::findSlot(mo, memberName, flags, msg.signature(), slotData.metaTypes); |
|
788 |
if (slotData.slotIdx == -1) { |
|
789 |
// ### this is where we want to add the connection as an arg too |
|
790 |
// try with no parameters, but with a QDBusMessage |
|
791 |
slotData.slotIdx = ::findSlot(mo, memberName, flags, QString(), slotData.metaTypes); |
|
792 |
if (slotData.metaTypes.count() != 2 || |
|
793 |
slotData.metaTypes.at(1) != QDBusMetaTypeId::message) { |
|
794 |
// not found |
|
795 |
// save the negative lookup |
|
796 |
slotData.slotIdx = -1; |
|
797 |
slotData.metaTypes.clear(); |
|
798 |
slotCache.hash.insert(cacheKey, slotData); |
|
799 |
object->setProperty(cachePropertyName, qVariantFromValue(slotCache)); |
|
800 |
return false; |
|
801 |
} |
|
802 |
} |
|
803 |
||
804 |
// save to the cache |
|
805 |
slotCache.hash.insert(cacheKey, slotData); |
|
806 |
object->setProperty(cachePropertyName, qVariantFromValue(slotCache)); |
|
807 |
||
808 |
// found the slot to be called |
|
809 |
deliverCall(object, flags, msg, slotData.metaTypes, slotData.slotIdx); |
|
810 |
return true; |
|
811 |
} else if (cacheIt->slotIdx == -1) { |
|
812 |
// negative cache |
|
813 |
return false; |
|
814 |
} else { |
|
815 |
// use the cache |
|
816 |
deliverCall(object, flags, msg, cacheIt->metaTypes, cacheIt->slotIdx); |
|
817 |
return true; |
|
818 |
} |
|
819 |
} |
|
820 |
||
821 |
void QDBusConnectionPrivate::deliverCall(QObject *object, int /*flags*/, const QDBusMessage &msg, |
|
822 |
const QList<int> &metaTypes, int slotIdx) |
|
823 |
{ |
|
824 |
Q_ASSERT_X(!object || QThread::currentThread() == object->thread(), |
|
825 |
"QDBusConnection: internal threading error", |
|
826 |
"function called for an object that is in another thread!!"); |
|
827 |
||
828 |
QVarLengthArray<void *, 10> params; |
|
829 |
params.reserve(metaTypes.count()); |
|
830 |
||
831 |
QVariantList auxParameters; |
|
832 |
// let's create the parameter list |
|
833 |
||
834 |
// first one is the return type -- add it below |
|
835 |
params.append(0); |
|
836 |
||
837 |
// add the input parameters |
|
838 |
int i; |
|
839 |
int pCount = qMin(msg.arguments().count(), metaTypes.count() - 1); |
|
840 |
for (i = 1; i <= pCount; ++i) { |
|
841 |
int id = metaTypes[i]; |
|
842 |
if (id == QDBusMetaTypeId::message) |
|
843 |
break; |
|
844 |
||
845 |
const QVariant &arg = msg.arguments().at(i - 1); |
|
846 |
if (arg.userType() == id) |
|
847 |
// no conversion needed |
|
848 |
params.append(const_cast<void *>(arg.constData())); |
|
849 |
else if (arg.userType() == qMetaTypeId<QDBusArgument>()) { |
|
850 |
// convert to what the function expects |
|
851 |
void *null = 0; |
|
852 |
auxParameters.append(QVariant(id, null)); |
|
853 |
||
854 |
const QDBusArgument &in = |
|
855 |
*reinterpret_cast<const QDBusArgument *>(arg.constData()); |
|
856 |
QVariant &out = auxParameters[auxParameters.count() - 1]; |
|
857 |
||
858 |
if (!QDBusMetaType::demarshall(in, out.userType(), out.data())) |
|
859 |
qFatal("Internal error: demarshalling function for type '%s' (%d) failed!", |
|
860 |
out.typeName(), out.userType()); |
|
861 |
||
862 |
params.append(const_cast<void *>(out.constData())); |
|
863 |
} else { |
|
864 |
qFatal("Internal error: got invalid meta type %d (%s) " |
|
865 |
"when trying to convert to meta type %d (%s)", |
|
866 |
arg.userType(), QMetaType::typeName(arg.userType()), |
|
867 |
id, QMetaType::typeName(id)); |
|
868 |
} |
|
869 |
} |
|
870 |
||
871 |
bool takesMessage = false; |
|
872 |
if (metaTypes.count() > i && metaTypes[i] == QDBusMetaTypeId::message) { |
|
873 |
params.append(const_cast<void*>(static_cast<const void*>(&msg))); |
|
874 |
takesMessage = true; |
|
875 |
++i; |
|
876 |
} |
|
877 |
||
878 |
// output arguments |
|
879 |
QVariantList outputArgs; |
|
880 |
void *null = 0; |
|
881 |
if (metaTypes[0] != QMetaType::Void) { |
|
882 |
QVariant arg(metaTypes[0], null); |
|
883 |
outputArgs.append( arg ); |
|
884 |
params[0] = const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData()); |
|
885 |
} |
|
886 |
for ( ; i < metaTypes.count(); ++i) { |
|
887 |
QVariant arg(metaTypes[i], null); |
|
888 |
outputArgs.append( arg ); |
|
889 |
params.append(const_cast<void*>(outputArgs.at( outputArgs.count() - 1 ).constData())); |
|
890 |
} |
|
891 |
||
892 |
// make call: |
|
893 |
bool fail; |
|
894 |
if (!object) { |
|
895 |
fail = true; |
|
896 |
} else { |
|
897 |
// FIXME: save the old sender! |
|
898 |
QDBusContextPrivate context(QDBusConnection(this), msg); |
|
899 |
QDBusContextPrivate *old = QDBusContextPrivate::set(object, &context); |
|
900 |
QDBusConnectionPrivate::setSender(this); |
|
901 |
||
902 |
QPointer<QObject> ptr = object; |
|
903 |
fail = object->qt_metacall(QMetaObject::InvokeMetaMethod, |
|
904 |
slotIdx, params.data()) >= 0; |
|
905 |
QDBusConnectionPrivate::setSender(0); |
|
906 |
// the object might be deleted in the slot |
|
907 |
if (!ptr.isNull()) |
|
908 |
QDBusContextPrivate::set(object, old); |
|
909 |
} |
|
910 |
||
911 |
// do we create a reply? Only if the caller is waiting for a reply and one hasn't been sent |
|
912 |
// yet. |
|
913 |
if (msg.isReplyRequired() && !msg.isDelayedReply()) { |
|
914 |
if (!fail) { |
|
915 |
// normal reply |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
916 |
qDBusDebug() << this << "Automatically sending reply:" << outputArgs; |
0 | 917 |
send(msg.createReply(outputArgs)); |
918 |
} else { |
|
919 |
// generate internal error |
|
920 |
qWarning("Internal error: Failed to deliver message"); |
|
921 |
send(msg.createErrorReply(QDBusError::InternalError, |
|
922 |
QLatin1String("Failed to deliver message"))); |
|
923 |
} |
|
924 |
} |
|
925 |
||
926 |
return; |
|
927 |
} |
|
928 |
||
929 |
extern bool qDBusInitThreads(); |
|
930 |
||
931 |
QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p) |
|
932 |
: QObject(p), ref(1), mode(InvalidMode), connection(0), server(0), busService(0), |
|
933 |
watchAndTimeoutLock(QMutex::Recursive), |
|
934 |
rootNode(QString(QLatin1Char('/'))) |
|
935 |
{ |
|
936 |
static const bool threads = q_dbus_threads_init_default(); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
937 |
static const int debugging = qgetenv("QDBUS_DEBUG").toInt(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
938 |
::isDebugging = debugging; |
0 | 939 |
Q_UNUSED(threads) |
940 |
Q_UNUSED(debugging) |
|
941 |
||
942 |
#ifdef QDBUS_THREAD_DEBUG |
|
943 |
if (debugging > 1) |
|
944 |
qdbusThreadDebug = qdbusDefaultThreadDebug; |
|
945 |
#endif |
|
946 |
||
947 |
QDBusMetaTypeId::init(); |
|
948 |
||
949 |
rootNode.flags = 0; |
|
950 |
} |
|
951 |
||
952 |
QDBusConnectionPrivate::~QDBusConnectionPrivate() |
|
953 |
{ |
|
954 |
if (thread() && thread() != QThread::currentThread()) |
|
955 |
qWarning("QDBusConnection(name=\"%s\")'s last reference in not in its creation thread! " |
|
956 |
"Timer and socket errors will follow and the program will probably crash", |
|
957 |
qPrintable(name)); |
|
958 |
||
959 |
closeConnection(); |
|
960 |
rootNode.children.clear(); // free resources |
|
961 |
qDeleteAll(cachedMetaObjects); |
|
962 |
||
963 |
if (server) |
|
964 |
q_dbus_server_unref(server); |
|
965 |
if (connection) |
|
966 |
q_dbus_connection_unref(connection); |
|
967 |
||
968 |
connection = 0; |
|
969 |
server = 0; |
|
970 |
} |
|
971 |
||
972 |
void QDBusConnectionPrivate::deleteYourself() |
|
973 |
{ |
|
974 |
if (thread() && thread() != QThread::currentThread()) { |
|
975 |
// last reference dropped while not in the correct thread |
|
976 |
// ask the correct thread to delete |
|
977 |
||
978 |
// note: since we're posting an event to another thread, we |
|
979 |
// must consider deleteLater() to take effect immediately |
|
980 |
deleteLater(); |
|
981 |
} else { |
|
982 |
delete this; |
|
983 |
} |
|
984 |
} |
|
985 |
||
986 |
void QDBusConnectionPrivate::closeConnection() |
|
987 |
{ |
|
988 |
QDBusWriteLocker locker(CloseConnectionAction, this); |
|
989 |
ConnectionMode oldMode = mode; |
|
990 |
mode = InvalidMode; // prevent reentrancy |
|
991 |
baseService.clear(); |
|
992 |
||
993 |
if (oldMode == ServerMode) { |
|
994 |
if (server) { |
|
995 |
q_dbus_server_disconnect(server); |
|
996 |
} |
|
997 |
} else if (oldMode == ClientMode || oldMode == PeerMode) { |
|
998 |
if (connection) { |
|
999 |
q_dbus_connection_close(connection); |
|
1000 |
// send the "close" message |
|
1001 |
while (q_dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS) |
|
1002 |
; |
|
1003 |
} |
|
1004 |
} |
|
1005 |
} |
|
1006 |
||
1007 |
void QDBusConnectionPrivate::checkThread() |
|
1008 |
{ |
|
1009 |
if (!thread()) { |
|
1010 |
if (QCoreApplication::instance()) |
|
1011 |
moveToThread(QCoreApplication::instance()->thread()); |
|
1012 |
else |
|
1013 |
qWarning("The thread that had QDBusConnection('%s') has died and there is no main thread", |
|
1014 |
qPrintable(name)); |
|
1015 |
} |
|
1016 |
} |
|
1017 |
||
1018 |
bool QDBusConnectionPrivate::handleError(const QDBusErrorInternal &error) |
|
1019 |
{ |
|
1020 |
if (!error) |
|
1021 |
return false; // no error |
|
1022 |
||
1023 |
//lock.lockForWrite(); |
|
1024 |
lastError = error; |
|
1025 |
//lock.unlock(); |
|
1026 |
return true; |
|
1027 |
} |
|
1028 |
||
1029 |
void QDBusConnectionPrivate::timerEvent(QTimerEvent *e) |
|
1030 |
{ |
|
1031 |
{ |
|
1032 |
QDBusWatchAndTimeoutLocker locker(TimerEventAction, this); |
|
1033 |
DBusTimeout *timeout = timeouts.value(e->timerId(), 0); |
|
1034 |
if (timeout) |
|
1035 |
q_dbus_timeout_handle(timeout); |
|
1036 |
} |
|
1037 |
||
1038 |
doDispatch(); |
|
1039 |
} |
|
1040 |
||
1041 |
void QDBusConnectionPrivate::customEvent(QEvent *e) |
|
1042 |
{ |
|
1043 |
Q_ASSERT(e->type() == QEvent::User); |
|
1044 |
||
1045 |
QDBusConnectionCallbackEvent *ev = static_cast<QDBusConnectionCallbackEvent *>(e); |
|
1046 |
QDBusLockerBase::reportThreadAction(int(AddTimeoutAction) + int(ev->subtype), |
|
1047 |
QDBusLockerBase::BeforeDeliver, this); |
|
1048 |
switch (ev->subtype) |
|
1049 |
{ |
|
1050 |
case QDBusConnectionCallbackEvent::AddTimeout: { |
|
1051 |
QDBusWatchAndTimeoutLocker locker(RealAddTimeoutAction, this); |
|
1052 |
while (!timeoutsPendingAdd.isEmpty()) { |
|
1053 |
QPair<DBusTimeout *, int> entry = timeoutsPendingAdd.takeFirst(); |
|
1054 |
qDBusRealAddTimeout(this, entry.first, entry.second); |
|
1055 |
} |
|
1056 |
break; |
|
1057 |
} |
|
1058 |
||
1059 |
case QDBusConnectionCallbackEvent::KillTimer: |
|
1060 |
killTimer(ev->timerId); |
|
1061 |
break; |
|
1062 |
||
1063 |
case QDBusConnectionCallbackEvent::AddWatch: |
|
1064 |
qDBusRealAddWatch(this, ev->watch, ev->extra, ev->fd); |
|
1065 |
break; |
|
1066 |
||
1067 |
case QDBusConnectionCallbackEvent::ToggleWatch: |
|
1068 |
qDBusRealToggleWatch(this, ev->watch, ev->fd); |
|
1069 |
break; |
|
1070 |
} |
|
1071 |
QDBusLockerBase::reportThreadAction(int(AddTimeoutAction) + int(ev->subtype), |
|
1072 |
QDBusLockerBase::AfterDeliver, this); |
|
1073 |
} |
|
1074 |
||
1075 |
void QDBusConnectionPrivate::doDispatch() |
|
1076 |
{ |
|
1077 |
QDBusDispatchLocker locker(DoDispatchAction, this); |
|
1078 |
if (mode == ClientMode || mode == PeerMode) |
|
1079 |
while (q_dbus_connection_dispatch(connection) == DBUS_DISPATCH_DATA_REMAINS) ; |
|
1080 |
} |
|
1081 |
||
1082 |
void QDBusConnectionPrivate::socketRead(int fd) |
|
1083 |
{ |
|
1084 |
QVarLengthArray<DBusWatch *, 2> pendingWatches; |
|
1085 |
||
1086 |
{ |
|
1087 |
QDBusWatchAndTimeoutLocker locker(SocketReadAction, this); |
|
1088 |
WatcherHash::ConstIterator it = watchers.constFind(fd); |
|
1089 |
while (it != watchers.constEnd() && it.key() == fd) { |
|
1090 |
if (it->watch && it->read && it->read->isEnabled()) |
|
1091 |
pendingWatches.append(it.value().watch); |
|
1092 |
++it; |
|
1093 |
} |
|
1094 |
} |
|
1095 |
||
1096 |
for (int i = 0; i < pendingWatches.size(); ++i) |
|
1097 |
if (!q_dbus_watch_handle(pendingWatches[i], DBUS_WATCH_READABLE)) |
|
1098 |
qDebug("OUT OF MEM"); |
|
1099 |
doDispatch(); |
|
1100 |
} |
|
1101 |
||
1102 |
void QDBusConnectionPrivate::socketWrite(int fd) |
|
1103 |
{ |
|
1104 |
QVarLengthArray<DBusWatch *, 2> pendingWatches; |
|
1105 |
||
1106 |
{ |
|
1107 |
QDBusWatchAndTimeoutLocker locker(SocketWriteAction, this); |
|
1108 |
WatcherHash::ConstIterator it = watchers.constFind(fd); |
|
1109 |
while (it != watchers.constEnd() && it.key() == fd) { |
|
1110 |
if (it->watch && it->write && it->write->isEnabled()) |
|
1111 |
pendingWatches.append(it.value().watch); |
|
1112 |
++it; |
|
1113 |
} |
|
1114 |
} |
|
1115 |
||
1116 |
for (int i = 0; i < pendingWatches.size(); ++i) |
|
1117 |
if (!q_dbus_watch_handle(pendingWatches[i], DBUS_WATCH_WRITABLE)) |
|
1118 |
qDebug("OUT OF MEM"); |
|
1119 |
} |
|
1120 |
||
1121 |
void QDBusConnectionPrivate::objectDestroyed(QObject *obj) |
|
1122 |
{ |
|
1123 |
QDBusWriteLocker locker(ObjectDestroyedAction, this); |
|
1124 |
huntAndDestroy(obj, rootNode); |
|
1125 |
||
1126 |
SignalHookHash::iterator sit = signalHooks.begin(); |
|
1127 |
while (sit != signalHooks.end()) { |
|
1128 |
if (static_cast<QObject *>(sit.value().obj) == obj) |
|
1129 |
sit = disconnectSignal(sit); |
|
1130 |
else |
|
1131 |
++sit; |
|
1132 |
} |
|
1133 |
||
1134 |
obj->disconnect(this); |
|
1135 |
} |
|
1136 |
||
1137 |
void QDBusConnectionPrivate::relaySignal(QObject *obj, const QMetaObject *mo, int signalId, |
|
1138 |
const QVariantList &args) |
|
1139 |
{ |
|
1140 |
QString interface = qDBusInterfaceFromMetaObject(mo); |
|
1141 |
||
1142 |
QMetaMethod mm = mo->method(signalId); |
|
1143 |
QByteArray memberName = mm.signature(); |
|
1144 |
memberName.truncate(memberName.indexOf('(')); |
|
1145 |
||
1146 |
// check if it's scriptable |
|
1147 |
bool isScriptable = mm.attributes() & QMetaMethod::Scriptable; |
|
1148 |
bool isAdaptor = false; |
|
1149 |
for ( ; mo; mo = mo->superClass()) |
|
1150 |
if (mo == &QDBusAbstractAdaptor::staticMetaObject) { |
|
1151 |
isAdaptor = true; |
|
1152 |
break; |
|
1153 |
} |
|
1154 |
||
1155 |
QDBusReadLocker locker(RelaySignalAction, this); |
|
1156 |
QDBusMessage message = QDBusMessage::createSignal(QLatin1String("/"), interface, |
|
1157 |
QLatin1String(memberName)); |
|
1158 |
QDBusMessagePrivate::setParametersValidated(message, true); |
|
1159 |
message.setArguments(args); |
|
1160 |
QDBusError error; |
|
1161 |
DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, &error); |
|
1162 |
if (!msg) { |
|
1163 |
qWarning("QDBusConnection: Could not emit signal %s.%s: %s", qPrintable(interface), memberName.constData(), |
|
1164 |
qPrintable(error.message())); |
|
1165 |
lastError = error; |
|
1166 |
return; |
|
1167 |
} |
|
1168 |
||
1169 |
//qDBusDebug() << "Emitting signal" << message; |
|
1170 |
//qDBusDebug() << "for paths:"; |
|
1171 |
q_dbus_message_set_no_reply(msg, true); // the reply would not be delivered to anything |
|
1172 |
huntAndEmit(connection, msg, obj, rootNode, isScriptable, isAdaptor); |
|
1173 |
q_dbus_message_unref(msg); |
|
1174 |
} |
|
1175 |
||
1176 |
void QDBusConnectionPrivate::_q_serviceOwnerChanged(const QString &name, |
|
1177 |
const QString &oldOwner, const QString &newOwner) |
|
1178 |
{ |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1179 |
Q_UNUSED(oldOwner); |
0 | 1180 |
QDBusWriteLocker locker(UpdateSignalHookOwnerAction, this); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1181 |
WatchedServicesHash::Iterator it = watchedServices.find(name); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1182 |
if (it == watchedServices.end()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1183 |
return; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1184 |
if (oldOwner != it->owner) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1185 |
qWarning("QDBusConnection: name '%s' had owner '%s' but we thought it was '%s'", |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1186 |
qPrintable(name), qPrintable(oldOwner), qPrintable(it->owner)); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1187 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1188 |
qDBusDebug() << this << "Updating name" << name << "from" << oldOwner << "to" << newOwner; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1189 |
it->owner = newOwner; |
0 | 1190 |
} |
1191 |
||
1192 |
int QDBusConnectionPrivate::findSlot(QObject* obj, const QByteArray &normalizedName, |
|
1193 |
QList<int> ¶ms) |
|
1194 |
{ |
|
1195 |
int midx = obj->metaObject()->indexOfMethod(normalizedName); |
|
1196 |
if (midx == -1) |
|
1197 |
return -1; |
|
1198 |
||
1199 |
int inputCount = qDBusParametersForMethod(obj->metaObject()->method(midx), params); |
|
1200 |
if ( inputCount == -1 || inputCount + 1 != params.count() ) |
|
1201 |
return -1; // failed to parse or invalid arguments or output arguments |
|
1202 |
||
1203 |
return midx; |
|
1204 |
} |
|
1205 |
||
1206 |
bool QDBusConnectionPrivate::prepareHook(QDBusConnectionPrivate::SignalHook &hook, QString &key, |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1207 |
const QString &service, |
0 | 1208 |
const QString &path, const QString &interface, const QString &name, |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1209 |
const QStringList &argMatch, |
0 | 1210 |
QObject *receiver, const char *signal, int minMIdx, |
1211 |
bool buildSignature) |
|
1212 |
{ |
|
1213 |
QByteArray normalizedName = signal + 1; |
|
1214 |
hook.midx = findSlot(receiver, signal + 1, hook.params); |
|
1215 |
if (hook.midx == -1) { |
|
1216 |
normalizedName = QMetaObject::normalizedSignature(signal + 1); |
|
1217 |
hook.midx = findSlot(receiver, normalizedName, hook.params); |
|
1218 |
} |
|
1219 |
if (hook.midx < minMIdx) { |
|
1220 |
if (hook.midx == -1) |
|
1221 |
{} |
|
1222 |
return false; |
|
1223 |
} |
|
1224 |
||
1225 |
hook.service = service; |
|
1226 |
hook.path = path; |
|
1227 |
hook.obj = receiver; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1228 |
hook.argumentMatch = argMatch; |
0 | 1229 |
|
1230 |
// build the D-Bus signal name and signature |
|
1231 |
// This should not happen for QDBusConnection::connect, use buildSignature here, since |
|
1232 |
// QDBusConnection::connect passes false and everything else uses true |
|
1233 |
QString mname = name; |
|
1234 |
if (buildSignature && mname.isNull()) { |
|
1235 |
normalizedName.truncate(normalizedName.indexOf('(')); |
|
1236 |
mname = QString::fromUtf8(normalizedName); |
|
1237 |
} |
|
1238 |
key = mname; |
|
1239 |
key.reserve(interface.length() + 1 + mname.length()); |
|
1240 |
key += QLatin1Char(':'); |
|
1241 |
key += interface; |
|
1242 |
||
1243 |
if (buildSignature) { |
|
1244 |
hook.signature.clear(); |
|
1245 |
for (int i = 1; i < hook.params.count(); ++i) |
|
1246 |
if (hook.params.at(i) != QDBusMetaTypeId::message) |
|
1247 |
hook.signature += QLatin1String( QDBusMetaType::typeToSignature( hook.params.at(i) ) ); |
|
1248 |
} |
|
1249 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1250 |
hook.matchRule = buildMatchRule(service, path, interface, mname, argMatch, hook.signature); |
0 | 1251 |
return true; // connect to this signal |
1252 |
} |
|
1253 |
||
1254 |
void QDBusConnectionPrivate::sendError(const QDBusMessage &msg, QDBusError::ErrorType code) |
|
1255 |
{ |
|
1256 |
if (code == QDBusError::UnknownMethod) { |
|
1257 |
QString interfaceMsg; |
|
1258 |
if (msg.interface().isEmpty()) |
|
1259 |
interfaceMsg = QLatin1String("any interface"); |
|
1260 |
else |
|
1261 |
interfaceMsg = QString::fromLatin1("interface '%1'").arg(msg.interface()); |
|
1262 |
||
1263 |
send(msg.createErrorReply(code, |
|
1264 |
QString::fromLatin1("No such method '%1' in %2 at object path '%3' " |
|
1265 |
"(signature '%4')") |
|
1266 |
.arg(msg.member(), interfaceMsg, msg.path(), msg.signature()))); |
|
1267 |
} else if (code == QDBusError::UnknownInterface) { |
|
1268 |
send(msg.createErrorReply(QDBusError::UnknownInterface, |
|
1269 |
QString::fromLatin1("No such interface '%1' at object path '%2'") |
|
1270 |
.arg(msg.interface(), msg.path()))); |
|
1271 |
} else if (code == QDBusError::UnknownObject) { |
|
1272 |
send(msg.createErrorReply(QDBusError::UnknownObject, |
|
1273 |
QString::fromLatin1("No such object path '%1'").arg(msg.path()))); |
|
1274 |
} |
|
1275 |
} |
|
1276 |
||
1277 |
bool QDBusConnectionPrivate::activateInternalFilters(const ObjectTreeNode &node, |
|
1278 |
const QDBusMessage &msg) |
|
1279 |
{ |
|
1280 |
// object may be null |
|
1281 |
const QString interface = msg.interface(); |
|
1282 |
||
1283 |
if (interface.isEmpty() || interface == QLatin1String(DBUS_INTERFACE_INTROSPECTABLE)) { |
|
1284 |
if (msg.member() == QLatin1String("Introspect") && msg.signature().isEmpty()) { |
|
1285 |
//qDebug() << "QDBusConnectionPrivate::activateInternalFilters introspect" << msg.d_ptr->msg; |
|
1286 |
QDBusMessage reply = msg.createReply(qDBusIntrospectObject(node)); |
|
1287 |
send(reply); |
|
1288 |
return true; |
|
1289 |
} |
|
1290 |
||
1291 |
if (!interface.isEmpty()) { |
|
1292 |
sendError(msg, QDBusError::UnknownMethod); |
|
1293 |
return true; |
|
1294 |
} |
|
1295 |
} |
|
1296 |
||
1297 |
if (node.obj && (interface.isEmpty() || |
|
1298 |
interface == QLatin1String(DBUS_INTERFACE_PROPERTIES))) { |
|
1299 |
//qDebug() << "QDBusConnectionPrivate::activateInternalFilters properties" << msg.d_ptr->msg; |
|
1300 |
if (msg.member() == QLatin1String("Get") && msg.signature() == QLatin1String("ss")) { |
|
1301 |
QDBusMessage reply = qDBusPropertyGet(node, msg); |
|
1302 |
send(reply); |
|
1303 |
return true; |
|
1304 |
} else if (msg.member() == QLatin1String("Set") && msg.signature() == QLatin1String("ssv")) { |
|
1305 |
QDBusMessage reply = qDBusPropertySet(node, msg); |
|
1306 |
send(reply); |
|
1307 |
return true; |
|
1308 |
} else if (msg.member() == QLatin1String("GetAll") && msg.signature() == QLatin1String("s")) { |
|
1309 |
QDBusMessage reply = qDBusPropertyGetAll(node, msg); |
|
1310 |
send(reply); |
|
1311 |
return true; |
|
1312 |
} |
|
1313 |
||
1314 |
if (!interface.isEmpty()) { |
|
1315 |
sendError(msg, QDBusError::UnknownMethod); |
|
1316 |
return true; |
|
1317 |
} |
|
1318 |
} |
|
1319 |
||
1320 |
return false; |
|
1321 |
} |
|
1322 |
||
1323 |
void QDBusConnectionPrivate::activateObject(ObjectTreeNode &node, const QDBusMessage &msg, |
|
1324 |
int pathStartPos) |
|
1325 |
{ |
|
1326 |
// This is called by QDBusConnectionPrivate::handleObjectCall to place a call to a slot |
|
1327 |
// on the object. |
|
1328 |
// |
|
1329 |
// The call is routed through the adaptor sub-objects if we have any |
|
1330 |
||
1331 |
// object may be null |
|
1332 |
||
1333 |
if (pathStartPos != msg.path().length()) { |
|
1334 |
node.flags &= ~QDBusConnection::ExportAllSignals; |
|
1335 |
node.obj = findChildObject(&node, msg.path(), pathStartPos); |
|
1336 |
if (!node.obj) { |
|
1337 |
sendError(msg, QDBusError::UnknownObject); |
|
1338 |
return; |
|
1339 |
} |
|
1340 |
} |
|
1341 |
||
1342 |
QDBusAdaptorConnector *connector; |
|
1343 |
if (node.flags & QDBusConnection::ExportAdaptors && |
|
1344 |
(connector = qDBusFindAdaptorConnector(node.obj))) { |
|
1345 |
int newflags = node.flags | QDBusConnection::ExportAllSlots; |
|
1346 |
||
1347 |
if (msg.interface().isEmpty()) { |
|
1348 |
// place the call in all interfaces |
|
1349 |
// let the first one that handles it to work |
|
1350 |
QDBusAdaptorConnector::AdaptorMap::ConstIterator it = |
|
1351 |
connector->adaptors.constBegin(); |
|
1352 |
QDBusAdaptorConnector::AdaptorMap::ConstIterator end = |
|
1353 |
connector->adaptors.constEnd(); |
|
1354 |
||
1355 |
for ( ; it != end; ++it) |
|
1356 |
if (activateCall(it->adaptor, newflags, msg)) |
|
1357 |
return; |
|
1358 |
} else { |
|
1359 |
// check if we have an interface matching the name that was asked: |
|
1360 |
QDBusAdaptorConnector::AdaptorMap::ConstIterator it; |
|
1361 |
it = qLowerBound(connector->adaptors.constBegin(), connector->adaptors.constEnd(), |
|
1362 |
msg.interface()); |
|
1363 |
if (it != connector->adaptors.constEnd() && msg.interface() == QLatin1String(it->interface)) { |
|
1364 |
if (!activateCall(it->adaptor, newflags, msg)) |
|
1365 |
sendError(msg, QDBusError::UnknownMethod); |
|
1366 |
return; |
|
1367 |
} |
|
1368 |
} |
|
1369 |
} |
|
1370 |
||
1371 |
// no adaptors matched or were exported |
|
1372 |
// try our standard filters |
|
1373 |
if (activateInternalFilters(node, msg)) |
|
1374 |
return; // internal filters have already run or an error has been sent |
|
1375 |
||
1376 |
// try the object itself: |
|
1377 |
if (node.flags & (QDBusConnection::ExportScriptableSlots|QDBusConnection::ExportNonScriptableSlots)) { |
|
1378 |
bool interfaceFound = true; |
|
1379 |
if (!msg.interface().isEmpty()) |
|
1380 |
interfaceFound = qDBusInterfaceInObject(node.obj, msg.interface()); |
|
1381 |
||
1382 |
if (interfaceFound) { |
|
1383 |
if (!activateCall(node.obj, node.flags, msg)) |
|
1384 |
sendError(msg, QDBusError::UnknownMethod); |
|
1385 |
return; |
|
1386 |
} |
|
1387 |
} |
|
1388 |
||
1389 |
// nothing matched, send an error code |
|
1390 |
if (msg.interface().isEmpty()) |
|
1391 |
sendError(msg, QDBusError::UnknownMethod); |
|
1392 |
else |
|
1393 |
sendError(msg, QDBusError::UnknownInterface); |
|
1394 |
} |
|
1395 |
||
1396 |
void QDBusConnectionPrivate::handleObjectCall(const QDBusMessage &msg) |
|
1397 |
{ |
|
1398 |
// if the msg is external, we were called from inside doDispatch |
|
1399 |
// that means the dispatchLock mutex is locked |
|
1400 |
// must not call out to user code in that case |
|
1401 |
// |
|
1402 |
// however, if the message is internal, handleMessage was called |
|
1403 |
// directly and no lock is in place. We can therefore call out to |
|
1404 |
// user code, if necessary |
|
1405 |
ObjectTreeNode result; |
|
1406 |
int usedLength; |
|
1407 |
QThread *objThread = 0; |
|
1408 |
QSemaphore sem; |
|
1409 |
bool semWait; |
|
1410 |
||
1411 |
{ |
|
1412 |
QDBusReadLocker locker(HandleObjectCallAction, this); |
|
1413 |
if (!findObject(&rootNode, msg.path(), usedLength, result)) { |
|
1414 |
// qDebug("Call failed: no object found at %s", qPrintable(msg.path())); |
|
1415 |
sendError(msg, QDBusError::UnknownObject); |
|
1416 |
return; |
|
1417 |
} |
|
1418 |
||
1419 |
if (!result.obj) { |
|
1420 |
// no object -> no threading issues |
|
1421 |
// it's either going to be an error, or an internal filter |
|
1422 |
activateObject(result, msg, usedLength); |
|
1423 |
return; |
|
1424 |
} |
|
1425 |
||
1426 |
objThread = result.obj->thread(); |
|
1427 |
if (!objThread) { |
|
1428 |
send(msg.createErrorReply(QDBusError::InternalError, |
|
1429 |
QString::fromLatin1("Object '%1' (at path '%2')" |
|
1430 |
" has no thread. Cannot deliver message.") |
|
1431 |
.arg(result.obj->objectName(), msg.path()))); |
|
1432 |
return; |
|
1433 |
} |
|
1434 |
||
1435 |
if (!QDBusMessagePrivate::isLocal(msg)) { |
|
1436 |
// external incoming message |
|
1437 |
// post it and forget |
|
1438 |
postEventToThread(HandleObjectCallPostEventAction, result.obj, |
|
1439 |
new QDBusActivateObjectEvent(QDBusConnection(this), this, result, |
|
1440 |
usedLength, msg)); |
|
1441 |
return; |
|
1442 |
} else if (objThread != QThread::currentThread()) { |
|
1443 |
// synchronize with other thread |
|
1444 |
postEventToThread(HandleObjectCallPostEventAction, result.obj, |
|
1445 |
new QDBusActivateObjectEvent(QDBusConnection(this), this, result, |
|
1446 |
usedLength, msg, &sem)); |
|
1447 |
semWait = true; |
|
1448 |
} else { |
|
1449 |
semWait = false; |
|
1450 |
} |
|
1451 |
} // release the lock |
|
1452 |
||
1453 |
if (semWait) |
|
1454 |
SEM_ACQUIRE(HandleObjectCallSemaphoreAction, sem); |
|
1455 |
else |
|
1456 |
activateObject(result, msg, usedLength); |
|
1457 |
} |
|
1458 |
||
1459 |
QDBusActivateObjectEvent::~QDBusActivateObjectEvent() |
|
1460 |
{ |
|
1461 |
if (!handled) { |
|
1462 |
// we're being destroyed without delivering |
|
1463 |
// it means the object was deleted between posting and delivering |
|
1464 |
QDBusConnectionPrivate *that = QDBusConnectionPrivate::d(connection); |
|
1465 |
that->sendError(message, QDBusError::UnknownObject); |
|
1466 |
} |
|
1467 |
||
1468 |
// semaphore releasing happens in ~QMetaCallEvent |
|
1469 |
} |
|
1470 |
||
1471 |
int QDBusActivateObjectEvent::placeMetaCall(QObject *) |
|
1472 |
{ |
|
1473 |
QDBusConnectionPrivate *that = QDBusConnectionPrivate::d(connection); |
|
1474 |
||
1475 |
QDBusLockerBase::reportThreadAction(HandleObjectCallPostEventAction, |
|
1476 |
QDBusLockerBase::BeforeDeliver, that); |
|
1477 |
that->activateObject(node, message, pathStartPos); |
|
1478 |
QDBusLockerBase::reportThreadAction(HandleObjectCallPostEventAction, |
|
1479 |
QDBusLockerBase::AfterDeliver, that); |
|
1480 |
||
1481 |
handled = true; |
|
1482 |
return -1; |
|
1483 |
} |
|
1484 |
||
1485 |
void QDBusConnectionPrivate::handleSignal(const QString &key, const QDBusMessage& msg) |
|
1486 |
{ |
|
1487 |
SignalHookHash::const_iterator it = signalHooks.find(key); |
|
1488 |
SignalHookHash::const_iterator end = signalHooks.constEnd(); |
|
1489 |
//qDebug("looking for: %s", path.toLocal8Bit().constData()); |
|
1490 |
//qDBusDebug() << signalHooks.keys(); |
|
1491 |
for ( ; it != end && it.key() == key; ++it) { |
|
1492 |
const SignalHook &hook = it.value(); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1493 |
if (!hook.service.isEmpty()) { |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1494 |
const QString owner = |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1495 |
shouldWatchService(hook.service) ? |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1496 |
watchedServices.value(hook.service).owner : |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1497 |
hook.service; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1498 |
if (owner != msg.service()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1499 |
continue; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1500 |
} |
0 | 1501 |
if (!hook.path.isEmpty() && hook.path != msg.path()) |
1502 |
continue; |
|
1503 |
if (!hook.signature.isEmpty() && hook.signature != msg.signature()) |
|
1504 |
continue; |
|
1505 |
if (hook.signature.isEmpty() && !hook.signature.isNull() && !msg.signature().isEmpty()) |
|
1506 |
continue; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1507 |
if (!hook.argumentMatch.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1508 |
const QVariantList arguments = msg.arguments(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1509 |
if (hook.argumentMatch.size() > arguments.size()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1510 |
continue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1511 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1512 |
bool matched = true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1513 |
for (int i = 0; i < hook.argumentMatch.size(); ++i) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1514 |
const QString ¶m = hook.argumentMatch.at(i); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1515 |
if (param.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1516 |
continue; // don't try to match against this |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1517 |
if (param == arguments.at(i).toString()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1518 |
continue; // matched |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1519 |
matched = false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1520 |
break; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1521 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1522 |
if (!matched) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1523 |
continue; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1524 |
} |
0 | 1525 |
|
1526 |
activateSignal(hook, msg); |
|
1527 |
} |
|
1528 |
} |
|
1529 |
||
1530 |
void QDBusConnectionPrivate::handleSignal(const QDBusMessage& msg) |
|
1531 |
{ |
|
1532 |
// We call handlesignal(QString, QDBusMessage) three times: |
|
1533 |
// one with member:interface |
|
1534 |
// one with member: |
|
1535 |
// one with :interface |
|
1536 |
// This allows us to match signals with wildcards on member or interface |
|
1537 |
// (but not both) |
|
1538 |
||
1539 |
QString key = msg.member(); |
|
1540 |
key.reserve(key.length() + 1 + msg.interface().length()); |
|
1541 |
key += QLatin1Char(':'); |
|
1542 |
key += msg.interface(); |
|
1543 |
||
1544 |
QDBusReadLocker locker(HandleSignalAction, this); |
|
1545 |
handleSignal(key, msg); // one try |
|
1546 |
||
1547 |
key.truncate(msg.member().length() + 1); // keep the ':' |
|
1548 |
handleSignal(key, msg); // second try |
|
1549 |
||
1550 |
key = QLatin1Char(':'); |
|
1551 |
key += msg.interface(); |
|
1552 |
handleSignal(key, msg); // third try |
|
1553 |
} |
|
1554 |
||
1555 |
static dbus_int32_t server_slot = -1; |
|
1556 |
||
1557 |
void QDBusConnectionPrivate::setServer(DBusServer *s, const QDBusErrorInternal &error) |
|
1558 |
{ |
|
1559 |
if (!s) { |
|
1560 |
handleError(error); |
|
1561 |
return; |
|
1562 |
} |
|
1563 |
||
1564 |
server = s; |
|
1565 |
mode = ServerMode; |
|
1566 |
||
1567 |
dbus_bool_t data_allocated = q_dbus_server_allocate_data_slot(&server_slot); |
|
1568 |
if (data_allocated && server_slot < 0) |
|
1569 |
return; |
|
1570 |
||
1571 |
dbus_bool_t watch_functions_set = q_dbus_server_set_watch_functions(server, |
|
1572 |
qDBusAddWatch, |
|
1573 |
qDBusRemoveWatch, |
|
1574 |
qDBusToggleWatch, |
|
1575 |
this, 0); |
|
1576 |
//qDebug() << "watch_functions_set" << watch_functions_set; |
|
1577 |
Q_UNUSED(watch_functions_set); |
|
1578 |
||
1579 |
dbus_bool_t time_functions_set = q_dbus_server_set_timeout_functions(server, |
|
1580 |
qDBusAddTimeout, |
|
1581 |
qDBusRemoveTimeout, |
|
1582 |
qDBusToggleTimeout, |
|
1583 |
this, 0); |
|
1584 |
//qDebug() << "time_functions_set" << time_functions_set; |
|
1585 |
Q_UNUSED(time_functions_set); |
|
1586 |
||
1587 |
q_dbus_server_set_new_connection_function(server, qDBusNewConnection, this, 0); |
|
1588 |
||
1589 |
dbus_bool_t data_set = q_dbus_server_set_data(server, server_slot, this, 0); |
|
1590 |
//qDebug() << "data_set" << data_set; |
|
1591 |
Q_UNUSED(data_set); |
|
1592 |
} |
|
1593 |
||
1594 |
void QDBusConnectionPrivate::setPeer(DBusConnection *c, const QDBusErrorInternal &error) |
|
1595 |
{ |
|
1596 |
if (!c) { |
|
1597 |
handleError(error); |
|
1598 |
return; |
|
1599 |
} |
|
1600 |
||
1601 |
connection = c; |
|
1602 |
mode = PeerMode; |
|
1603 |
||
1604 |
q_dbus_connection_set_exit_on_disconnect(connection, false); |
|
1605 |
q_dbus_connection_set_watch_functions(connection, |
|
1606 |
qDBusAddWatch, |
|
1607 |
qDBusRemoveWatch, |
|
1608 |
qDBusToggleWatch, |
|
1609 |
this, 0); |
|
1610 |
q_dbus_connection_set_timeout_functions(connection, |
|
1611 |
qDBusAddTimeout, |
|
1612 |
qDBusRemoveTimeout, |
|
1613 |
qDBusToggleTimeout, |
|
1614 |
this, 0); |
|
1615 |
q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0); |
|
1616 |
q_dbus_connection_add_filter(connection, |
|
1617 |
qDBusSignalFilter, |
|
1618 |
this, 0); |
|
1619 |
||
1620 |
QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection); |
|
1621 |
} |
|
1622 |
||
1623 |
void QDBusConnectionPrivate::setConnection(DBusConnection *dbc, const QDBusErrorInternal &error) |
|
1624 |
{ |
|
1625 |
if (!dbc) { |
|
1626 |
handleError(error); |
|
1627 |
return; |
|
1628 |
} |
|
1629 |
||
1630 |
connection = dbc; |
|
1631 |
mode = ClientMode; |
|
1632 |
||
1633 |
q_dbus_connection_set_exit_on_disconnect(connection, false); |
|
1634 |
q_dbus_connection_set_watch_functions(connection, qDBusAddWatch, qDBusRemoveWatch, |
|
1635 |
qDBusToggleWatch, this, 0); |
|
1636 |
q_dbus_connection_set_timeout_functions(connection, qDBusAddTimeout, qDBusRemoveTimeout, |
|
1637 |
qDBusToggleTimeout, this, 0); |
|
1638 |
q_dbus_connection_set_dispatch_status_function(connection, qDBusUpdateDispatchStatus, this, 0); |
|
1639 |
||
1640 |
// Initialize the match rules |
|
1641 |
// We want all messages that have us as destination |
|
1642 |
// signals don't have destinations, but connectSignal() takes care of them |
|
1643 |
const char *service = q_dbus_bus_get_unique_name(connection); |
|
1644 |
if (service) { |
|
1645 |
QVarLengthArray<char, 56> filter; |
|
1646 |
filter.append("destination='", 13); |
|
1647 |
filter.append(service, qstrlen(service)); |
|
1648 |
filter.append("\'\0", 2); |
|
1649 |
||
1650 |
QDBusErrorInternal error; |
|
1651 |
q_dbus_bus_add_match(connection, filter.constData(), error); |
|
1652 |
if (handleError(error)) { |
|
1653 |
closeConnection(); |
|
1654 |
return; |
|
1655 |
} |
|
1656 |
||
1657 |
baseService = QString::fromUtf8(service); |
|
1658 |
} else { |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1659 |
qWarning("QDBusConnectionPrivate::setConnection: Unable to get base service"); |
0 | 1660 |
} |
1661 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1662 |
QString busService = QLatin1String(DBUS_SERVICE_DBUS); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1663 |
connectSignal(busService, QString(), QString(), QLatin1String("NameAcquired"), QStringList(), QString(), |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1664 |
this, SLOT(registerService(QString))); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1665 |
connectSignal(busService, QString(), QString(), QLatin1String("NameLost"), QStringList(), QString(), |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1666 |
this, SLOT(unregisterService(QString))); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1667 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1668 |
|
0 | 1669 |
q_dbus_connection_add_filter(connection, qDBusSignalFilter, this, 0); |
1670 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1671 |
qDBusDebug() << this << ": connected successfully"; |
0 | 1672 |
|
1673 |
// schedule a dispatch: |
|
1674 |
QMetaObject::invokeMethod(this, "doDispatch", Qt::QueuedConnection); |
|
1675 |
} |
|
1676 |
||
1677 |
extern "C"{ |
|
1678 |
static void qDBusResultReceived(DBusPendingCall *pending, void *user_data) |
|
1679 |
{ |
|
1680 |
QDBusPendingCallPrivate *call = reinterpret_cast<QDBusPendingCallPrivate *>(user_data); |
|
1681 |
Q_ASSERT(call->pending == pending); |
|
1682 |
Q_UNUSED(pending); |
|
1683 |
QDBusConnectionPrivate::processFinishedCall(call); |
|
1684 |
} |
|
1685 |
} |
|
1686 |
||
1687 |
void QDBusConnectionPrivate::waitForFinished(QDBusPendingCallPrivate *pcall) |
|
1688 |
{ |
|
1689 |
Q_ASSERT(pcall->pending); |
|
1690 |
QDBusDispatchLocker locker(PendingCallBlockAction, this); |
|
1691 |
q_dbus_pending_call_block(pcall->pending); |
|
1692 |
// QDBusConnectionPrivate::processFinishedCall() is called automatically |
|
1693 |
} |
|
1694 |
||
1695 |
void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call) |
|
1696 |
{ |
|
1697 |
QDBusConnectionPrivate *connection = const_cast<QDBusConnectionPrivate *>(call->connection); |
|
1698 |
||
1699 |
QDBusMessage &msg = call->replyMessage; |
|
1700 |
if (call->pending) { |
|
1701 |
// decode the message |
|
1702 |
DBusMessage *reply = q_dbus_pending_call_steal_reply(call->pending); |
|
1703 |
msg = QDBusMessagePrivate::fromDBusMessage(reply); |
|
1704 |
q_dbus_message_unref(reply); |
|
1705 |
} |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1706 |
qDBusDebug() << connection << "got message reply (async):" << msg; |
0 | 1707 |
|
1708 |
// Check if the reply has the expected signature |
|
1709 |
call->checkReceivedSignature(); |
|
1710 |
||
1711 |
if (!call->receiver.isNull() && call->methodIdx != -1 && msg.type() == QDBusMessage::ReplyMessage) { |
|
1712 |
// Deliver the return values of a remote function call. |
|
1713 |
// |
|
1714 |
// There is only one connection and it is specified by idx |
|
1715 |
// The slot must have the same parameter types that the message does |
|
1716 |
// The slot may have less parameters than the message |
|
1717 |
// The slot may optionally have one final parameter that is QDBusMessage |
|
1718 |
// The slot receives read-only copies of the message (i.e., pass by value or by const-ref) |
|
1719 |
||
1720 |
QDBusCallDeliveryEvent *e = prepareReply(connection, call->receiver, call->methodIdx, |
|
1721 |
call->metaTypes, msg); |
|
1722 |
if (e) |
|
1723 |
connection->postEventToThread(MessageResultReceivedAction, call->receiver, e); |
|
1724 |
else |
|
1725 |
qDBusDebug() << "Deliver failed!"; |
|
1726 |
} |
|
1727 |
||
1728 |
// Are there any watchers? |
|
1729 |
if (call->watcherHelper) |
|
1730 |
call->watcherHelper->emitSignals(msg, call->sentMessage); |
|
1731 |
||
1732 |
if (msg.type() == QDBusMessage::ErrorMessage) |
|
1733 |
emit connection->callWithCallbackFailed(QDBusError(msg), call->sentMessage); |
|
1734 |
||
1735 |
if (call->pending) |
|
1736 |
q_dbus_pending_call_unref(call->pending); |
|
1737 |
call->pending = 0; |
|
1738 |
||
1739 |
if (call->autoDelete) |
|
1740 |
delete call; |
|
1741 |
} |
|
1742 |
||
1743 |
int QDBusConnectionPrivate::send(const QDBusMessage& message) |
|
1744 |
{ |
|
1745 |
if (QDBusMessagePrivate::isLocal(message)) |
|
1746 |
return -1; // don't send; the reply will be retrieved by the caller |
|
1747 |
// through the d_ptr->localReply link |
|
1748 |
||
1749 |
QDBusError error; |
|
1750 |
DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, &error); |
|
1751 |
if (!msg) { |
|
1752 |
if (message.type() == QDBusMessage::MethodCallMessage) |
|
1753 |
qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s", |
|
1754 |
qPrintable(message.service()), qPrintable(message.path()), |
|
1755 |
qPrintable(message.interface()), qPrintable(message.member()), |
|
1756 |
qPrintable(error.message())); |
|
1757 |
else if (message.type() == QDBusMessage::SignalMessage) |
|
1758 |
qWarning("QDBusConnection: error: could not send signal path \"%s\" interface \"%s\" member \"%s\": %s", |
|
1759 |
qPrintable(message.path()), qPrintable(message.interface()), |
|
1760 |
qPrintable(message.member()), |
|
1761 |
qPrintable(error.message())); |
|
1762 |
else |
|
1763 |
qWarning("QDBusConnection: error: could not send %s message to service \"%s\": %s", |
|
1764 |
message.type() == QDBusMessage::ReplyMessage ? "reply" : |
|
1765 |
message.type() == QDBusMessage::ErrorMessage ? "error" : |
|
1766 |
"invalid", qPrintable(message.service()), |
|
1767 |
qPrintable(error.message())); |
|
1768 |
lastError = error; |
|
1769 |
return 0; |
|
1770 |
} |
|
1771 |
||
1772 |
q_dbus_message_set_no_reply(msg, true); // the reply would not be delivered to anything |
|
1773 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1774 |
qDBusDebug() << this << "sending message (no reply):" << message; |
0 | 1775 |
checkThread(); |
1776 |
bool isOk = q_dbus_connection_send(connection, msg, 0); |
|
1777 |
int serial = 0; |
|
1778 |
if (isOk) |
|
1779 |
serial = q_dbus_message_get_serial(msg); |
|
1780 |
||
1781 |
q_dbus_message_unref(msg); |
|
1782 |
return serial; |
|
1783 |
} |
|
1784 |
||
1785 |
QDBusMessage QDBusConnectionPrivate::sendWithReply(const QDBusMessage &message, |
|
1786 |
int sendMode, int timeout) |
|
1787 |
{ |
|
1788 |
checkThread(); |
|
1789 |
if ((sendMode == QDBus::BlockWithGui || sendMode == QDBus::Block) |
|
1790 |
&& isServiceRegisteredByThread(message.service())) |
|
1791 |
// special case for synchronous local calls |
|
1792 |
return sendWithReplyLocal(message); |
|
1793 |
||
1794 |
if (!QCoreApplication::instance() || sendMode == QDBus::Block) { |
|
1795 |
QDBusError err; |
|
1796 |
DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, &err); |
|
1797 |
if (!msg) { |
|
1798 |
qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s", |
|
1799 |
qPrintable(message.service()), qPrintable(message.path()), |
|
1800 |
qPrintable(message.interface()), qPrintable(message.member()), |
|
1801 |
qPrintable(err.message())); |
|
1802 |
lastError = err; |
|
1803 |
return QDBusMessage::createError(err); |
|
1804 |
} |
|
1805 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1806 |
qDBusDebug() << this << "sending message (blocking):" << message; |
0 | 1807 |
QDBusErrorInternal error; |
1808 |
DBusMessage *reply = q_dbus_connection_send_with_reply_and_block(connection, msg, timeout, error); |
|
1809 |
||
1810 |
q_dbus_message_unref(msg); |
|
1811 |
||
1812 |
if (!!error) { |
|
1813 |
lastError = err = error; |
|
1814 |
return QDBusMessage::createError(err); |
|
1815 |
} |
|
1816 |
||
1817 |
QDBusMessage amsg = QDBusMessagePrivate::fromDBusMessage(reply); |
|
1818 |
q_dbus_message_unref(reply); |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1819 |
qDBusDebug() << this << "got message reply (blocking):" << amsg; |
0 | 1820 |
|
1821 |
return amsg; |
|
1822 |
} else { // use the event loop |
|
1823 |
QDBusPendingCallPrivate *pcall = sendWithReplyAsync(message, timeout); |
|
1824 |
Q_ASSERT(pcall); |
|
1825 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1826 |
if (pcall->replyMessage.type() == QDBusMessage::InvalidMessage) { |
0 | 1827 |
pcall->watcherHelper = new QDBusPendingCallWatcherHelper; |
1828 |
QEventLoop loop; |
|
1829 |
loop.connect(pcall->watcherHelper, SIGNAL(reply(QDBusMessage)), SLOT(quit())); |
|
1830 |
loop.connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), SLOT(quit())); |
|
1831 |
||
1832 |
// enter the event loop and wait for a reply |
|
1833 |
loop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents); |
|
1834 |
} |
|
1835 |
||
1836 |
QDBusMessage reply = pcall->replyMessage; |
|
1837 |
lastError = reply; // set or clear error |
|
1838 |
||
1839 |
delete pcall; |
|
1840 |
return reply; |
|
1841 |
} |
|
1842 |
} |
|
1843 |
||
1844 |
QDBusMessage QDBusConnectionPrivate::sendWithReplyLocal(const QDBusMessage &message) |
|
1845 |
{ |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1846 |
qDBusDebug() << this << "sending message via local-loop:" << message; |
0 | 1847 |
|
1848 |
QDBusMessage localCallMsg = QDBusMessagePrivate::makeLocal(*this, message); |
|
1849 |
bool handled = handleMessage(localCallMsg); |
|
1850 |
||
1851 |
if (!handled) { |
|
1852 |
QString interface = message.interface(); |
|
1853 |
if (interface.isEmpty()) |
|
1854 |
interface = QLatin1String("<no-interface>"); |
|
1855 |
return QDBusMessage::createError(QDBusError::InternalError, |
|
1856 |
QString::fromLatin1("Internal error trying to call %1.%2 at %3 (signature '%4'") |
|
1857 |
.arg(interface, message.member(), |
|
1858 |
message.path(), message.signature())); |
|
1859 |
} |
|
1860 |
||
1861 |
// if the message was handled, there might be a reply |
|
1862 |
QDBusMessage localReplyMsg = QDBusMessagePrivate::makeLocalReply(*this, localCallMsg); |
|
1863 |
if (localReplyMsg.type() == QDBusMessage::InvalidMessage) { |
|
1864 |
qWarning("QDBusConnection: cannot call local method '%s' at object %s (with signature '%s') " |
|
1865 |
"on blocking mode", qPrintable(message.member()), qPrintable(message.path()), |
|
1866 |
qPrintable(message.signature())); |
|
1867 |
return QDBusMessage::createError( |
|
1868 |
QDBusError(QDBusError::InternalError, |
|
1869 |
QLatin1String("local-loop message cannot have delayed replies"))); |
|
1870 |
} |
|
1871 |
||
1872 |
// there is a reply |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1873 |
qDBusDebug() << this << "got message via local-loop:" << localReplyMsg; |
0 | 1874 |
return localReplyMsg; |
1875 |
} |
|
1876 |
||
1877 |
QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusMessage &message, |
|
1878 |
int timeout) |
|
1879 |
{ |
|
1880 |
if (isServiceRegisteredByThread(message.service())) { |
|
1881 |
// special case for local calls |
|
1882 |
QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate; |
|
1883 |
pcall->sentMessage = message; |
|
1884 |
pcall->replyMessage = sendWithReplyLocal(message); |
|
1885 |
pcall->connection = this; |
|
1886 |
||
1887 |
return pcall; |
|
1888 |
} |
|
1889 |
||
1890 |
checkThread(); |
|
1891 |
QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate; |
|
1892 |
pcall->sentMessage = message; |
|
1893 |
pcall->ref = 0; |
|
1894 |
||
1895 |
QDBusError error; |
|
1896 |
DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, &error); |
|
1897 |
if (!msg) { |
|
1898 |
qWarning("QDBusConnection: error: could not send message to service \"%s\" path \"%s\" interface \"%s\" member \"%s\": %s", |
|
1899 |
qPrintable(message.service()), qPrintable(message.path()), |
|
1900 |
qPrintable(message.interface()), qPrintable(message.member()), |
|
1901 |
qPrintable(error.message())); |
|
1902 |
pcall->replyMessage = QDBusMessage::createError(error); |
|
1903 |
lastError = error; |
|
1904 |
return pcall; |
|
1905 |
} |
|
1906 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1907 |
qDBusDebug() << this << "sending message (async):" << message; |
0 | 1908 |
DBusPendingCall *pending = 0; |
1909 |
||
1910 |
QDBusDispatchLocker locker(SendWithReplyAsyncAction, this); |
|
1911 |
if (q_dbus_connection_send_with_reply(connection, msg, &pending, timeout)) { |
|
1912 |
if (pending) { |
|
1913 |
q_dbus_message_unref(msg); |
|
1914 |
||
1915 |
pcall->pending = pending; |
|
1916 |
pcall->connection = this; |
|
1917 |
q_dbus_pending_call_set_notify(pending, qDBusResultReceived, pcall, 0); |
|
1918 |
||
1919 |
return pcall; |
|
1920 |
} else { |
|
1921 |
// we're probably disconnected at this point |
|
1922 |
lastError = error = QDBusError(QDBusError::Disconnected, QLatin1String("Not connected to server")); |
|
1923 |
} |
|
1924 |
} else { |
|
1925 |
lastError = error = QDBusError(QDBusError::NoMemory, QLatin1String("Out of memory")); |
|
1926 |
} |
|
1927 |
||
1928 |
q_dbus_message_unref(msg); |
|
1929 |
pcall->replyMessage = QDBusMessage::createError(error); |
|
1930 |
return pcall; |
|
1931 |
} |
|
1932 |
||
1933 |
int QDBusConnectionPrivate::sendWithReplyAsync(const QDBusMessage &message, QObject *receiver, |
|
1934 |
const char *returnMethod, const char *errorMethod, |
|
1935 |
int timeout) |
|
1936 |
{ |
|
1937 |
QDBusPendingCallPrivate *pcall = sendWithReplyAsync(message, timeout); |
|
1938 |
Q_ASSERT(pcall); |
|
1939 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1940 |
// has it already finished with success (dispatched locally)? |
0 | 1941 |
if (pcall->replyMessage.type() == QDBusMessage::ReplyMessage) { |
1942 |
pcall->setReplyCallback(receiver, returnMethod); |
|
1943 |
processFinishedCall(pcall); |
|
1944 |
delete pcall; |
|
1945 |
return 1; |
|
1946 |
} |
|
1947 |
||
7
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1948 |
// either it hasn't finished or it has finished with error |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1949 |
if (errorMethod) { |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1950 |
pcall->watcherHelper = new QDBusPendingCallWatcherHelper; |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1951 |
connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), receiver, errorMethod, |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1952 |
Qt::QueuedConnection); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1953 |
pcall->watcherHelper->moveToThread(thread()); |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1954 |
} |
3f74d0d4af4c
qt:70947f0f93d948bc89b3b43d00da758a51f1ef84
Eckhart Koeppen <eckhart.koppen@nokia.com>
parents:
5
diff
changeset
|
1955 |
|
0 | 1956 |
// has it already finished and is an error reply message? |
1957 |
if (pcall->replyMessage.type() == QDBusMessage::ErrorMessage) { |
|
1958 |
processFinishedCall(pcall); |
|
1959 |
delete pcall; |
|
1960 |
return 1; |
|
1961 |
} |
|
1962 |
||
1963 |
pcall->autoDelete = true; |
|
1964 |
pcall->ref.ref(); |
|
1965 |
pcall->setReplyCallback(receiver, returnMethod); |
|
1966 |
||
1967 |
return 1; |
|
1968 |
} |
|
1969 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1970 |
bool QDBusConnectionPrivate::connectSignal(const QString &service, |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1971 |
const QString &path, const QString &interface, const QString &name, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1972 |
const QStringList &argumentMatch, const QString &signature, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1973 |
QObject *receiver, const char *slot) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1974 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1975 |
// check the slot |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1976 |
QDBusConnectionPrivate::SignalHook hook; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1977 |
QString key; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1978 |
QString name2 = name; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1979 |
if (name2.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1980 |
name2.detach(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1981 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1982 |
hook.signature = signature; |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
1983 |
if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false)) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1984 |
return false; // don't connect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1985 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1986 |
// avoid duplicating: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1987 |
QDBusConnectionPrivate::SignalHookHash::ConstIterator it = signalHooks.find(key); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1988 |
QDBusConnectionPrivate::SignalHookHash::ConstIterator end = signalHooks.constEnd(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1989 |
for ( ; it != end && it.key() == key; ++it) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1990 |
const QDBusConnectionPrivate::SignalHook &entry = it.value(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1991 |
if (entry.service == hook.service && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1992 |
entry.path == hook.path && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1993 |
entry.signature == hook.signature && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1994 |
entry.obj == hook.obj && |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1995 |
entry.midx == hook.midx && |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
1996 |
entry.argumentMatch == hook.argumentMatch) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1997 |
// no need to compare the parameters if it's the same slot |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1998 |
return true; // already there |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
1999 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2000 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2001 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2002 |
connectSignal(key, hook); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2003 |
return true; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2004 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2005 |
|
0 | 2006 |
void QDBusConnectionPrivate::connectSignal(const QString &key, const SignalHook &hook) |
2007 |
{ |
|
2008 |
signalHooks.insertMulti(key, hook); |
|
2009 |
connect(hook.obj, SIGNAL(destroyed(QObject*)), SLOT(objectDestroyed(QObject*)), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2010 |
Qt::ConnectionType(Qt::DirectConnection | Qt::UniqueConnection)); |
0 | 2011 |
|
2012 |
MatchRefCountHash::iterator it = matchRefCounts.find(hook.matchRule); |
|
2013 |
||
2014 |
if (it != matchRefCounts.end()) { // Match already present |
|
2015 |
it.value() = it.value() + 1; |
|
2016 |
return; |
|
2017 |
} |
|
2018 |
||
2019 |
matchRefCounts.insert(hook.matchRule, 1); |
|
2020 |
||
2021 |
if (connection) { |
|
2022 |
qDBusDebug("Adding rule: %s", hook.matchRule.constData()); |
|
2023 |
QDBusErrorInternal error; |
|
2024 |
q_dbus_bus_add_match(connection, hook.matchRule, error); |
|
2025 |
if (!!error) { |
|
2026 |
QDBusError qerror = error; |
|
2027 |
qWarning("QDBusConnectionPrivate::connectSignal: received error from D-Bus server " |
|
2028 |
"while connecting signal to %s::%s: %s (%s)", |
|
2029 |
hook.obj->metaObject()->className(), |
|
2030 |
hook.obj->metaObject()->method(hook.midx).signature(), |
|
2031 |
qPrintable(qerror.name()), qPrintable(qerror.message())); |
|
2032 |
Q_ASSERT(false); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2033 |
} else { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2034 |
// Successfully connected the signal |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2035 |
// Do we need to watch for this name? |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2036 |
if (shouldWatchService(hook.service)) { |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2037 |
WatchedServicesHash::mapped_type &data = watchedServices[hook.service]; |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2038 |
if (++data.refcount == 1) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2039 |
// we need to watch for this service changing |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2040 |
QString dbusServerService = QLatin1String(DBUS_SERVICE_DBUS); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2041 |
connectSignal(dbusServerService, QString(), QLatin1String(DBUS_INTERFACE_DBUS), |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2042 |
QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2043 |
this, SLOT(_q_serviceOwnerChanged(QString,QString,QString))); |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2044 |
data.owner = getNameOwnerNoCache(hook.service); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2045 |
qDBusDebug() << this << "Watching service" << hook.service << "for owner changes (current owner:" |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2046 |
<< data.owner << ")"; |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2047 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2048 |
} |
0 | 2049 |
} |
2050 |
} |
|
2051 |
} |
|
2052 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2053 |
bool QDBusConnectionPrivate::disconnectSignal(const QString &service, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2054 |
const QString &path, const QString &interface, const QString &name, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2055 |
const QStringList &argumentMatch, const QString &signature, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2056 |
QObject *receiver, const char *slot) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2057 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2058 |
// check the slot |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2059 |
QDBusConnectionPrivate::SignalHook hook; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2060 |
QString key; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2061 |
QString name2 = name; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2062 |
if (name2.isNull()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2063 |
name2.detach(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2064 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2065 |
hook.signature = signature; |
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2066 |
if (!prepareHook(hook, key, service, path, interface, name, argumentMatch, receiver, slot, 0, false)) |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2067 |
return false; // don't disconnect |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2068 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2069 |
// avoid duplicating: |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2070 |
QDBusConnectionPrivate::SignalHookHash::Iterator it = signalHooks.find(key); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2071 |
QDBusConnectionPrivate::SignalHookHash::Iterator end = signalHooks.end(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2072 |
for ( ; it != end && it.key() == key; ++it) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2073 |
const QDBusConnectionPrivate::SignalHook &entry = it.value(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2074 |
if (entry.service == hook.service && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2075 |
entry.path == hook.path && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2076 |
entry.signature == hook.signature && |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2077 |
entry.obj == hook.obj && |
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2078 |
entry.midx == hook.midx && |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2079 |
entry.argumentMatch == hook.argumentMatch) { |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2080 |
// no need to compare the parameters if it's the same slot |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2081 |
disconnectSignal(it); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2082 |
return true; // it was there |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2083 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2084 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2085 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2086 |
// the slot was not found |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2087 |
return false; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2088 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
2089 |
|
0 | 2090 |
QDBusConnectionPrivate::SignalHookHash::Iterator |
2091 |
QDBusConnectionPrivate::disconnectSignal(SignalHookHash::Iterator &it) |
|
2092 |
{ |
|
2093 |
const SignalHook &hook = it.value(); |
|
2094 |
||
2095 |
bool erase = false; |
|
2096 |
MatchRefCountHash::iterator i = matchRefCounts.find(hook.matchRule); |
|
2097 |
if (i == matchRefCounts.end()) { |
|
2098 |
qWarning("QDBusConnectionPrivate::disconnectSignal: MatchRule not found in matchRefCounts!!"); |
|
2099 |
} else { |
|
2100 |
if (i.value() == 1) { |
|
2101 |
erase = true; |
|
2102 |
matchRefCounts.erase(i); |
|
2103 |
} |
|
2104 |
else { |
|
2105 |
i.value() = i.value() - 1; |
|
2106 |
} |
|
2107 |
} |
|
2108 |
||
2109 |
// we don't care about errors here |
|
2110 |
if (connection && erase) { |
|
2111 |
qDBusDebug("Removing rule: %s", hook.matchRule.constData()); |
|
2112 |
q_dbus_bus_remove_match(connection, hook.matchRule, NULL); |
|
5
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2113 |
|
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2114 |
// Successfully disconnected the signal |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2115 |
// Were we watching for this name? |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2116 |
WatchedServicesHash::Iterator sit = watchedServices.find(hook.service); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2117 |
if (sit != watchedServices.end()) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2118 |
if (--sit.value().refcount == 0) { |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2119 |
watchedServices.erase(sit); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2120 |
QString dbusServerService = QLatin1String(DBUS_SERVICE_DBUS); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2121 |
disconnectSignal(dbusServerService, QString(), QLatin1String(DBUS_INTERFACE_DBUS), |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2122 |
QLatin1String("NameOwnerChanged"), QStringList() << hook.service, QString(), |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2123 |
this, SLOT(_q_serviceOwnerChanged(QString,QString,QString))); |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2124 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2125 |
} |
d3bac044e0f0
Revision: 201007
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
4
diff
changeset
|
2126 |
|
0 | 2127 |
} |
2128 |
||
2129 |
return signalHooks.erase(it); |
|
2130 |
} |
|
2131 |
||
2132 |
void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node) |
|
2133 |
{ |
|
2134 |
connect(node->obj, SIGNAL(destroyed(QObject*)), SLOT(objectDestroyed(QObject*)), |
|
2135 |
Qt::DirectConnection); |
|
2136 |
||
2137 |
if (node->flags & (QDBusConnection::ExportAdaptors |
|
2138 |
| QDBusConnection::ExportScriptableSignals |
|
2139 |
| QDBusConnection::ExportNonScriptableSignals)) { |
|
2140 |
QDBusAdaptorConnector *connector = qDBusCreateAdaptorConnector(node->obj); |
|
2141 |
||
2142 |
if (node->flags & (QDBusConnection::ExportScriptableSignals |
|
2143 |
| QDBusConnection::ExportNonScriptableSignals)) { |
|
2144 |
connector->disconnectAllSignals(node->obj); |
|
2145 |
connector->connectAllSignals(node->obj); |
|
2146 |
} |
|
2147 |
||
2148 |
// disconnect and reconnect to avoid duplicates |
|
2149 |
connector->disconnect(SIGNAL(relaySignal(QObject*,const QMetaObject*,int,QVariantList)), |
|
2150 |
this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList))); |
|
2151 |
connect(connector, SIGNAL(relaySignal(QObject*,const QMetaObject*,int,QVariantList)), |
|
2152 |
this, SLOT(relaySignal(QObject*,const QMetaObject*,int,QVariantList)), |
|
2153 |
Qt::DirectConnection); |
|
2154 |
} |
|
2155 |
} |
|
2156 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2157 |
void QDBusConnectionPrivate::connectRelay(const QString &service, |
0 | 2158 |
const QString &path, const QString &interface, |
2159 |
QDBusAbstractInterface *receiver, |
|
2160 |
const char *signal) |
|
2161 |
{ |
|
2162 |
// this function is called by QDBusAbstractInterface when one of its signals is connected |
|
2163 |
// we set up a relay from D-Bus into it |
|
2164 |
SignalHook hook; |
|
2165 |
QString key; |
|
2166 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2167 |
if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, signal, |
0 | 2168 |
QDBusAbstractInterface::staticMetaObject.methodCount(), true)) |
2169 |
return; // don't connect |
|
2170 |
||
2171 |
// add it to our list: |
|
2172 |
QDBusWriteLocker locker(ConnectRelayAction, this); |
|
2173 |
SignalHookHash::ConstIterator it = signalHooks.find(key); |
|
2174 |
SignalHookHash::ConstIterator end = signalHooks.constEnd(); |
|
2175 |
for ( ; it != end && it.key() == key; ++it) { |
|
2176 |
const SignalHook &entry = it.value(); |
|
2177 |
if (entry.service == hook.service && |
|
2178 |
entry.path == hook.path && |
|
2179 |
entry.signature == hook.signature && |
|
2180 |
entry.obj == hook.obj && |
|
2181 |
entry.midx == hook.midx) |
|
2182 |
return; // already there, no need to re-add |
|
2183 |
} |
|
2184 |
||
2185 |
connectSignal(key, hook); |
|
2186 |
} |
|
2187 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2188 |
void QDBusConnectionPrivate::disconnectRelay(const QString &service, |
0 | 2189 |
const QString &path, const QString &interface, |
2190 |
QDBusAbstractInterface *receiver, |
|
2191 |
const char *signal) |
|
2192 |
{ |
|
2193 |
// this function is called by QDBusAbstractInterface when one of its signals is disconnected |
|
2194 |
// we remove relay from D-Bus into it |
|
2195 |
SignalHook hook; |
|
2196 |
QString key; |
|
2197 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2198 |
if (!prepareHook(hook, key, service, path, interface, QString(), QStringList(), receiver, signal, |
0 | 2199 |
QDBusAbstractInterface::staticMetaObject.methodCount(), true)) |
2200 |
return; // don't connect |
|
2201 |
||
2202 |
// remove it from our list: |
|
2203 |
QDBusWriteLocker locker(DisconnectRelayAction, this); |
|
2204 |
SignalHookHash::Iterator it = signalHooks.find(key); |
|
2205 |
SignalHookHash::Iterator end = signalHooks.end(); |
|
2206 |
for ( ; it != end && it.key() == key; ++it) { |
|
2207 |
const SignalHook &entry = it.value(); |
|
2208 |
if (entry.service == hook.service && |
|
2209 |
entry.path == hook.path && |
|
2210 |
entry.signature == hook.signature && |
|
2211 |
entry.obj == hook.obj && |
|
2212 |
entry.midx == hook.midx) { |
|
2213 |
// found it |
|
2214 |
disconnectSignal(it); |
|
2215 |
return; |
|
2216 |
} |
|
2217 |
} |
|
2218 |
||
2219 |
qWarning("QDBusConnectionPrivate::disconnectRelay called for a signal that was not found"); |
|
2220 |
} |
|
2221 |
||
2222 |
QString QDBusConnectionPrivate::getNameOwner(const QString& serviceName) |
|
2223 |
{ |
|
2224 |
if (QDBusUtil::isValidUniqueConnectionName(serviceName)) |
|
2225 |
return serviceName; |
|
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2226 |
if (!connection) |
0 | 2227 |
return QString(); |
2228 |
||
4
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2229 |
{ |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2230 |
// acquire a read lock for the cache |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2231 |
QReadLocker locker(&lock); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2232 |
WatchedServicesHash::ConstIterator it = watchedServices.constFind(serviceName); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2233 |
if (it != watchedServices.constEnd()) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2234 |
return it->owner; |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2235 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2236 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2237 |
// not cached |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2238 |
return getNameOwnerNoCache(serviceName); |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2239 |
} |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2240 |
|
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2241 |
QString QDBusConnectionPrivate::getNameOwnerNoCache(const QString &serviceName) |
3b1da2848fc7
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
2242 |
{ |
0 | 2243 |
QDBusMessage msg = QDBusMessage::createMethodCall(QLatin1String(DBUS_SERVICE_DBUS), |
2244 |
QLatin1String(DBUS_PATH_DBUS), QLatin1String(DBUS_INTERFACE_DBUS), |
|
2245 |
QLatin1String("GetNameOwner")); |
|
2246 |
QDBusMessagePrivate::setParametersValidated(msg, true); |
|
2247 |
msg << serviceName; |
|
2248 |
QDBusMessage reply = sendWithReply(msg, QDBus::Block); |
|
2249 |
if (reply.type() == QDBusMessage::ReplyMessage) |
|
2250 |
return reply.arguments().at(0).toString(); |
|
2251 |
return QString(); |
|
2252 |
} |
|
2253 |
||
2254 |
QDBusMetaObject * |
|
2255 |
QDBusConnectionPrivate::findMetaObject(const QString &service, const QString &path, |
|
2256 |
const QString &interface, QDBusError &error) |
|
2257 |
{ |
|
2258 |
// service must be a unique connection name |
|
2259 |
if (!interface.isEmpty()) { |
|
2260 |
QDBusReadLocker locker(FindMetaObject1Action, this); |
|
2261 |
QDBusMetaObject *mo = cachedMetaObjects.value(interface, 0); |
|
2262 |
if (mo) |
|
2263 |
return mo; |
|
2264 |
} |
|
2265 |
||
2266 |
// introspect the target object |
|
2267 |
QDBusMessage msg = QDBusMessage::createMethodCall(service, path, |
|
2268 |
QLatin1String(DBUS_INTERFACE_INTROSPECTABLE), |
|
2269 |
QLatin1String("Introspect")); |
|
2270 |
QDBusMessagePrivate::setParametersValidated(msg, true); |
|
2271 |
||
2272 |
QDBusMessage reply = sendWithReply(msg, QDBus::Block); |
|
2273 |
||
2274 |
// it doesn't exist yet, we have to create it |
|
2275 |
QDBusWriteLocker locker(FindMetaObject2Action, this); |
|
2276 |
QDBusMetaObject *mo = 0; |
|
2277 |
if (!interface.isEmpty()) |
|
2278 |
mo = cachedMetaObjects.value(interface, 0); |
|
2279 |
if (mo) |
|
2280 |
// maybe it got created when we switched from read to write lock |
|
2281 |
return mo; |
|
2282 |
||
2283 |
QString xml; |
|
2284 |
if (reply.type() == QDBusMessage::ReplyMessage) { |
|
2285 |
if (reply.signature() == QLatin1String("s")) |
|
2286 |
// fetch the XML description |
|
2287 |
xml = reply.arguments().at(0).toString(); |
|
2288 |
} else { |
|
2289 |
error = reply; |
|
2290 |
lastError = error; |
|
2291 |
if (reply.type() != QDBusMessage::ErrorMessage || error.type() != QDBusError::UnknownMethod) |
|
2292 |
return 0; // error |
|
2293 |
} |
|
2294 |
||
2295 |
// release the lock and return |
|
2296 |
QDBusMetaObject *result = QDBusMetaObject::createMetaObject(interface, xml, |
|
2297 |
cachedMetaObjects, error); |
|
2298 |
lastError = error; |
|
2299 |
return result; |
|
2300 |
} |
|
2301 |
||
2302 |
void QDBusConnectionPrivate::registerService(const QString &serviceName) |
|
2303 |
{ |
|
2304 |
QDBusWriteLocker locker(RegisterServiceAction, this); |
|
2305 |
serviceNames.append(serviceName); |
|
2306 |
} |
|
2307 |
||
2308 |
void QDBusConnectionPrivate::unregisterService(const QString &serviceName) |
|
2309 |
{ |
|
2310 |
QDBusWriteLocker locker(UnregisterServiceAction, this); |
|
2311 |
serviceNames.removeAll(serviceName); |
|
2312 |
} |
|
2313 |
||
2314 |
bool QDBusConnectionPrivate::isServiceRegisteredByThread(const QString &serviceName) const |
|
2315 |
{ |
|
2316 |
if (serviceName == baseService) |
|
2317 |
return true; |
|
2318 |
QStringList copy = serviceNames; |
|
2319 |
return copy.contains(serviceName); |
|
2320 |
} |
|
2321 |
||
2322 |
void QDBusConnectionPrivate::postEventToThread(int action, QObject *object, QEvent *ev) |
|
2323 |
{ |
|
2324 |
QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::BeforePost, this); |
|
2325 |
QCoreApplication::postEvent(object, ev); |
|
2326 |
QDBusLockerBase::reportThreadAction(action, QDBusLockerBase::AfterPost, this); |
|
2327 |
} |
|
2328 |
||
2329 |
QT_END_NAMESPACE |