diff options
Diffstat (limited to 'src/dbus/qdbuspendingcall.cpp')
-rw-r--r-- | src/dbus/qdbuspendingcall.cpp | 131 |
1 files changed, 53 insertions, 78 deletions
diff --git a/src/dbus/qdbuspendingcall.cpp b/src/dbus/qdbuspendingcall.cpp index 9bfdc8edce..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; @@ -185,10 +154,10 @@ bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *memb return true; } -void QDBusPendingCallPrivate::setMetaTypes(int count, const int *types) +void QDBusPendingCallPrivate::setMetaTypes(int count, const QMetaType *types) { if (count == 0) { - expectedReplySignature = QLatin1String(""); // not null + expectedReplySignature = ""_L1; // not null return; } @@ -196,10 +165,8 @@ void QDBusPendingCallPrivate::setMetaTypes(int count, const int *types) sig.reserve(count + count / 2); for (int i = 0; i < count; ++i) { const char *typeSig = QDBusMetaType::typeToSignature(types[i]); - if (Q_UNLIKELY(!typeSig)) { - qFatal("QDBusPendingReply: type %s is not registered with QtDBus", - QMetaType(types[i]).name()); - } + if (Q_UNLIKELY(!typeSig)) + qFatal("QDBusPendingReply: type %s is not registered with QtDBus", types[i].name()); sig += typeSig; } @@ -221,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)); @@ -240,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. @@ -258,7 +244,6 @@ QDBusPendingCall::QDBusPendingCall(QDBusPendingCallPrivate *dd) if (dd) { bool r = dd->ref.deref(); Q_ASSERT(r); - Q_UNUSED(r); } } @@ -310,8 +295,9 @@ QDBusPendingCall &QDBusPendingCall::operator=(const QDBusPendingCall &other) \sa QDBusPendingReply::isFinished() */ + /*! - \fn template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> bool QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::isFinished() const + \fn template <typename... Types> bool QDBusPendingReply<Types...>::isFinished() const Returns \c true if the pending call has finished processing and the reply has been received. If this function returns \c true, the @@ -340,7 +326,7 @@ void QDBusPendingCall::waitForFinished() } /*! - \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> bool QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::isValid() const + \fn template <typename... Types> bool QDBusPendingReply<Types...>::isValid() const Returns \c true if the reply contains a normal reply message, false if it contains anything else. @@ -357,7 +343,7 @@ bool QDBusPendingCall::isValid() const } /*! - \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> bool QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::isError() const + \fn template <typename... Types> bool QDBusPendingReply<Types...>::isError() const Returns \c true if the reply contains an error message, false if it contains a normal method reply. @@ -374,7 +360,7 @@ bool QDBusPendingCall::isError() const } /*! - \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusError QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::error() const + \fn template <typename... Types> QDBusError QDBusPendingReply<Types...>::error() const Retrieves the error content of the reply message, if it has finished processing. If the reply message has not finished @@ -395,7 +381,7 @@ QDBusError QDBusPendingCall::error() const } /*! - \fn template<typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8> QDBusMessage QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::reply() const + \fn template <typename... Types> QDBusMessage QDBusPendingReply<Types...>::reply() const Retrieves the reply message received for the asynchronous call that was sent, if it has finished processing. If the pending call @@ -445,7 +431,7 @@ bool QDBusPendingCall::setReplyCallback(QObject *target, const char *member) \since 4.6 Creates a QDBusPendingCall object based on the error condition \a error. The resulting pending call object will be in the - "finished" state and QDBusPendingReply<T1, T2, T3, T4, T5, T6, T7, T8>::isError() will return true. + "finished" state and QDBusPendingReply<Types...>::isError() will return true. \sa fromCompletedCall() */ @@ -479,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); @@ -508,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); @@ -546,6 +519,8 @@ void QDBusPendingCallWatcher::waitForFinished() } QT_END_NAMESPACE +#include "moc_qdbuspendingcall_p.cpp" + #endif // QT_NO_DBUS #include "moc_qdbuspendingcall.cpp" |