| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbuspendingreply.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtDBus module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
| 29 | ** | - | ||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||
| 31 | ** | - | ||||||
| 32 | ****************************************************************************/ | - | ||||||
| 33 | - | |||||||
| 34 | #include "qdbuspendingreply.h" | - | ||||||
| 35 | #include "qdbuspendingcall_p.h" | - | ||||||
| 36 | #include "qdbusmetatype.h" | - | ||||||
| 37 | - | |||||||
| 38 | #ifndef QT_NO_DBUS | - | ||||||
| 39 | - | |||||||
| 40 | /*! | - | ||||||
| 41 | \class QDBusPendingReply | - | ||||||
| 42 | \inmodule QtDBus | - | ||||||
| 43 | \since 4.5 | - | ||||||
| 44 | - | |||||||
| 45 | \brief The QDBusPendingReply class contains the reply to an asynchronous method call | - | ||||||
| 46 | - | |||||||
| 47 | The QDBusPendingReply is a template class with up to 8 template | - | ||||||
| 48 | parameters. Those parameters are the types that will be used to | - | ||||||
| 49 | extract the contents of the reply's data. | - | ||||||
| 50 | - | |||||||
| 51 | This class is similar in functionality to QDBusReply, but with two | - | ||||||
| 52 | important differences: | - | ||||||
| 53 | - | |||||||
| 54 | \list | - | ||||||
| 55 | \li QDBusReply accepts exactly one return type, whereas | - | ||||||
| 56 | QDBusPendingReply can have from 1 to 8 types | - | ||||||
| 57 | \li QDBusReply only works on already completed replies, whereas | - | ||||||
| 58 | QDBusPendingReply allows one to wait for replies from pending | - | ||||||
| 59 | calls | - | ||||||
| 60 | \endlist | - | ||||||
| 61 | - | |||||||
| 62 | Where with QDBusReply you would write: | - | ||||||
| 63 | - | |||||||
| 64 | \snippet code/src_qdbus_qdbusreply.cpp 0 | - | ||||||
| 65 | - | |||||||
| 66 | with QDBusPendingReply, the equivalent code (including the blocking | - | ||||||
| 67 | wait for the reply) would be: | - | ||||||
| 68 | - | |||||||
| 69 | \snippet code/src_qdbus_qdbuspendingreply.cpp 0 | - | ||||||
| 70 | - | |||||||
| 71 | For method calls that have more than one output argument, with | - | ||||||
| 72 | QDBusReply, you would write: | - | ||||||
| 73 | - | |||||||
| 74 | \snippet code/src_qdbus_qdbusreply.cpp 1 | - | ||||||
| 75 | - | |||||||
| 76 | whereas with QDBusPendingReply, all of the output arguments should | - | ||||||
| 77 | be template parameters: | - | ||||||
| 78 | - | |||||||
| 79 | \snippet code/src_qdbus_qdbuspendingreply.cpp 2 | - | ||||||
| 80 | - | |||||||
| 81 | QDBusPendingReply objects can be associated with | - | ||||||
| 82 | QDBusPendingCallWatcher objects, which emit signals when the reply | - | ||||||
| 83 | arrives. | - | ||||||
| 84 | - | |||||||
| 85 | \sa QDBusPendingCallWatcher, QDBusReply, | - | ||||||
| 86 | QDBusAbstractInterface::asyncCall() | - | ||||||
| 87 | */ | - | ||||||
| 88 | - | |||||||
| 89 | /*! | - | ||||||
| 90 | \fn QDBusPendingReply::QDBusPendingReply() | - | ||||||
| 91 | - | |||||||
| 92 | Creates an empty QDBusPendingReply object. Without assigning a | - | ||||||
| 93 | QDBusPendingCall object to this reply, QDBusPendingReply cannot do | - | ||||||
| 94 | anything. All functions return their failure values. | - | ||||||
| 95 | */ | - | ||||||
| 96 | - | |||||||
| 97 | /*! | - | ||||||
| 98 | \fn QDBusPendingReply::QDBusPendingReply(const QDBusPendingReply &other) | - | ||||||
| 99 | - | |||||||
| 100 | Creates a copy of the \a other QDBusPendingReply object. Just like | - | ||||||
| 101 | QDBusPendingCall and QDBusPendingCallWatcher, this QDBusPendingReply | - | ||||||
| 102 | object will share the same pending call reference. All copies | - | ||||||
| 103 | share the same return values. | - | ||||||
| 104 | */ | - | ||||||
| 105 | - | |||||||
| 106 | /*! | - | ||||||
| 107 | \fn QDBusPendingReply::QDBusPendingReply(const QDBusPendingCall &call) | - | ||||||
| 108 | - | |||||||
| 109 | Creates a QDBusPendingReply object that will take its contents from | - | ||||||
| 110 | the \a call pending asynchronous call. This QDBusPendingReply object | - | ||||||
| 111 | will share the same pending call reference as \a call. | - | ||||||
| 112 | */ | - | ||||||
| 113 | - | |||||||
| 114 | /*! | - | ||||||
| 115 | \fn QDBusPendingReply::QDBusPendingReply(const QDBusMessage &message) | - | ||||||
| 116 | - | |||||||
| 117 | Creates a QDBusPendingReply object that will take its contents from | - | ||||||
| 118 | the message \a message. In this case, this object will be already | - | ||||||
| 119 | in its finished state and the reply's contents will be accessible. | - | ||||||
| 120 | - | |||||||
| 121 | \sa isFinished() | - | ||||||
| 122 | */ | - | ||||||
| 123 | - | |||||||
| 124 | /*! | - | ||||||
| 125 | \fn QDBusPendingReply &QDBusPendingReply::operator=(const QDBusPendingReply &other) | - | ||||||
| 126 | - | |||||||
| 127 | Makes a copy of \a other and drops the reference to the current | - | ||||||
| 128 | pending call. If the current reference is to an unfinished pending | - | ||||||
| 129 | call and this is the last reference, the pending call will be | - | ||||||
| 130 | canceled and there will be no way of retrieving the reply's | - | ||||||
| 131 | contents, when they arrive. | - | ||||||
| 132 | */ | - | ||||||
| 133 | - | |||||||
| 134 | /*! | - | ||||||
| 135 | \fn QDBusPendingReply &QDBusPendingReply::operator=(const QDBusPendingCall &call) | - | ||||||
| 136 | - | |||||||
| 137 | Makes this object take its contents from the \a call pending call | - | ||||||
| 138 | and drops the reference to the current pending call. If the | - | ||||||
| 139 | current reference is to an unfinished pending call and this is the | - | ||||||
| 140 | last reference, the pending call will be canceled and there will | - | ||||||
| 141 | be no way of retrieving the reply's contents, when they arrive. | - | ||||||
| 142 | */ | - | ||||||
| 143 | - | |||||||
| 144 | /*! | - | ||||||
| 145 | \fn QDBusPendingReply &QDBusPendingReply::operator=(const QDBusMessage &message) | - | ||||||
| 146 | - | |||||||
| 147 | Makes this object take its contents from the \a message message | - | ||||||
| 148 | and drops the reference to the current pending call. If the | - | ||||||
| 149 | current reference is to an unfinished pending call and this is the | - | ||||||
| 150 | last reference, the pending call will be canceled and there will | - | ||||||
| 151 | be no way of retrieving the reply's contents, when they arrive. | - | ||||||
| 152 | - | |||||||
| 153 | After this function is finished, the QDBusPendingReply object will | - | ||||||
| 154 | be in its "finished" state and the \a message contents will be | - | ||||||
| 155 | accessible. | - | ||||||
| 156 | - | |||||||
| 157 | \sa isFinished() | - | ||||||
| 158 | */ | - | ||||||
| 159 | - | |||||||
| 160 | /*! | - | ||||||
| 161 | \fn int QDBusPendingReply::count() const | - | ||||||
| 162 | - | |||||||
| 163 | Return the number of arguments the reply is supposed to have. This | - | ||||||
| 164 | number matches the number of non-void template parameters in this | - | ||||||
| 165 | class. | - | ||||||
| 166 | - | |||||||
| 167 | If the reply arrives with a different number of arguments (or with | - | ||||||
| 168 | different types), it will be transformed into an error reply | - | ||||||
| 169 | indicating a bad signature. | - | ||||||
| 170 | */ | - | ||||||
| 171 | - | |||||||
| 172 | /*! | - | ||||||
| 173 | \fn QVariant QDBusPendingReply::argumentAt(int index) const | - | ||||||
| 174 | - | |||||||
| 175 | Returns the argument at position \a index in the reply's | - | ||||||
| 176 | contents. If the reply doesn't have that many elements, this | - | ||||||
| 177 | function's return value is undefined (will probably cause an | - | ||||||
| 178 | assertion failure), so it is important to verify that the | - | ||||||
| 179 | processing is finished and the reply is valid. | - | ||||||
| 180 | - | |||||||
| 181 | If the reply does not contain an argument at position \a index or if the | - | ||||||
| 182 | reply was an error, this function returns an invalid QVariant. Since D-Bus | - | ||||||
| 183 | messages can never contain invalid QVariants, this return can be used to | - | ||||||
| 184 | detect an error condition. | - | ||||||
| 185 | */ | - | ||||||
| 186 | - | |||||||
| 187 | /*! | - | ||||||
| 188 | \fn Type QDBusPendingReply::argumentAt() const | - | ||||||
| 189 | - | |||||||
| 190 | Returns the argument at position \c Index (which is a template | - | ||||||
| 191 | parameter) cast to type \c Type. This function uses template code | - | ||||||
| 192 | to determine the proper \c Type type, according to the type list | - | ||||||
| 193 | used in the construction of this object. | - | ||||||
| 194 | - | |||||||
| 195 | Note that, if the reply hasn't arrived, this function causes the | - | ||||||
| 196 | calling thread to block until the reply is processed. | - | ||||||
| 197 | - | |||||||
| 198 | If the reply does not contain an argument at position \c Index or if the | - | ||||||
| 199 | reply was an error, this function returns a \c Type object that is default | - | ||||||
| 200 | constructed, which may be indistinguishable from a valid value. To reliably | - | ||||||
| 201 | determine whether the message was an error, use isError(). | - | ||||||
| 202 | */ | - | ||||||
| 203 | - | |||||||
| 204 | /*! | - | ||||||
| 205 | \fn T1 QDBusPendingReply::value() const | - | ||||||
| 206 | - | |||||||
| 207 | Returns the first argument in this reply, cast to type \c T1 (the | - | ||||||
| 208 | first template parameter of this class). This is equivalent to | - | ||||||
| 209 | calling argumentAt<0>(). | - | ||||||
| 210 | - | |||||||
| 211 | This function is provided as a convenience, matching the | - | ||||||
| 212 | QDBusReply::value() function. | - | ||||||
| 213 | - | |||||||
| 214 | Note that, if the reply hasn't arrived, this function causes the | - | ||||||
| 215 | calling thread to block until the reply is processed. | - | ||||||
| 216 | - | |||||||
| 217 | If the reply is an error reply, this function returns a default-constructed | - | ||||||
| 218 | \c T1 object, which may be indistinguishable from a valid value. To | - | ||||||
| 219 | reliably determine whether the message was an error, use isError(). | - | ||||||
| 220 | */ | - | ||||||
| 221 | - | |||||||
| 222 | /*! | - | ||||||
| 223 | \fn QDBusPendingReply::operator T1() const | - | ||||||
| 224 | - | |||||||
| 225 | Returns the first argument in this reply, cast to type \c T1 (the | - | ||||||
| 226 | first template parameter of this class). This is equivalent to | - | ||||||
| 227 | calling argumentAt<0>(). | - | ||||||
| 228 | - | |||||||
| 229 | This function is provided as a convenience, matching the | - | ||||||
| 230 | QDBusReply::value() function. | - | ||||||
| 231 | - | |||||||
| 232 | Note that, if the reply hasn't arrived, this function causes the | - | ||||||
| 233 | calling thread to block until the reply is processed. | - | ||||||
| 234 | - | |||||||
| 235 | If the reply is an error reply, this function returns a default-constructed | - | ||||||
| 236 | \c T1 object, which may be indistinguishable from a valid value. To | - | ||||||
| 237 | reliably determine whether the message was an error, use isError(). | - | ||||||
| 238 | */ | - | ||||||
| 239 | - | |||||||
| 240 | /*! | - | ||||||
| 241 | \fn void QDBusPendingReply::waitForFinished() | - | ||||||
| 242 | - | |||||||
| 243 | Suspends the execution of the calling thread until the reply is | - | ||||||
| 244 | received and processed. After this function returns, isFinished() | - | ||||||
| 245 | should return true, indicating the reply's contents are ready to | - | ||||||
| 246 | be processed. | - | ||||||
| 247 | - | |||||||
| 248 | \sa QDBusPendingCallWatcher::waitForFinished() | - | ||||||
| 249 | */ | - | ||||||
| 250 | - | |||||||
| 251 | QDBusPendingReplyData::QDBusPendingReplyData() | - | ||||||
| 252 | : QDBusPendingCall(0) // initialize base class empty | - | ||||||
| 253 | { | - | ||||||
| 254 | } executed 274 times by 18 tests: end of blockExecuted by:
| 274 | ||||||
| 255 | - | |||||||
| 256 | QDBusPendingReplyData::~QDBusPendingReplyData() | - | ||||||
| 257 | { | - | ||||||
| 258 | } | - | ||||||
| 259 | - | |||||||
| 260 | void QDBusPendingReplyData::assign(const QDBusPendingCall &other) | - | ||||||
| 261 | { | - | ||||||
| 262 | QDBusPendingCall::operator=(other); | - | ||||||
| 263 | } executed 103 times by 18 tests: end of blockExecuted by:
| 103 | ||||||
| 264 | - | |||||||
| 265 | void QDBusPendingReplyData::assign(const QDBusMessage &message) | - | ||||||
| 266 | { | - | ||||||
| 267 | d = new QDBusPendingCallPrivate(QDBusMessage(), 0); // drops the reference to the old one | - | ||||||
| 268 | d->replyMessage = message; | - | ||||||
| 269 | } executed 177 times by 17 tests: end of blockExecuted by:
| 177 | ||||||
| 270 | - | |||||||
| 271 | QVariant QDBusPendingReplyData::argumentAt(int index) const | - | ||||||
| 272 | { | - | ||||||
| 273 | if (!d)
| 0-211 | ||||||
| 274 | return QVariant(); never executed: return QVariant(); | 0 | ||||||
| 275 | - | |||||||
| 276 | d->waitForFinished(); // bypasses "const" | - | ||||||
| 277 | - | |||||||
| 278 | return d->replyMessage.arguments().value(index); executed 211 times by 18 tests: return d->replyMessage.arguments().value(index);Executed by:
| 211 | ||||||
| 279 | } | - | ||||||
| 280 | - | |||||||
| 281 | void QDBusPendingReplyData::setMetaTypes(int count, const int *types) | - | ||||||
| 282 | { | - | ||||||
| 283 | Q_ASSERT(d); | - | ||||||
| 284 | QMutexLocker locker(&d->mutex); | - | ||||||
| 285 | d->setMetaTypes(count, types); | - | ||||||
| 286 | d->checkReceivedSignature(); | - | ||||||
| 287 | } executed 278 times by 18 tests: end of blockExecuted by:
| 278 | ||||||
| 288 | - | |||||||
| 289 | #endif // QT_NO_DBUS | - | ||||||
| Source code | Switch to Preprocessed file |