And move the sending of other types of D-Bus messages to the thread

With this, we now know that all messages sent are sent from the same
thread. This simplifies greatly the handling of the socket.

Task-number: QTBUG-43585
Change-Id: Ic5d393bfd36e48a193fcffff13b73758087344ed
Reviewed-by: Albert Astals Cid <aacid@kde.org>
Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
bb10
Thiago Macieira 2014-12-29 19:47:54 -02:00
parent df7064c151
commit 5d41a4aa5a
3 changed files with 16 additions and 13 deletions

View File

@ -272,7 +272,7 @@ private slots:
signals:
void dispatchStatusChanged();
void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout);
void messageNeedsSending(QDBusPendingCallPrivate *pcall, void *msg, int timeout = -1);
void serviceOwnerChanged(const QString &name, const QString &oldOwner, const QString &newOwner);
void callWithCallbackFailed(const QDBusError &error, const QDBusMessage &message);
void newServerConnection(QDBusConnectionPrivate *newConnection);

View File

@ -1874,13 +1874,9 @@ bool QDBusConnectionPrivate::send(const QDBusMessage& message)
}
q_dbus_message_set_no_reply(msg, true); // the reply would not be delivered to anything
qDBusDebug() << this << "sending message (no reply):" << message;
checkThread();
QDBusDispatchLocker locker(SendMessageAction, this);
bool isOk = q_dbus_connection_send(connection, msg, 0);
q_dbus_message_unref(msg);
return isOk;
emit messageNeedsSending(Q_NULLPTR, msg);
return true;
}
// small helper to note long running blocking dbus calls.
@ -2089,10 +2085,15 @@ void QDBusConnectionPrivate::sendInternal(QDBusPendingCallPrivate *pcall, void *
QDBusError error;
DBusPendingCall *pending = 0;
DBusMessage *msg = static_cast<DBusMessage *>(message);
checkThread();
bool isNoReply = !pcall;
Q_ASSERT(isNoReply == !!q_dbus_message_get_no_reply(msg));
QDBusDispatchLocker locker(SendWithReplyAsyncAction, this);
if (q_dbus_connection_send_with_reply(connection, msg, &pending, timeout)) {
checkThread();
QDBusDispatchLocker locker(SendMessageAction, this);
if (isNoReply && q_dbus_connection_send(connection, msg, Q_NULLPTR)) {
// success
} else if (!isNoReply && q_dbus_connection_send_with_reply(connection, msg, &pending, timeout)) {
if (pending) {
q_dbus_message_unref(msg);
@ -2113,8 +2114,10 @@ void QDBusConnectionPrivate::sendInternal(QDBusPendingCallPrivate *pcall, void *
}
q_dbus_message_unref(msg);
pcall->replyMessage = QDBusMessage::createError(error);
processFinishedCall(pcall);
if (pcall) {
pcall->replyMessage = QDBusMessage::createError(error);
processFinishedCall(pcall);
}
}
bool QDBusConnectionPrivate::connectSignal(const QString &service,

View File

@ -83,7 +83,7 @@ enum ThreadAction {
HandleObjectCallPostEventAction = 22,
HandleObjectCallSemaphoreAction = 23,
DoDispatchAction = 24,
SendWithReplyAsyncAction = 25,
// unused: 25,
MessageResultReceivedAction = 26,
ActivateSignalAction = 27,
PendingCallBlockAction = 28,