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