diff options
Diffstat (limited to 'src/dbus/qdbuspendingcall.cpp')
-rw-r--r-- | src/dbus/qdbuspendingcall.cpp | 110 |
1 files changed, 43 insertions, 67 deletions
diff --git a/src/dbus/qdbuspendingcall.cpp b/src/dbus/qdbuspendingcall.cpp index 74aa1629fa..f9d414d1bd 100644 --- a/src/dbus/qdbuspendingcall.cpp +++ b/src/dbus/qdbuspendingcall.cpp @@ -1,42 +1,6 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtDBus module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// Copyright (C) 2016 Intel Corporation. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qdbuspendingcall.h" #include "qdbuspendingcall_p.h" @@ -53,6 +17,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + /*! \class QDBusPendingCall \inmodule QtDBus @@ -128,7 +94,8 @@ QT_BEGIN_NAMESPACE void QDBusPendingCallWatcherHelper::add(QDBusPendingCallWatcher *watcher) { - connect(this, SIGNAL(finished()), watcher, SLOT(_q_finished()), Qt::QueuedConnection); + connect(this, &QDBusPendingCallWatcherHelper::finished, watcher, + [watcher] { Q_EMIT watcher->finished(watcher); }, Qt::QueuedConnection); } QDBusPendingCallPrivate::~QDBusPendingCallPrivate() @@ -157,22 +124,24 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb return false; } - methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes); + QString errorMsg; + methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes, errorMsg); if (methodIdx == -1) { QByteArray normalizedName = QMetaObject::normalizedSignature(member + 1); - methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes); + methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes, errorMsg); } if (methodIdx == -1) { // would not be able to deliver a reply - qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s)", - target->metaObject()->className(), - member + 1, qPrintable(target->objectName())); + qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s) " + "because %s", + target->metaObject()->className(), member + 1, qPrintable(target->objectName()), + qPrintable(errorMsg)); return false; } // success // construct the expected signature - int count = metaTypes.count() - 1; + int count = metaTypes.size() - 1; if (count == 1 && metaTypes.at(1) == QDBusMetaTypeId::message()) { // wildcard slot, can receive anything, so don't set the signature return true; @@ -188,7 +157,7 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb void QDBusPendingCallPrivate::setMetaTypes(int count, const QMetaType *types) { if (count == 0) { - expectedReplySignature = QLatin1String(""); // not null + expectedReplySignature = ""_L1; // not null return; } @@ -219,8 +188,7 @@ void QDBusPendingCallPrivate::checkReceivedSignature() // can't use startsWith here because a null string doesn't start or end with an empty string if (replyMessage.signature().indexOf(expectedReplySignature) != 0) { - const auto errorMsg = QLatin1String("Unexpected reply signature: got \"%1\", " - "expected \"%2\""); + const auto errorMsg = "Unexpected reply signature: got \"%1\", expected \"%2\""_L1; replyMessage = QDBusMessage::createError( QDBusError::InvalidSignature, errorMsg.arg(replyMessage.signature(), expectedReplySignature)); @@ -238,6 +206,26 @@ void QDBusPendingCallPrivate::waitForFinished() waitForFinishedCondition.wait(&mutex); } +void QDBusPendingCallPrivate::waitForFinishedWithGui() +{ + QEventLoop loop; + + { + const auto locker = qt_scoped_lock(mutex); + if (replyMessage.type() != QDBusMessage::InvalidMessage) + return; // already finished + + Q_ASSERT(!watcherHelper); + watcherHelper = new QDBusPendingCallWatcherHelper; + loop.connect(watcherHelper, &QDBusPendingCallWatcherHelper::reply, &loop, + &QEventLoop::quit); + loop.connect(watcherHelper, &QDBusPendingCallWatcherHelper::error, &loop, + &QEventLoop::quit); + } + + loop.exec(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents); +} + /*! Creates a copy of the \a other pending asynchronous call. Note that both objects will refer to the same pending call. @@ -256,7 +244,6 @@ QDBusPendingCall::QDBusPendingCall(QDBusPendingCallPrivate *dd) if (dd) { bool r = dd->ref.deref(); Q_ASSERT(r); - Q_UNUSED(r); } } @@ -478,28 +465,13 @@ QDBusPendingCall QDBusPendingCall::fromCompletedCall(const QDBusMessage &msg) return QDBusPendingCall(d); } - -class QDBusPendingCallWatcherPrivate: public QObjectPrivate -{ -public: - void _q_finished(); - - Q_DECLARE_PUBLIC(QDBusPendingCallWatcher) -}; - -inline void QDBusPendingCallWatcherPrivate::_q_finished() -{ - Q_Q(QDBusPendingCallWatcher); - emit q->finished(q); -} - /*! Creates a QDBusPendingCallWatcher object to watch for replies on the asynchronous pending call \a call and sets this object's parent to \a parent. */ QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent) - : QObject(*new QDBusPendingCallWatcherPrivate, parent), QDBusPendingCall(call) + : QObject(parent), QDBusPendingCall(call) { if (d) { // QDBusPendingCall::d const auto locker = qt_scoped_lock(d->mutex); @@ -507,7 +479,9 @@ QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, Q d->watcherHelper = new QDBusPendingCallWatcherHelper; if (d->replyMessage.type() != QDBusMessage::InvalidMessage) { // cause a signal emission anyways - QMetaObject::invokeMethod(d->watcherHelper, "finished", Qt::QueuedConnection); + QMetaObject::invokeMethod(d->watcherHelper, + &QDBusPendingCallWatcherHelper::finished, + Qt::QueuedConnection); } } d->watcherHelper->add(this); @@ -545,6 +519,8 @@ void QDBusPendingCallWatcher::waitForFinished() } QT_END_NAMESPACE +#include "moc_qdbuspendingcall_p.cpp" + #endif // QT_NO_DBUS #include "moc_qdbuspendingcall.cpp" |