qdbusreply.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/dbus/qdbusreply.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 "qdbusreply.h"-
35#include "qdbusmetatype.h"-
36#include "qdbusmetatype_p.h"-
37#include <QDebug>-
38-
39#ifndef QT_NO_DBUS-
40-
41QT_BEGIN_NAMESPACE-
42-
43/*!-
44 \class QDBusReply-
45 \inmodule QtDBus-
46 \since 4.2-
47-
48 \brief The QDBusReply class stores the reply for a method call to a remote object.-
49-
50 A QDBusReply object is a subset of the QDBusMessage object that represents a method call's-
51 reply. It contains only the first output argument or the error code and is used by-
52 QDBusInterface-derived classes to allow returning the error code as the function's return-
53 argument.-
54-
55 It can be used in the following manner:-
56 \snippet code/src_qdbus_qdbusreply.cpp 0-
57-
58 If the remote method call cannot fail, you can skip the error checking:-
59 \snippet code/src_qdbus_qdbusreply.cpp 1-
60-
61 However, if it does fail under those conditions, the value returned by QDBusReply::value() is-
62 a default-constructed value. It may be indistinguishable from a valid return value.-
63-
64 QDBusReply objects are used for remote calls that have no output-
65 arguments or return values (i.e., they have a "void" return-
66 type). Use the isValid() function to test if the reply succeeded.-
67-
68 \sa QDBusMessage, QDBusInterface-
69*/-
70-
71/*!-
72 \fn QDBusReply::QDBusReply(const QDBusMessage &reply)-
73 Automatically construct a QDBusReply object from the reply message \a reply, extracting the-
74 first return value from it if it is a success reply.-
75*/-
76-
77/*!-
78 \fn QDBusReply::QDBusReply(const QDBusPendingReply<T> &reply)-
79 Constructs a QDBusReply object from the pending reply message, \a reply.-
80*/-
81-
82/*!-
83 \fn QDBusReply::QDBusReply(const QDBusPendingCall &pcall)-
84 Automatically construct a QDBusReply object from the asynchronous-
85 pending call \a pcall. If the call isn't finished yet, QDBusReply-
86 will call QDBusPendingCall::waitForFinished(), which is a blocking-
87 operation.-
88-
89 If the return types patch, QDBusReply will extract the first-
90 return argument from the reply.-
91*/-
92-
93/*!-
94 \fn QDBusReply::QDBusReply(const QDBusError &error)-
95 Constructs an error reply from the D-Bus error code given by \a error.-
96*/-
97-
98/*!-
99 \fn QDBusReply::operator=(const QDBusReply &other)-
100 Makes this object be a copy of the object \a other.-
101*/-
102-
103/*!-
104 \fn QDBusReply::operator=(const QDBusError &error)-
105 Sets this object to contain the error code given by \a error. You-
106 can later access it with error().-
107*/-
108-
109/*!-
110 \fn QDBusReply::operator=(const QDBusMessage &message)-
111-
112 Makes this object contain the reply specified by message \a-
113 message. If \a message is an error message, this function will-
114 copy the error code and message into this object-
115-
116 If \a message is a standard reply message and contains at least-
117 one parameter, it will be copied into this object, as long as it-
118 is of the correct type. If it's not of the same type as this-
119 QDBusError object, this function will instead set an error code-
120 indicating a type mismatch.-
121*/-
122-
123/*!-
124 \fn QDBusReply::operator=(const QDBusPendingCall &pcall)-
125-
126 Makes this object contain the reply specified by the pending-
127 asynchronous call \a pcall. If the call is not finished yet, this-
128 function will call QDBusPendingCall::waitForFinished() to block-
129 until the reply arrives.-
130-
131 If \a pcall finishes with an error message, this function will-
132 copy the error code and message into this object-
133-
134 If \a pcall finished with a standard reply message and contains at-
135 least one parameter, it will be copied into this object, as long-
136 as it is of the correct type. If it's not of the same type as this-
137 QDBusError object, this function will instead set an error code-
138 indicating a type mismatch.-
139*/-
140-
141/*!-
142 \fn bool QDBusReply::isValid() const-
143-
144 Returns \c true if no error occurred; otherwise, returns \c false.-
145-
146 \sa error()-
147*/-
148-
149/*!-
150 \fn const QDBusError& QDBusReply::error() const-
151-
152 Returns the error code that was returned from the remote function call. If the remote call did-
153 not return an error (i.e., if it succeeded), then the QDBusError object that is returned will-
154 not be a valid error code (QDBusError::isValid() will return false).-
155-
156 \sa isValid()-
157*/-
158-
159/*!-
160 \fn const QDBusError& QDBusReply::error()-
161 \overload-
162*/-
163-
164/*!-
165 \fn QDBusReply::value() const-
166 Returns the remote function's calls return value. If the remote call returned with an error,-
167 the return value of this function is undefined and may be undistinguishable from a valid return-
168 value.-
169-
170 This function is not available if the remote call returns \c void.-
171*/-
172-
173/*!-
174 \fn QDBusReply::operator Type() const-
175 Returns the same as value().-
176-
177 This function is not available if the remote call returns \c void.-
178*/-
179-
180/*!-
181 \internal-
182 Fills in the QDBusReply data \a error and \a data from the reply message \a reply.-
183*/-
184void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data)-
185{-
186 error = QDBusError(reply);-
187-
188 if (error.isValid()) {
error.isValid()Description
TRUEevaluated 17 times by 3 tests
Evaluated by:
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbusabstractinterface - unknown status
  • tst_qdbusreply - unknown status
FALSEevaluated 348 times by 154 tests
Evaluated by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QDataWidgetMapper
  • tst_QDateTimeEdit
  • tst_QDesktopWidget
  • ...
17-348
189 data = QVariant(); // clear it-
190 return;
executed 17 times by 3 tests: return;
Executed by:
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbusabstractinterface - unknown status
  • tst_qdbusreply - unknown status
17
191 }-
192-
193 if (reply.arguments().count() >= 1 && reply.arguments().at(0).userType() == data.userType()) {
reply.arguments().count() >= 1Description
TRUEevaluated 348 times by 154 tests
Evaluated by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QDataWidgetMapper
  • tst_QDateTimeEdit
  • tst_QDesktopWidget
  • ...
FALSEnever evaluated
reply.argument...ata.userType()Description
TRUEevaluated 320 times by 154 tests
Evaluated by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QDataWidgetMapper
  • tst_QDateTimeEdit
  • tst_QDesktopWidget
  • ...
FALSEevaluated 28 times by 3 tests
Evaluated by:
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbusabstractinterface - unknown status
  • tst_qdbusreply - unknown status
0-348
194 data = reply.arguments().at(0);-
195 return;
executed 320 times by 154 tests: return;
Executed by:
  • tst_Gestures
  • tst_ModelTest
  • tst_NetworkSelfTest
  • tst_QAbstractButton
  • tst_QAbstractItemView
  • tst_QAbstractNetworkCache
  • tst_QAbstractScrollArea
  • tst_QAbstractSlider
  • tst_QAbstractSpinBox
  • tst_QAccessibility
  • tst_QAction
  • tst_QActionGroup
  • tst_QApplication
  • tst_QBackingStore
  • tst_QBoxLayout
  • tst_QButtonGroup
  • tst_QCalendarWidget
  • tst_QCheckBox
  • tst_QColorDialog
  • tst_QColumnView
  • tst_QComboBox
  • tst_QCommandLinkButton
  • tst_QDataWidgetMapper
  • tst_QDateTimeEdit
  • tst_QDesktopWidget
  • ...
320
196 }-
197-
198 const char *expectedSignature = QDBusMetaType::typeToSignature(data.userType());-
199 const char *receivedType = 0;-
200 QByteArray receivedSignature;-
201-
202 if (reply.arguments().count() >= 1) {
reply.arguments().count() >= 1Description
TRUEevaluated 28 times by 3 tests
Evaluated by:
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbusabstractinterface - unknown status
  • tst_qdbusreply - unknown status
FALSEnever evaluated
0-28
203 if (reply.arguments().at(0).userType() == QDBusMetaTypeId::argument()) {
reply.argument...Id::argument()Description
TRUEevaluated 20 times by 3 tests
Evaluated by:
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbusabstractinterface - unknown status
  • tst_qdbusreply - unknown status
FALSEevaluated 8 times by 1 test
Evaluated by:
  • tst_qdbusreply - unknown status
8-20
204 // compare signatures instead-
205 QDBusArgument arg = qvariant_cast<QDBusArgument>(reply.arguments().at(0));-
206 receivedSignature = arg.currentSignature().toLatin1();-
207 if (receivedSignature == expectedSignature) {
receivedSignat...ectedSignatureDescription
TRUEevaluated 17 times by 3 tests
Evaluated by:
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbusabstractinterface - unknown status
  • tst_qdbusreply - unknown status
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_qdbusreply - unknown status
3-17
208 // matched. Demarshall it-
209 QDBusMetaType::demarshall(arg, data.userType(), data.data());-
210 return;
executed 17 times by 3 tests: return;
Executed by:
  • tst_qdbusabstractadaptor - unknown status
  • tst_qdbusabstractinterface - unknown status
  • tst_qdbusreply - unknown status
17
211 }-
212 } else {
executed 3 times by 1 test: end of block
Executed by:
  • tst_qdbusreply - unknown status
3
213 // not an argument and doesn't match?-
214 int type = reply.arguments().at(0).userType();-
215 receivedType = QMetaType::typeName(type);-
216 receivedSignature = QDBusMetaType::typeToSignature(type);-
217 }
executed 8 times by 1 test: end of block
Executed by:
  • tst_qdbusreply - unknown status
8
218 }-
219-
220 // error-
221 if (receivedSignature.isEmpty())
receivedSignature.isEmpty()Description
TRUEnever evaluated
FALSEevaluated 11 times by 1 test
Evaluated by:
  • tst_qdbusreply - unknown status
0-11
222 receivedSignature = "<empty signature>";
never executed: receivedSignature = "<empty signature>";
0
223 QString errorMsg;-
224 if (receivedType) {
receivedTypeDescription
TRUEevaluated 8 times by 1 test
Evaluated by:
  • tst_qdbusreply - unknown status
FALSEevaluated 3 times by 1 test
Evaluated by:
  • tst_qdbusreply - unknown status
3-8
225 errorMsg = QString::fromLatin1("Unexpected reply signature: got \"%1\" (%4), "-
226 "expected \"%2\" (%3)")-
227 .arg(QLatin1String(receivedSignature),-
228 QLatin1String(expectedSignature),-
229 QLatin1String(data.typeName()),-
230 QLatin1String(receivedType));-
231 } else {
executed 8 times by 1 test: end of block
Executed by:
  • tst_qdbusreply - unknown status
8
232 errorMsg = QString::fromLatin1("Unexpected reply signature: got \"%1\", "-
233 "expected \"%2\" (%3)")-
234 .arg(QLatin1String(receivedSignature),-
235 QLatin1String(expectedSignature),-
236 QLatin1String(data.typeName()));-
237 }
executed 3 times by 1 test: end of block
Executed by:
  • tst_qdbusreply - unknown status
3
238-
239 error = QDBusError(QDBusError::InvalidSignature, errorMsg);-
240 data = QVariant(); // clear it-
241}
executed 11 times by 1 test: end of block
Executed by:
  • tst_qdbusreply - unknown status
11
242-
243QT_END_NAMESPACE-
244-
245#endif // QT_NO_DBUS-
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9