1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the QtDBus module of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Lesser General Public License Usage
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
---|
18 | ** General Public License version 2.1 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
---|
20 | ** packaging of this file. Please review the following information to
|
---|
21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
---|
22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
---|
23 | **
|
---|
24 | ** In addition, as a special exception, Nokia gives you certain additional
|
---|
25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
---|
26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
---|
27 | **
|
---|
28 | ** GNU General Public License Usage
|
---|
29 | ** Alternatively, this file may be used under the terms of the GNU
|
---|
30 | ** General Public License version 3.0 as published by the Free Software
|
---|
31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
32 | ** packaging of this file. Please review the following information to
|
---|
33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
---|
34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
---|
35 | **
|
---|
36 | ** If you have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at [email protected].
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #include "qdbusargument_p.h"
|
---|
43 | #include <stdlib.h>
|
---|
44 |
|
---|
45 | QT_BEGIN_NAMESPACE
|
---|
46 |
|
---|
47 | template <typename T>
|
---|
48 | static inline T qIterGet(DBusMessageIter *it)
|
---|
49 | {
|
---|
50 | T t;
|
---|
51 | q_dbus_message_iter_get_basic(it, &t);
|
---|
52 | q_dbus_message_iter_next(it);
|
---|
53 | return t;
|
---|
54 | }
|
---|
55 |
|
---|
56 | QDBusDemarshaller::~QDBusDemarshaller()
|
---|
57 | {
|
---|
58 | }
|
---|
59 |
|
---|
60 | inline QString QDBusDemarshaller::currentSignature()
|
---|
61 | {
|
---|
62 | char *sig = q_dbus_message_iter_get_signature(&iterator);
|
---|
63 | QString retval = QString::fromUtf8(sig);
|
---|
64 | q_dbus_free(sig);
|
---|
65 |
|
---|
66 | return retval;
|
---|
67 | }
|
---|
68 |
|
---|
69 | inline uchar QDBusDemarshaller::toByte()
|
---|
70 | {
|
---|
71 | return qIterGet<uchar>(&iterator);
|
---|
72 | }
|
---|
73 |
|
---|
74 | inline bool QDBusDemarshaller::toBool()
|
---|
75 | {
|
---|
76 | return bool(qIterGet<dbus_bool_t>(&iterator));
|
---|
77 | }
|
---|
78 |
|
---|
79 | inline ushort QDBusDemarshaller::toUShort()
|
---|
80 | {
|
---|
81 | return qIterGet<dbus_uint16_t>(&iterator);
|
---|
82 | }
|
---|
83 |
|
---|
84 | inline short QDBusDemarshaller::toShort()
|
---|
85 | {
|
---|
86 | return qIterGet<dbus_int16_t>(&iterator);
|
---|
87 | }
|
---|
88 |
|
---|
89 | inline int QDBusDemarshaller::toInt()
|
---|
90 | {
|
---|
91 | return qIterGet<dbus_int32_t>(&iterator);
|
---|
92 | }
|
---|
93 |
|
---|
94 | inline uint QDBusDemarshaller::toUInt()
|
---|
95 | {
|
---|
96 | return qIterGet<dbus_uint32_t>(&iterator);
|
---|
97 | }
|
---|
98 |
|
---|
99 | inline qlonglong QDBusDemarshaller::toLongLong()
|
---|
100 | {
|
---|
101 | return qIterGet<qlonglong>(&iterator);
|
---|
102 | }
|
---|
103 |
|
---|
104 | inline qulonglong QDBusDemarshaller::toULongLong()
|
---|
105 | {
|
---|
106 | return qIterGet<qulonglong>(&iterator);
|
---|
107 | }
|
---|
108 |
|
---|
109 | inline double QDBusDemarshaller::toDouble()
|
---|
110 | {
|
---|
111 | return qIterGet<double>(&iterator);
|
---|
112 | }
|
---|
113 |
|
---|
114 | inline QString QDBusDemarshaller::toString()
|
---|
115 | {
|
---|
116 | return QString::fromUtf8(qIterGet<char *>(&iterator));
|
---|
117 | }
|
---|
118 |
|
---|
119 | inline QDBusObjectPath QDBusDemarshaller::toObjectPath()
|
---|
120 | {
|
---|
121 | return QDBusObjectPath(QString::fromUtf8(qIterGet<char *>(&iterator)));
|
---|
122 | }
|
---|
123 |
|
---|
124 | inline QDBusSignature QDBusDemarshaller::toSignature()
|
---|
125 | {
|
---|
126 | return QDBusSignature(QString::fromUtf8(qIterGet<char *>(&iterator)));
|
---|
127 | }
|
---|
128 |
|
---|
129 | inline QDBusVariant QDBusDemarshaller::toVariant()
|
---|
130 | {
|
---|
131 | QDBusDemarshaller sub;
|
---|
132 | sub.message = q_dbus_message_ref(message);
|
---|
133 | q_dbus_message_iter_recurse(&iterator, &sub.iterator);
|
---|
134 | q_dbus_message_iter_next(&iterator);
|
---|
135 |
|
---|
136 | return QDBusVariant( sub.toVariantInternal() );
|
---|
137 | }
|
---|
138 |
|
---|
139 | QDBusArgument::ElementType QDBusDemarshaller::currentType()
|
---|
140 | {
|
---|
141 | switch (q_dbus_message_iter_get_arg_type(&iterator)) {
|
---|
142 | case DBUS_TYPE_BYTE:
|
---|
143 | case DBUS_TYPE_INT16:
|
---|
144 | case DBUS_TYPE_UINT16:
|
---|
145 | case DBUS_TYPE_INT32:
|
---|
146 | case DBUS_TYPE_UINT32:
|
---|
147 | case DBUS_TYPE_INT64:
|
---|
148 | case DBUS_TYPE_UINT64:
|
---|
149 | case DBUS_TYPE_BOOLEAN:
|
---|
150 | case DBUS_TYPE_DOUBLE:
|
---|
151 | case DBUS_TYPE_STRING:
|
---|
152 | case DBUS_TYPE_OBJECT_PATH:
|
---|
153 | case DBUS_TYPE_SIGNATURE:
|
---|
154 | return QDBusArgument::BasicType;
|
---|
155 |
|
---|
156 | case DBUS_TYPE_VARIANT:
|
---|
157 | return QDBusArgument::VariantType;
|
---|
158 |
|
---|
159 | case DBUS_TYPE_ARRAY:
|
---|
160 | switch (q_dbus_message_iter_get_element_type(&iterator)) {
|
---|
161 | case DBUS_TYPE_BYTE:
|
---|
162 | case DBUS_TYPE_STRING:
|
---|
163 | // QByteArray and QStringList
|
---|
164 | return QDBusArgument::BasicType;
|
---|
165 | case DBUS_TYPE_DICT_ENTRY:
|
---|
166 | return QDBusArgument::MapType;
|
---|
167 | default:
|
---|
168 | return QDBusArgument::ArrayType;
|
---|
169 | }
|
---|
170 |
|
---|
|
---|