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 <aacid@kde.org>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
bb10
Thiago Macieira 2014-12-29 18:01:39 -02:00
parent c2049f67e4
commit 42858a9e88
1 changed files with 11 additions and 24 deletions

View File

@ -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<QDBusPendingCallPrivate>
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) {