Qt 4.8
qdbusreply.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 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 "qdbusreply.h"
43 #include "qdbusmetatype.h"
44 #include "qdbusmetatype_p.h"
45 #include <QDebug>
46 
47 #ifndef QT_NO_DBUS
48 
50 
230 {
231  error = reply;
232 
233  if (error.isValid()) {
234  data = QVariant(); // clear it
235  return;
236  }
237 
238  if (reply.arguments().count() >= 1 && reply.arguments().at(0).userType() == data.userType()) {
239  data = reply.arguments().at(0);
240  return;
241  }
242 
243  const char *expectedSignature = QDBusMetaType::typeToSignature(data.userType());
244  const char *receivedType = 0;
245  QByteArray receivedSignature;
246 
247  if (reply.arguments().count() >= 1) {
248  if (reply.arguments().at(0).userType() == QDBusMetaTypeId::argument) {
249  // compare signatures instead
251  receivedSignature = arg.currentSignature().toLatin1();
252  if (receivedSignature == expectedSignature) {
253  // matched. Demarshall it
254  QDBusMetaType::demarshall(arg, data.userType(), data.data());
255  return;
256  }
257  } else {
258  // not an argument and doesn't match?
259  int type = reply.arguments().at(0).userType();
260  receivedType = QVariant::typeToName(QVariant::Type(type));
261  receivedSignature = QDBusMetaType::typeToSignature(type);
262  }
263  }
264 
265  // error
266  if (receivedSignature.isEmpty())
267  receivedSignature = "no signature";
268  QString errorMsg;
269  if (receivedType) {
270  errorMsg = QString::fromLatin1("Unexpected reply signature: got \"%1\" (%4), "
271  "expected \"%2\" (%3)")
272  .arg(QLatin1String(receivedSignature),
273  QLatin1String(expectedSignature),
274  QLatin1String(data.typeName()),
275  QLatin1String(receivedType));
276  } else {
277  errorMsg = QString::fromLatin1("Unexpected reply signature: got \"%1\", "
278  "expected \"%2\" (%3)")
279  .arg(QLatin1String(receivedSignature),
280  QLatin1String(expectedSignature),
281  QLatin1String(data.typeName()));
282  }
283 
284  error = QDBusError(QDBusError::InvalidSignature, errorMsg);
285  data = QVariant(); // clear it
286 }
287 
289 
290 #endif // QT_NO_DBUS
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92
int type
Definition: qmetatype.cpp:239
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool isValid() const
Returns true if this is a valid error condition (i.e., if there was an error), otherwise false...
Definition: qdbuserror.cpp:356
The QDBusArgument class is used to marshall and demarshall D-Bus arguments.
Definition: qdbusargument.h:69
#define error(msg)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QDBusError class represents an error received from the D-Bus bus or from remote applications foun...
Definition: qdbuserror.h:60
QString currentSignature() const
Returns the type signature of the D-Bus type this QDBusArgument object is currently pointing to...
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const char * typeToName(Type type)
Converts the enum representation of the storage type, typ, to its string representation.
Definition: qvariant.cpp:2008
static const char * typeToSignature(int type)
Returns the D-Bus signature equivalent to the supplied meta type id type.
void * data()
Definition: qvariant.cpp:3077
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QList< QVariant > arguments() const
Returns the list of arguments that are going to be sent or were received from D-Bus.
static bool demarshall(const QDBusArgument &, int id, void *data)
Executes the demarshalling of type id (whose data will be placed in data) from the D-Bus marshalling ...
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
static const char * data(const QByteArray &arr)
Type
This enum type defines the types of variable that a QVariant can contain.
Definition: qvariant.h:95
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * typeName() const
Returns the name of the type stored in the variant.
Definition: qvariant.cpp:1984
void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data)
Fills in the QDBusReply data error and data from the reply message reply.
Definition: qdbusreply.cpp:229
QString arg(qlonglong a, int fieldwidth=0, int base=10, const QChar &fillChar=QLatin1Char(' ')) const Q_REQUIRED_RESULT
Definition: qstring.cpp:7186
int userType() const
Returns the storage type of the value stored in the variant.
Definition: qvariant.cpp:1913
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
The QDBusMessage class represents one message sent or received over the D-Bus bus.
Definition: qdbusmessage.h:59
bool isEmpty() const
Returns true if the byte array has size 0; otherwise returns false.
Definition: qbytearray.h:421
static int argument
T qvariant_cast(const QVariant &value)
Returns the given value converted to the template type T.
Definition: qvariant.h:571