diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2014-12-29 19:16:53 -0200 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2015-09-15 02:08:41 +0000 |
commit | df7064c1514c66610c56487e0444036539aa8645 (patch) | |
tree | 29292f46c47413cc859033625e6e98e6a2e6cbd0 /src/dbus | |
parent | 6734c50a9eefa51f693e3d799d7b18fba9b7da04 (diff) |
Move the sending of the D-Bus messages with reply to the thread
This is intended to simply the handling of the socket in the
future. Now, we know that all calls to send_with_reply are placed only
from the manager's thread.
Task-number: QTBUG-43585
Change-Id: Ic5d393bfd36e48a193fcffff13b737575c231927
Reviewed-by: Albert Astals Cid <aacid@kde.org>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
Diffstat (limited to 'src/dbus')
-rw-r--r-- | src/dbus/qdbusconnection.cpp | 2 | ||||
-rw-r--r-- | src/dbus/qdbusconnection_p.h | 2 | ||||
-rw-r--r-- | src/dbus/qdbusintegrator.cpp | 22 |
3 files changed, 18 insertions, 8 deletions
diff --git a/src/dbus/qdbusconnection.cpp b/src/dbus/qdbusconnection.cpp index 47255992ae..8ebdf4c66e 100644 --- a/src/dbus/qdbusconnection.cpp +++ b/src/dbus/qdbusconnection.cpp @@ -483,7 +483,7 @@ bool QDBusConnection::send(const QDBusMessage &message) const d->lastError = err; return false; } - return d->send(message) != 0; + return d->send(message); } /*! diff --git a/src/dbus/qdbusconnection_p.h b/src/dbus/qdbusconnection_p.h index 2155bd634c..3becc7cbc3 100644 --- a/src/dbus/qdbusconnection_p.h +++ b/src/dbus/qdbusconnection_p.h @@ -242,6 +242,7 @@ private: bool activateInternalFilters(const ObjectTreeNode &node, const QDBusMessage &msg); bool activateCall(QObject *object, int flags, const QDBusMessage &msg); + void sendInternal(QDBusPendingCallPrivate *pcall, void *msg, int timeout); void sendError(const QDBusMessage &msg, QDBusError::ErrorType code); void deliverCall(QObject *object, int flags, const QDBusMessage &msg, const QVector<int> &metaTypes, int slotIdx); @@ -271,6 +272,7 @@ private slots: signals: void dispatchStatusChanged(); + void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout); void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner); void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message); void newServerConnection(QDBusConnectionPrivate *newConnection); diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 8cffe4d706..77f27e6fb1 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -1022,6 +1022,8 @@ QDBusConnectionPrivate::QDBusConnectionPrivate(QObject *p) QDBusMetaTypeId::init(); connect(this, &QDBusConnectionPrivate::dispatchStatusChanged, this, &QDBusConnectionPrivate::doDispatch, Qt::QueuedConnection); + connect(this, &QDBusConnectionPrivate::messageNeedsSending, + this, &QDBusConnectionPrivate::sendInternal); rootNode.flags = 0; @@ -1092,6 +1094,7 @@ void QDBusConnectionPrivate::closeConnection() void QDBusConnectionPrivate::checkThread() { Q_ASSERT(thread() == QDBusConnectionManager::instance()); + Q_ASSERT(QThread::currentThread() == thread()); } bool QDBusConnectionPrivate::handleError(const QDBusErrorInternal &error) @@ -1822,7 +1825,6 @@ void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call) } if (call->pending) { - call->waitForFinishedCondition.wakeAll(); q_dbus_pending_call_unref(call->pending); call->pending = 0; } @@ -1831,6 +1833,7 @@ void QDBusConnectionPrivate::processFinishedCall(QDBusPendingCallPrivate *call) if (call->watcherHelper) call->watcherHelper->emitSignals(msg, call->sentMessage); + call->waitForFinishedCondition.wakeAll(); locker.unlock(); if (msg.type() == QDBusMessage::ErrorMessage) @@ -2032,8 +2035,6 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout) { - checkThread(); - QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate(message, this); bool isLoopback; if ((isLoopback = isServiceRegisteredByThread(message.service()))) { @@ -2076,11 +2077,19 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM pcall->replyMessage = QDBusMessage::createError(error); lastError = error; processFinishedCall(pcall); - return pcall; + } else { + qDBusDebug() << this << "sending message:" << message; + emit messageNeedsSending(pcall, msg, timeout); } + return pcall; +} - qDBusDebug() << this << "sending message:" << message; +void QDBusConnectionPrivate::sendInternal(QDBusPendingCallPrivate *pcall, void *message, int timeout) +{ + QDBusError error; DBusPendingCall *pending = 0; + DBusMessage *msg = static_cast<DBusMessage *>(message); + checkThread(); QDBusDispatchLocker locker(SendWithReplyAsyncAction, this); if (q_dbus_connection_send_with_reply(connection, msg, &pending, timeout)) { @@ -2094,7 +2103,7 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM if (mode == QDBusConnectionPrivate::PeerMode) pendingCalls.append(pcall); - return pcall; + return; } else { // we're probably disconnected at this point lastError = error = QDBusError(QDBusError::Disconnected, QDBusUtil::disconnectedErrorMessage()); @@ -2106,7 +2115,6 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM q_dbus_message_unref(msg); pcall->replyMessage = QDBusMessage::createError(error); processFinishedCall(pcall); - return pcall; } bool QDBusConnectionPrivate::connectSignal(const QString &service, |