| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbuspendingcall.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||
| 2 | ** | - | ||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||
| 4 | ** Copyright (C) 2015 Intel Corporation. | - | ||||||||||||
| 5 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||
| 6 | ** | - | ||||||||||||
| 7 | ** This file is part of the QtDBus module of the Qt Toolkit. | - | ||||||||||||
| 8 | ** | - | ||||||||||||
| 9 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||
| 10 | ** Commercial License Usage | - | ||||||||||||
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
| 12 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
| 13 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
| 14 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
| 15 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||
| 16 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||
| 17 | ** | - | ||||||||||||
| 18 | ** GNU Lesser General Public License Usage | - | ||||||||||||
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
| 20 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||
| 21 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||
| 22 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||
| 23 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||
| 24 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||
| 25 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||
| 26 | ** | - | ||||||||||||
| 27 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||
| 28 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||
| 29 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||
| 30 | ** | - | ||||||||||||
| 31 | ** $QT_END_LICENSE$ | - | ||||||||||||
| 32 | ** | - | ||||||||||||
| 33 | ****************************************************************************/ | - | ||||||||||||
| 34 | - | |||||||||||||
| 35 | #include "qdbuspendingcall.h" | - | ||||||||||||
| 36 | #include "qdbuspendingcall_p.h" | - | ||||||||||||
| 37 | - | |||||||||||||
| 38 | #include "qdbusconnection_p.h" | - | ||||||||||||
| 39 | #include "qdbusmetatype_p.h" | - | ||||||||||||
| 40 | #include "qdbusutil_p.h" | - | ||||||||||||
| 41 | #include "qcoreapplication.h" | - | ||||||||||||
| 42 | #include "qcoreevent.h" | - | ||||||||||||
| 43 | #include <private/qobject_p.h> | - | ||||||||||||
| 44 | - | |||||||||||||
| 45 | #ifndef QT_NO_DBUS | - | ||||||||||||
| 46 | - | |||||||||||||
| 47 | QT_BEGIN_NAMESPACE | - | ||||||||||||
| 48 | - | |||||||||||||
| 49 | /*! | - | ||||||||||||
| 50 | \class QDBusPendingCall | - | ||||||||||||
| 51 | \inmodule QtDBus | - | ||||||||||||
| 52 | \ingroup shared | - | ||||||||||||
| 53 | \since 4.5 | - | ||||||||||||
| 54 | - | |||||||||||||
| 55 | \brief The QDBusPendingCall class refers to one pending asynchronous call | - | ||||||||||||
| 56 | - | |||||||||||||
| 57 | A QDBusPendingCall object is a reference to a method call that was | - | ||||||||||||
| 58 | sent over D-Bus without waiting for a reply. QDBusPendingCall is an | - | ||||||||||||
| 59 | opaque type, meant to be used as a handle for a pending reply. | - | ||||||||||||
| 60 | - | |||||||||||||
| 61 | In most programs, the QDBusPendingCall class will not be used | - | ||||||||||||
| 62 | directly. It can be safely replaced with the template-based | - | ||||||||||||
| 63 | QDBusPendingReply, in order to access the contents of the reply or | - | ||||||||||||
| 64 | wait for it to be complete. | - | ||||||||||||
| 65 | - | |||||||||||||
| 66 | The QDBusPendingCallWatcher class allows one to connect to a signal | - | ||||||||||||
| 67 | that will indicate when the reply has arrived or if the call has | - | ||||||||||||
| 68 | timed out. It also provides the | - | ||||||||||||
| 69 | QDBusPendingCallWatcher::waitForFinished() method which will suspend | - | ||||||||||||
| 70 | the execution of the program until the reply has arrived. | - | ||||||||||||
| 71 | - | |||||||||||||
| 72 | \note If you create a copy of a QDBusPendingCall object, all | - | ||||||||||||
| 73 | information will be shared among the many copies. Therefore, | - | ||||||||||||
| 74 | QDBusPendingCall is an explicitly-shared object and does not | - | ||||||||||||
| 75 | provide a method of detaching the copies (since they refer | - | ||||||||||||
| 76 | to the same pending call) | - | ||||||||||||
| 77 | - | |||||||||||||
| 78 | \sa QDBusPendingReply, QDBusPendingCallWatcher, | - | ||||||||||||
| 79 | QDBusAbstractInterface::asyncCall() | - | ||||||||||||
| 80 | */ | - | ||||||||||||
| 81 | - | |||||||||||||
| 82 | /*! | - | ||||||||||||
| 83 | \class QDBusPendingCallWatcher | - | ||||||||||||
| 84 | \inmodule QtDBus | - | ||||||||||||
| 85 | \since 4.5 | - | ||||||||||||
| 86 | - | |||||||||||||
| 87 | \brief The QDBusPendingCallWatcher class provides a convenient way for | - | ||||||||||||
| 88 | waiting for asynchronous replies | - | ||||||||||||
| 89 | - | |||||||||||||
| 90 | The QDBusPendingCallWatcher provides the finished() signal that will be | - | ||||||||||||
| 91 | emitted when a reply arrives. | - | ||||||||||||
| 92 | - | |||||||||||||
| 93 | It is usually used like the following example: | - | ||||||||||||
| 94 | - | |||||||||||||
| 95 | \snippet code/src_qdbus_qdbuspendingcall.cpp 0 | - | ||||||||||||
| 96 | - | |||||||||||||
| 97 | Note that it is not necessary to keep the original QDBusPendingCall | - | ||||||||||||
| 98 | object around since QDBusPendingCallWatcher inherits from that class | - | ||||||||||||
| 99 | too. | - | ||||||||||||
| 100 | - | |||||||||||||
| 101 | The slot connected to by the above code could be something similar | - | ||||||||||||
| 102 | to the following: | - | ||||||||||||
| 103 | - | |||||||||||||
| 104 | \snippet code/src_qdbus_qdbuspendingcall.cpp 1 | - | ||||||||||||
| 105 | - | |||||||||||||
| 106 | Note the use of QDBusPendingReply to validate the argument types in | - | ||||||||||||
| 107 | the reply. If the reply did not contain exactly two arguments | - | ||||||||||||
| 108 | (one string and one QByteArray), QDBusPendingReply::isError() will | - | ||||||||||||
| 109 | return true. | - | ||||||||||||
| 110 | - | |||||||||||||
| 111 | \sa QDBusPendingReply, QDBusAbstractInterface::asyncCall() | - | ||||||||||||
| 112 | */ | - | ||||||||||||
| 113 | - | |||||||||||||
| 114 | /*! | - | ||||||||||||
| 115 | \fn void QDBusPendingCallWatcher::finished(QDBusPendingCallWatcher *self) | - | ||||||||||||
| 116 | - | |||||||||||||
| 117 | This signal is emitted when the pending call has finished and its | - | ||||||||||||
| 118 | reply is available. The \a self parameter is a pointer to the | - | ||||||||||||
| 119 | object itself, passed for convenience so that the slot can access | - | ||||||||||||
| 120 | the properties and determine the contents of the reply. | - | ||||||||||||
| 121 | */ | - | ||||||||||||
| 122 | - | |||||||||||||
| 123 | void QDBusPendingCallWatcherHelper::add(QDBusPendingCallWatcher *watcher) | - | ||||||||||||
| 124 | { | - | ||||||||||||
| 125 | connect(this, SIGNAL(finished()), watcher, SLOT(_q_finished()), Qt::QueuedConnection); | - | ||||||||||||
| 126 | } executed 45 times by 18 tests: end of blockExecuted by:
| 45 | ||||||||||||
| 127 | - | |||||||||||||
| 128 | QDBusPendingCallPrivate::~QDBusPendingCallPrivate() | - | ||||||||||||
| 129 | { | - | ||||||||||||
| 130 | if (pending) {
| 0-2786 | ||||||||||||
| 131 | q_dbus_pending_call_cancel(pending); | - | ||||||||||||
| 132 | q_dbus_pending_call_unref(pending); | - | ||||||||||||
| 133 | } never executed: end of block | 0 | ||||||||||||
| 134 | delete watcherHelper; | - | ||||||||||||
| 135 | } executed 2786 times by 158 tests: end of blockExecuted by:
| 2786 | ||||||||||||
| 136 | - | |||||||||||||
| 137 | bool QDBusPendingCallPrivate::setReplyCallback(QObject *target, const char *member) | - | ||||||||||||
| 138 | { | - | ||||||||||||
| 139 | receiver = target; | - | ||||||||||||
| 140 | metaTypes.clear(); | - | ||||||||||||
| 141 | methodIdx = -1; | - | ||||||||||||
| 142 | if (!target)
| 0-12 | ||||||||||||
| 143 | return true;; // unsetting never executed: return true; | 0 | ||||||||||||
| 144 | - | |||||||||||||
| 145 | if (!member || !*member) {
| 0-12 | ||||||||||||
| 146 | // would not be able to deliver a reply | - | ||||||||||||
| 147 | qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s)", | - | ||||||||||||
| 148 | target ? target->metaObject()->className() : "(null)", | - | ||||||||||||
| 149 | member ? member + 1 : "(null)", | - | ||||||||||||
| 150 | target ? qPrintable(target->objectName()) : "no name"); | - | ||||||||||||
| 151 | return false; never executed: return false; | 0 | ||||||||||||
| 152 | } | - | ||||||||||||
| 153 | - | |||||||||||||
| 154 | methodIdx = QDBusConnectionPrivate::findSlot(target, member + 1, metaTypes); | - | ||||||||||||
| 155 | if (methodIdx == -1) {
| 0-12 | ||||||||||||
| 156 | QByteArray normalizedName = QMetaObject::normalizedSignature(member + 1); | - | ||||||||||||
| 157 | methodIdx = QDBusConnectionPrivate::findSlot(target, normalizedName, metaTypes); | - | ||||||||||||
| 158 | } never executed: end of block | 0 | ||||||||||||
| 159 | if (methodIdx == -1) {
| 0-12 | ||||||||||||
| 160 | // would not be able to deliver a reply | - | ||||||||||||
| 161 | qWarning("QDBusPendingCall::setReplyCallback: error: cannot deliver a reply to %s::%s (%s)", | - | ||||||||||||
| 162 | target->metaObject()->className(), | - | ||||||||||||
| 163 | member + 1, qPrintable(target->objectName())); | - | ||||||||||||
| 164 | return false; never executed: return false; | 0 | ||||||||||||
| 165 | } | - | ||||||||||||
| 166 | - | |||||||||||||
| 167 | // success | - | ||||||||||||
| 168 | // construct the expected signature | - | ||||||||||||
| 169 | int count = metaTypes.count() - 1; | - | ||||||||||||
| 170 | if (count == 1 && metaTypes.at(1) == QDBusMetaTypeId::message()) {
| 2-8 | ||||||||||||
| 171 | // wildcard slot, can receive anything, so don't set the signature | - | ||||||||||||
| 172 | return true; executed 2 times by 2 tests: return true;Executed by:
| 2 | ||||||||||||
| 173 | } | - | ||||||||||||
| 174 | - | |||||||||||||
| 175 | if (metaTypes.at(count) == QDBusMetaTypeId::message())
| 0-10 | ||||||||||||
| 176 | --count; never executed: --count; | 0 | ||||||||||||
| 177 | - | |||||||||||||
| 178 | setMetaTypes(count, count ? metaTypes.constData() + 1 : 0); | - | ||||||||||||
| 179 | return true; executed 10 times by 4 tests: return true;Executed by:
| 10 | ||||||||||||
| 180 | } | - | ||||||||||||
| 181 | - | |||||||||||||
| 182 | void QDBusPendingCallPrivate::setMetaTypes(int count, const int *types) | - | ||||||||||||
| 183 | { | - | ||||||||||||
| 184 | if (count == 0) {
| 14-274 | ||||||||||||
| 185 | expectedReplySignature = QLatin1String(""); // not null | - | ||||||||||||
| 186 | return; executed 14 times by 5 tests: return;Executed by:
| 14 | ||||||||||||
| 187 | } | - | ||||||||||||
| 188 | - | |||||||||||||
| 189 | QByteArray sig; | - | ||||||||||||
| 190 | sig.reserve(count + count / 2); | - | ||||||||||||
| 191 | for (int i = 0; i < count; ++i) {
| 274-278 | ||||||||||||
| 192 | const char *typeSig = QDBusMetaType::typeToSignature(types[i]); | - | ||||||||||||
| 193 | if (!typeSig) {
| 0-278 | ||||||||||||
| 194 | qFatal("QDBusPendingReply: type %s is not registered with QtDBus", | - | ||||||||||||
| 195 | QMetaType::typeName(types[i])); | - | ||||||||||||
| 196 | } never executed: end of block | 0 | ||||||||||||
| 197 | sig += typeSig; | - | ||||||||||||
| 198 | } executed 278 times by 19 tests: end of blockExecuted by:
| 278 | ||||||||||||
| 199 | - | |||||||||||||
| 200 | expectedReplySignature = QString::fromLatin1(sig); | - | ||||||||||||
| 201 | } executed 274 times by 19 tests: end of blockExecuted by:
| 274 | ||||||||||||
| 202 | - | |||||||||||||
| 203 | void QDBusPendingCallPrivate::checkReceivedSignature() | - | ||||||||||||
| 204 | { | - | ||||||||||||
| 205 | // MUST BE CALLED WITH A LOCKED MUTEX! | - | ||||||||||||
| 206 | - | |||||||||||||
| 207 | if (replyMessage.type() == QDBusMessage::InvalidMessage)
| 43-2830 | ||||||||||||
| 208 | return; // not yet finished - no message to executed 43 times by 16 tests: return;Executed by:
| 43 | ||||||||||||
| 209 | // validate against | - | ||||||||||||
| 210 | if (replyMessage.type() == QDBusMessage::ErrorMessage)
| 416-2414 | ||||||||||||
| 211 | return; // we don't have to check the signature of an error reply executed 416 times by 29 tests: return;Executed by:
| 416 | ||||||||||||
| 212 | - | |||||||||||||
| 213 | if (expectedReplySignature.isNull())
| 230-2184 | ||||||||||||
| 214 | return; // no signature to validate against executed 2184 times by 158 tests: return;Executed by:
| 2184 | ||||||||||||
| 215 | - | |||||||||||||
| 216 | // can't use startsWith here because a null string doesn't start or end with an empty string | - | ||||||||||||
| 217 | if (replyMessage.signature().indexOf(expectedReplySignature) != 0) {
| 9-221 | ||||||||||||
| 218 | QString errorMsg = QLatin1String("Unexpected reply signature: got \"%1\", " | - | ||||||||||||
| 219 | "expected \"%2\""); | - | ||||||||||||
| 220 | replyMessage = QDBusMessage::createError( | - | ||||||||||||
| 221 | QDBusError::InvalidSignature, | - | ||||||||||||
| 222 | errorMsg.arg(replyMessage.signature(), expectedReplySignature)); | - | ||||||||||||
| 223 | - | |||||||||||||
| 224 | } executed 9 times by 1 test: end of blockExecuted by:
| 9 | ||||||||||||
| 225 | } executed 230 times by 22 tests: end of blockExecuted by:
| 230 | ||||||||||||
| 226 | - | |||||||||||||
| 227 | void QDBusPendingCallPrivate::waitForFinished() | - | ||||||||||||
| 228 | { | - | ||||||||||||
| 229 | QMutexLocker locker(&mutex); | - | ||||||||||||
| 230 | - | |||||||||||||
| 231 | if (replyMessage.type() != QDBusMessage::InvalidMessage)
| 464-1234 | ||||||||||||
| 232 | return; // already finished executed 464 times by 30 tests: return;Executed by:
| 464 | ||||||||||||
| 233 | - | |||||||||||||
| 234 | waitForFinishedCondition.wait(&mutex); | - | ||||||||||||
| 235 | } executed 1234 times by 154 tests: end of blockExecuted by:
| 1234 | ||||||||||||
| 236 | - | |||||||||||||
| 237 | /*! | - | ||||||||||||
| 238 | Creates a copy of the \a other pending asynchronous call. Note | - | ||||||||||||
| 239 | that both objects will refer to the same pending call. | - | ||||||||||||
| 240 | */ | - | ||||||||||||
| 241 | QDBusPendingCall::QDBusPendingCall(const QDBusPendingCall &other) | - | ||||||||||||
| 242 | : d(other.d) | - | ||||||||||||
| 243 | { | - | ||||||||||||
| 244 | } executed 75 times by 20 tests: end of blockExecuted by:
| 75 | ||||||||||||
| 245 | - | |||||||||||||
| 246 | /*! | - | ||||||||||||
| 247 | \internal | - | ||||||||||||
| 248 | */ | - | ||||||||||||
| 249 | QDBusPendingCall::QDBusPendingCall(QDBusPendingCallPrivate *dd) | - | ||||||||||||
| 250 | : d(dd) | - | ||||||||||||
| 251 | { | - | ||||||||||||
| 252 | if (dd) {
| 131-278 | ||||||||||||
| 253 | bool r = dd->ref.deref(); | - | ||||||||||||
| 254 | Q_ASSERT(r); | - | ||||||||||||
| 255 | Q_UNUSED(r); | - | ||||||||||||
| 256 | } executed 131 times by 23 tests: end of blockExecuted by:
| 131 | ||||||||||||
| 257 | } executed 409 times by 24 tests: end of blockExecuted by:
| 409 | ||||||||||||
| 258 | - | |||||||||||||
| 259 | /*! | - | ||||||||||||
| 260 | Destroys this copy of the QDBusPendingCall object. If this copy is | - | ||||||||||||
| 261 | also the last copy of a pending asynchronous call, the call will | - | ||||||||||||
| 262 | be canceled and no further notifications will be received. There | - | ||||||||||||
| 263 | will be no way of accessing the reply's contents when it arrives. | - | ||||||||||||
| 264 | */ | - | ||||||||||||
| 265 | QDBusPendingCall::~QDBusPendingCall() | - | ||||||||||||
| 266 | { | - | ||||||||||||
| 267 | // d deleted by QExplicitlySharedDataPointer | - | ||||||||||||
| 268 | } | - | ||||||||||||
| 269 | - | |||||||||||||
| 270 | - | |||||||||||||
| 271 | /*! | - | ||||||||||||
| 272 | Creates a copy of the \a other pending asynchronous call and drops | - | ||||||||||||
| 273 | the reference to the previously-referenced call. Note that both | - | ||||||||||||
| 274 | objects will refer to the same pending call after this function. | - | ||||||||||||
| 275 | - | |||||||||||||
| 276 | If this object contained the last reference of a pending | - | ||||||||||||
| 277 | asynchronous call, the call will be canceled and no further | - | ||||||||||||
| 278 | notifications will be received. There will be no way of accessing | - | ||||||||||||
| 279 | the reply's contents when it arrives. | - | ||||||||||||
| 280 | */ | - | ||||||||||||
| 281 | QDBusPendingCall &QDBusPendingCall::operator=(const QDBusPendingCall &other) | - | ||||||||||||
| 282 | { | - | ||||||||||||
| 283 | d = other.d; | - | ||||||||||||
| 284 | return *this; executed 103 times by 18 tests: return *this;Executed by:
| 103 | ||||||||||||
| 285 | } | - | ||||||||||||
| 286 | - | |||||||||||||
| 287 | /*! | - | ||||||||||||
| 288 | \fn void QDBusPendingCall::swap(QDBusPendingCall &other) | - | ||||||||||||
| 289 | \since 5.0 | - | ||||||||||||
| 290 | - | |||||||||||||
| 291 | Swaps this pending call instance with \a other. This function is | - | ||||||||||||
| 292 | very fast and never fails. | - | ||||||||||||
| 293 | */ | - | ||||||||||||
| 294 | - | |||||||||||||
| 295 | /*! | - | ||||||||||||
| 296 | \fn bool QDBusPendingCallWatcher::isFinished() const | - | ||||||||||||
| 297 | - | |||||||||||||
| 298 | Returns \c true if the pending call has finished processing and the | - | ||||||||||||
| 299 | reply has been received. | - | ||||||||||||
| 300 | - | |||||||||||||
| 301 | Note that this function only changes state if you call | - | ||||||||||||
| 302 | waitForFinished() or if an external D-Bus event happens, which in | - | ||||||||||||
| 303 | general only happens if you return to the event loop execution. | - | ||||||||||||
| 304 | - | |||||||||||||
| 305 | \sa QDBusPendingReply::isFinished() | - | ||||||||||||
| 306 | */ | - | ||||||||||||
| 307 | /*! | - | ||||||||||||
| 308 | \fn bool QDBusPendingReply::isFinished() const | - | ||||||||||||
| 309 | - | |||||||||||||
| 310 | Returns \c true if the pending call has finished processing and the | - | ||||||||||||
| 311 | reply has been received. If this function returns \c true, the | - | ||||||||||||
| 312 | isError(), error() and reply() methods should return valid | - | ||||||||||||
| 313 | information. | - | ||||||||||||
| 314 | - | |||||||||||||
| 315 | Note that this function only changes state if you call | - | ||||||||||||
| 316 | waitForFinished() or if an external D-Bus event happens, which in | - | ||||||||||||
| 317 | general only happens if you return to the event loop execution. | - | ||||||||||||
| 318 | - | |||||||||||||
| 319 | \sa QDBusPendingCallWatcher::isFinished() | - | ||||||||||||
| 320 | */ | - | ||||||||||||
| 321 | - | |||||||||||||
| 322 | bool QDBusPendingCall::isFinished() const | - | ||||||||||||
| 323 | { | - | ||||||||||||
| 324 | if (!d)
| 2-66 | ||||||||||||
| 325 | return true; // considered finished executed 2 times by 1 test: return true;Executed by:
| 2 | ||||||||||||
| 326 | - | |||||||||||||
| 327 | QMutexLocker locker(&d->mutex); | - | ||||||||||||
| 328 | return d->replyMessage.type() != QDBusMessage::InvalidMessage; executed 66 times by 6 tests: return d->replyMessage.type() != QDBusMessage::InvalidMessage;Executed by:
| 66 | ||||||||||||
| 329 | } | - | ||||||||||||
| 330 | - | |||||||||||||
| 331 | void QDBusPendingCall::waitForFinished() | - | ||||||||||||
| 332 | { | - | ||||||||||||
| 333 | if (d) d->waitForFinished(); executed 111 times by 22 tests: d->waitForFinished();Executed by:
| 4-111 | ||||||||||||
| 334 | } executed 115 times by 23 tests: end of blockExecuted by:
| 115 | ||||||||||||
| 335 | - | |||||||||||||
| 336 | /*! | - | ||||||||||||
| 337 | \fn bool QDBusPendingReply::isValid() const | - | ||||||||||||
| 338 | - | |||||||||||||
| 339 | Returns \c true if the reply contains a normal reply message, false | - | ||||||||||||
| 340 | if it contains anything else. | - | ||||||||||||
| 341 | - | |||||||||||||
| 342 | If the pending call has not finished processing, this function | - | ||||||||||||
| 343 | return false. | - | ||||||||||||
| 344 | */ | - | ||||||||||||
| 345 | bool QDBusPendingCall::isValid() const | - | ||||||||||||
| 346 | { | - | ||||||||||||
| 347 | if (!d)
| 4-12 | ||||||||||||
| 348 | return false; executed 4 times by 1 test: return false;Executed by:
| 4 | ||||||||||||
| 349 | QMutexLocker locker(&d->mutex); | - | ||||||||||||
| 350 | return d->replyMessage.type() == QDBusMessage::ReplyMessage; executed 12 times by 3 tests: return d->replyMessage.type() == QDBusMessage::ReplyMessage;Executed by:
| 12 | ||||||||||||
| 351 | } | - | ||||||||||||
| 352 | - | |||||||||||||
| 353 | /*! | - | ||||||||||||
| 354 | \fn bool QDBusPendingReply::isError() const | - | ||||||||||||
| 355 | - | |||||||||||||
| 356 | Returns \c true if the reply contains an error message, false if it | - | ||||||||||||
| 357 | contains a normal method reply. | - | ||||||||||||
| 358 | - | |||||||||||||
| 359 | If the pending call has not finished processing, this function | - | ||||||||||||
| 360 | also returns \c true. | - | ||||||||||||
| 361 | */ | - | ||||||||||||
| 362 | bool QDBusPendingCall::isError() const | - | ||||||||||||
| 363 | { | - | ||||||||||||
| 364 | if (!d)
| 4-208 | ||||||||||||
| 365 | return true; // considered finished and an error executed 4 times by 1 test: return true;Executed by:
| 4 | ||||||||||||
| 366 | QMutexLocker locker(&d->mutex); | - | ||||||||||||
| 367 | return d->replyMessage.type() == QDBusMessage::ErrorMessage; executed 208 times by 22 tests: return d->replyMessage.type() == QDBusMessage::ErrorMessage;Executed by:
| 208 | ||||||||||||
| 368 | } | - | ||||||||||||
| 369 | - | |||||||||||||
| 370 | /*! | - | ||||||||||||
| 371 | \fn QDBusError QDBusPendingReply::error() const | - | ||||||||||||
| 372 | - | |||||||||||||
| 373 | Retrieves the error content of the reply message, if it has | - | ||||||||||||
| 374 | finished processing. If the reply message has not finished | - | ||||||||||||
| 375 | processing or if it contains a normal reply message (non-error), | - | ||||||||||||
| 376 | this function returns an invalid QDBusError. | - | ||||||||||||
| 377 | */ | - | ||||||||||||
| 378 | QDBusError QDBusPendingCall::error() const | - | ||||||||||||
| 379 | { | - | ||||||||||||
| 380 | if (d) {
| 2-33 | ||||||||||||
| 381 | QMutexLocker locker(&d->mutex); | - | ||||||||||||
| 382 | return QDBusError(d->replyMessage); executed 33 times by 6 tests: return QDBusError(d->replyMessage);Executed by:
| 33 | ||||||||||||
| 383 | } | - | ||||||||||||
| 384 | - | |||||||||||||
| 385 | // not connected, return an error | - | ||||||||||||
| 386 | QDBusError err = QDBusError(QDBusError::Disconnected, | - | ||||||||||||
| 387 | QDBusUtil::disconnectedErrorMessage()); | - | ||||||||||||
| 388 | return err; executed 2 times by 1 test: return err;Executed by:
| 2 | ||||||||||||
| 389 | } | - | ||||||||||||
| 390 | - | |||||||||||||
| 391 | /*! | - | ||||||||||||
| 392 | \fn QDBusMessage QDBusPendingReply::reply() const | - | ||||||||||||
| 393 | - | |||||||||||||
| 394 | Retrieves the reply message received for the asynchronous call | - | ||||||||||||
| 395 | that was sent, if it has finished processing. If the pending call | - | ||||||||||||
| 396 | is not finished, this function returns a QDBusMessage of type | - | ||||||||||||
| 397 | QDBusMessage::InvalidMessage. | - | ||||||||||||
| 398 | - | |||||||||||||
| 399 | After it has finished processing, the message type will either be | - | ||||||||||||
| 400 | an error message or a normal method reply message. | - | ||||||||||||
| 401 | */ | - | ||||||||||||
| 402 | QDBusMessage QDBusPendingCall::reply() const | - | ||||||||||||
| 403 | { | - | ||||||||||||
| 404 | if (!d)
| 2-40 | ||||||||||||
| 405 | return QDBusMessage::createError(error()); executed 2 times by 1 test: return QDBusMessage::createError(error());Executed by:
| 2 | ||||||||||||
| 406 | QMutexLocker locker(&d->mutex); | - | ||||||||||||
| 407 | return d->replyMessage; executed 40 times by 6 tests: return d->replyMessage;Executed by:
| 40 | ||||||||||||
| 408 | } | - | ||||||||||||
| 409 | - | |||||||||||||
| 410 | #if 0 | - | ||||||||||||
| 411 | /*! | - | ||||||||||||
| 412 | Sets the slot \a member in object \a target to be called when the | - | ||||||||||||
| 413 | reply arrives. The slot's parameter list must match the reply | - | ||||||||||||
| 414 | message's arguments for it to be called. | - | ||||||||||||
| 415 | - | |||||||||||||
| 416 | It may, optionally, contain a QDBusMessage final parameter. If it | - | ||||||||||||
| 417 | is present, the parameter will contain the reply message object. | - | ||||||||||||
| 418 | - | |||||||||||||
| 419 | The callback will not be called if the reply is an error message. | - | ||||||||||||
| 420 | - | |||||||||||||
| 421 | This function returns \c true if it could set the callback, false | - | ||||||||||||
| 422 | otherwise. It is not a guarantee that the callback will be | - | ||||||||||||
| 423 | called. | - | ||||||||||||
| 424 | - | |||||||||||||
| 425 | \warning QDBusPendingCall only supports one callback per pending | - | ||||||||||||
| 426 | asynchronous call, even if multiple QDBusPendingCall | - | ||||||||||||
| 427 | objects are referencing the same pending call. | - | ||||||||||||
| 428 | */ | - | ||||||||||||
| 429 | bool QDBusPendingCall::setReplyCallback(QObject *target, const char *member) | - | ||||||||||||
| 430 | { | - | ||||||||||||
| 431 | if (!d) | - | ||||||||||||
| 432 | return false; | - | ||||||||||||
| 433 | - | |||||||||||||
| 434 | return d->setReplyCallback(target, member); | - | ||||||||||||
| 435 | } | - | ||||||||||||
| 436 | #endif | - | ||||||||||||
| 437 | - | |||||||||||||
| 438 | /*! | - | ||||||||||||
| 439 | \since 4.6 | - | ||||||||||||
| 440 | Creates a QDBusPendingCall object based on the error condition | - | ||||||||||||
| 441 | \a error. The resulting pending call object will be in the | - | ||||||||||||
| 442 | "finished" state and QDBusPendingReply::isError() will return true. | - | ||||||||||||
| 443 | - | |||||||||||||
| 444 | \sa fromCompletedCall() | - | ||||||||||||
| 445 | */ | - | ||||||||||||
| 446 | QDBusPendingCall QDBusPendingCall::fromError(const QDBusError &error) | - | ||||||||||||
| 447 | { | - | ||||||||||||
| 448 | return fromCompletedCall(QDBusMessage::createError(error)); executed 14 times by 1 test: return fromCompletedCall(QDBusMessage::createError(error));Executed by:
| 14 | ||||||||||||
| 449 | } | - | ||||||||||||
| 450 | - | |||||||||||||
| 451 | /*! | - | ||||||||||||
| 452 | \since 4.6 | - | ||||||||||||
| 453 | Creates a QDBusPendingCall object based on the message \a msg. | - | ||||||||||||
| 454 | The message must be of type QDBusMessage::ErrorMessage or | - | ||||||||||||
| 455 | QDBusMessage::ReplyMessage (that is, a message that is typical | - | ||||||||||||
| 456 | of a completed call). | - | ||||||||||||
| 457 | - | |||||||||||||
| 458 | This function is useful for code that requires simulating a pending | - | ||||||||||||
| 459 | call, but that has already finished. | - | ||||||||||||
| 460 | - | |||||||||||||
| 461 | \sa fromError() | - | ||||||||||||
| 462 | */ | - | ||||||||||||
| 463 | QDBusPendingCall QDBusPendingCall::fromCompletedCall(const QDBusMessage &msg) | - | ||||||||||||
| 464 | { | - | ||||||||||||
| 465 | QDBusPendingCallPrivate *d = 0; | - | ||||||||||||
| 466 | if (msg.type() == QDBusMessage::ErrorMessage ||
| 0-14 | ||||||||||||
| 467 | msg.type() == QDBusMessage::ReplyMessage) {
| 0 | ||||||||||||
| 468 | d = new QDBusPendingCallPrivate(QDBusMessage(), 0); | - | ||||||||||||
| 469 | d->replyMessage = msg; | - | ||||||||||||
| 470 | d->ref.store(1); | - | ||||||||||||
| 471 | } executed 14 times by 1 test: end of blockExecuted by:
| 14 | ||||||||||||
| 472 | - | |||||||||||||
| 473 | return QDBusPendingCall(d); executed 14 times by 1 test: return QDBusPendingCall(d);Executed by:
| 14 | ||||||||||||
| 474 | } | - | ||||||||||||
| 475 | - | |||||||||||||
| 476 | - | |||||||||||||
| 477 | class QDBusPendingCallWatcherPrivate: public QObjectPrivate | - | ||||||||||||
| 478 | { | - | ||||||||||||
| 479 | public: | - | ||||||||||||
| 480 | void _q_finished(); | - | ||||||||||||
| 481 | - | |||||||||||||
| 482 | Q_DECLARE_PUBLIC(QDBusPendingCallWatcher) | - | ||||||||||||
| 483 | }; | - | ||||||||||||
| 484 | - | |||||||||||||
| 485 | inline void QDBusPendingCallWatcherPrivate::_q_finished() | - | ||||||||||||
| 486 | { | - | ||||||||||||
| 487 | Q_Q(QDBusPendingCallWatcher); | - | ||||||||||||
| 488 | emit q->finished(q); | - | ||||||||||||
| 489 | } executed 9 times by 2 tests: end of blockExecuted by:
| 9 | ||||||||||||
| 490 | - | |||||||||||||
| 491 | /*! | - | ||||||||||||
| 492 | Creates a QDBusPendingCallWatcher object to watch for replies on the | - | ||||||||||||
| 493 | asynchronous pending call \a call and sets this object's parent | - | ||||||||||||
| 494 | to \a parent. | - | ||||||||||||
| 495 | */ | - | ||||||||||||
| 496 | QDBusPendingCallWatcher::QDBusPendingCallWatcher(const QDBusPendingCall &call, QObject *parent) | - | ||||||||||||
| 497 | : QObject(*new QDBusPendingCallWatcherPrivate, parent), QDBusPendingCall(call) | - | ||||||||||||
| 498 | { | - | ||||||||||||
| 499 | if (d) { // QDBusPendingCall::d
| 0-45 | ||||||||||||
| 500 | QMutexLocker locker(&d->mutex); | - | ||||||||||||
| 501 | if (!d->watcherHelper) {
| 0-45 | ||||||||||||
| 502 | d->watcherHelper = new QDBusPendingCallWatcherHelper; | - | ||||||||||||
| 503 | if (d->replyMessage.type() != QDBusMessage::InvalidMessage) {
| 5-40 | ||||||||||||
| 504 | // cause a signal emission anyways | - | ||||||||||||
| 505 | QMetaObject::invokeMethod(d->watcherHelper, "finished", Qt::QueuedConnection); | - | ||||||||||||
| 506 | } executed 5 times by 2 tests: end of blockExecuted by:
| 5 | ||||||||||||
| 507 | } executed 45 times by 18 tests: end of blockExecuted by:
| 45 | ||||||||||||
| 508 | d->watcherHelper->add(this); | - | ||||||||||||
| 509 | } executed 45 times by 18 tests: end of blockExecuted by:
| 45 | ||||||||||||
| 510 | } executed 45 times by 18 tests: end of blockExecuted by:
| 45 | ||||||||||||
| 511 | - | |||||||||||||
| 512 | /*! | - | ||||||||||||
| 513 | Destroys this object. If this QDBusPendingCallWatcher object was the | - | ||||||||||||
| 514 | last reference to the unfinished pending call, the call will be | - | ||||||||||||
| 515 | canceled. | - | ||||||||||||
| 516 | */ | - | ||||||||||||
| 517 | QDBusPendingCallWatcher::~QDBusPendingCallWatcher() | - | ||||||||||||
| 518 | { | - | ||||||||||||
| 519 | } | - | ||||||||||||
| 520 | - | |||||||||||||
| 521 | /*! | - | ||||||||||||
| 522 | \fn void QDBusPendingCallWatcher::waitForFinished() | - | ||||||||||||
| 523 | - | |||||||||||||
| 524 | Suspends the execution of the calling thread until the reply is | - | ||||||||||||
| 525 | received and processed. After this function returns, isFinished() | - | ||||||||||||
| 526 | should return true, indicating the reply's contents are ready to | - | ||||||||||||
| 527 | be processed. | - | ||||||||||||
| 528 | - | |||||||||||||
| 529 | \sa QDBusPendingReply::waitForFinished() | - | ||||||||||||
| 530 | */ | - | ||||||||||||
| 531 | void QDBusPendingCallWatcher::waitForFinished() | - | ||||||||||||
| 532 | { | - | ||||||||||||
| 533 | if (d) {
| 0-5 | ||||||||||||
| 534 | d->waitForFinished(); | - | ||||||||||||
| 535 | - | |||||||||||||
| 536 | // our signals were queued, so deliver them | - | ||||||||||||
| 537 | QCoreApplication::sendPostedEvents(d->watcherHelper, QEvent::MetaCall); | - | ||||||||||||
| 538 | QCoreApplication::sendPostedEvents(this, QEvent::MetaCall); | - | ||||||||||||
| 539 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||
| 540 | } executed 5 times by 1 test: end of blockExecuted by:
| 5 | ||||||||||||
| 541 | QT_END_NAMESPACE | - | ||||||||||||
| 542 | - | |||||||||||||
| 543 | #endif // QT_NO_DBUS | - | ||||||||||||
| 544 | - | |||||||||||||
| 545 | #include "moc_qdbuspendingcall.cpp" | - | ||||||||||||
| Source code | Switch to Preprocessed file |