From 42858a9e88db6006ab541f3077f033415386400d Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 29 Dec 2014 18:01:39 -0200 Subject: [PATCH] Simplify some code in QDBusConnectionPrivate::sendWithReplyAsync They're pretty much the same, clearly a copy & paste. Instead, merge the two codepaths so that we don't run the risk of applying a change in one part and forgetting the other. Task-number: QTBUG-43585 Change-Id: Ic5d393bfd36e48a193fcffff13b737560f6753be Reviewed-by: Albert Astals Cid Reviewed-by: Alex Blasche --- src/dbus/qdbusintegrator.cpp | 35 +++++++++++------------------------ 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/src/dbus/qdbusintegrator.cpp b/src/dbus/qdbusintegrator.cpp index 6e37ea6f7c..e87ae5b29d 100644 --- a/src/dbus/qdbusintegrator.cpp +++ b/src/dbus/qdbusintegrator.cpp @@ -2038,34 +2038,15 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM QObject *receiver, const char *returnMethod, const char *errorMethod, int timeout) { - if (isServiceRegisteredByThread(message.service())) { + checkThread(); + + QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate(message, this); + bool isLoopback; + if ((isLoopback = isServiceRegisteredByThread(message.service()))) { // special case for local calls - QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate(message, this); pcall->replyMessage = sendWithReplyLocal(message); - if (receiver && returnMethod) - pcall->setReplyCallback(receiver, returnMethod); - - if (errorMethod) { - pcall->watcherHelper = new QDBusPendingCallWatcherHelper; - connect(pcall->watcherHelper, SIGNAL(error(QDBusError,QDBusMessage)), receiver, errorMethod, - Qt::QueuedConnection); - pcall->watcherHelper->moveToThread(thread()); - } - - if ((receiver && returnMethod) || errorMethod) { - // no one waiting, will delete pcall in processFinishedCall() - pcall->ref.store(1); - } else { - // set double ref to prevent race between processFinishedCall() and ref counting - // by QDBusPendingCall::QExplicitlySharedDataPointer - pcall->ref.store(2); - } - processFinishedCall(pcall); - return pcall; } - checkThread(); - QDBusPendingCallPrivate *pcall = new QDBusPendingCallPrivate(message, this); if (receiver && returnMethod) pcall->setReplyCallback(receiver, returnMethod); @@ -2085,6 +2066,12 @@ QDBusPendingCallPrivate *QDBusConnectionPrivate::sendWithReplyAsync(const QDBusM pcall->ref.store(2); } + if (isLoopback) { + // a loopback call + processFinishedCall(pcall); + return pcall; + } + QDBusError error; DBusMessage *msg = QDBusMessagePrivate::toDBusMessage(message, capabilities, &error); if (!msg) {