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