author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Wed, 18 Aug 2010 10:37:55 +0300 | |
changeset 33 | 3e2da88830cd |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the QtDBus module of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
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 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
#ifndef QDBUSARGUMENT_H |
|
43 |
#define QDBUSARGUMENT_H |
|
44 |
||
45 |
#include <QtCore/qbytearray.h> |
|
46 |
#include <QtCore/qhash.h> |
|
47 |
#include <QtCore/qglobal.h> |
|
48 |
#include <QtCore/qlist.h> |
|
49 |
#include <QtCore/qmap.h> |
|
50 |
#include <QtCore/qstring.h> |
|
51 |
#include <QtCore/qstringlist.h> |
|
52 |
#include <QtCore/qvariant.h> |
|
53 |
#include <QtDBus/qdbusextratypes.h> |
|
54 |
#include <QtDBus/qdbusmacros.h> |
|
55 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
56 |
#ifndef QT_NO_DBUS |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
57 |
|
0 | 58 |
QT_BEGIN_HEADER |
59 |
||
60 |
QT_BEGIN_NAMESPACE |
|
61 |
||
62 |
QT_MODULE(DBus) |
|
63 |
||
64 |
class QDBusArgumentPrivate; |
|
65 |
class QDBusDemarshaller; |
|
66 |
class QDBusMarshaller; |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
67 |
class Q_DBUS_EXPORT QDBusArgument |
0 | 68 |
{ |
69 |
public: |
|
70 |
enum ElementType { |
|
71 |
BasicType, |
|
72 |
VariantType, |
|
73 |
ArrayType, |
|
74 |
StructureType, |
|
75 |
MapType, |
|
76 |
MapEntryType, |
|
77 |
UnknownType = -1 |
|
78 |
}; |
|
79 |
||
80 |
QDBusArgument(); |
|
81 |
QDBusArgument(const QDBusArgument &other); |
|
82 |
QDBusArgument &operator=(const QDBusArgument &other); |
|
83 |
~QDBusArgument(); |
|
84 |
||
85 |
// used for marshalling (Qt -> D-BUS) |
|
86 |
QDBusArgument &operator<<(uchar arg); |
|
87 |
QDBusArgument &operator<<(bool arg); |
|
88 |
QDBusArgument &operator<<(short arg); |
|
89 |
QDBusArgument &operator<<(ushort arg); |
|
90 |
QDBusArgument &operator<<(int arg); |
|
91 |
QDBusArgument &operator<<(uint arg); |
|
92 |
QDBusArgument &operator<<(qlonglong arg); |
|
93 |
QDBusArgument &operator<<(qulonglong arg); |
|
94 |
QDBusArgument &operator<<(double arg); |
|
95 |
QDBusArgument &operator<<(const QString &arg); |
|
96 |
QDBusArgument &operator<<(const QDBusVariant &arg); |
|
97 |
QDBusArgument &operator<<(const QDBusObjectPath &arg); |
|
98 |
QDBusArgument &operator<<(const QDBusSignature &arg); |
|
99 |
QDBusArgument &operator<<(const QStringList &arg); |
|
100 |
QDBusArgument &operator<<(const QByteArray &arg); |
|
101 |
||
102 |
void beginStructure(); |
|
103 |
void endStructure(); |
|
104 |
void beginArray(int elementMetaTypeId); |
|
105 |
void endArray(); |
|
106 |
void beginMap(int keyMetaTypeId, int valueMetaTypeId); |
|
107 |
void endMap(); |
|
108 |
void beginMapEntry(); |
|
109 |
void endMapEntry(); |
|
110 |
||
111 |
void appendVariant(const QVariant &v); |
|
112 |
||
113 |
// used for de-marshalling (D-BUS -> Qt) |
|
114 |
QString currentSignature() const; |
|
115 |
ElementType currentType() const; |
|
116 |
||
117 |
const QDBusArgument &operator>>(uchar &arg) const; |
|
118 |
const QDBusArgument &operator>>(bool &arg) const; |
|
119 |
const QDBusArgument &operator>>(short &arg) const; |
|
120 |
const QDBusArgument &operator>>(ushort &arg) const; |
|
121 |
const QDBusArgument &operator>>(int &arg) const; |
|
122 |
const QDBusArgument &operator>>(uint &arg) const; |
|
123 |
const QDBusArgument &operator>>(qlonglong &arg) const; |
|
124 |
const QDBusArgument &operator>>(qulonglong &arg) const; |
|
125 |
const QDBusArgument &operator>>(double &arg) const; |
|
126 |
const QDBusArgument &operator>>(QString &arg) const; |
|
127 |
const QDBusArgument &operator>>(QDBusVariant &arg) const; |
|
128 |
const QDBusArgument &operator>>(QDBusObjectPath &arg) const; |
|
129 |
const QDBusArgument &operator>>(QDBusSignature &arg) const; |
|
130 |
const QDBusArgument &operator>>(QStringList &arg) const; |
|
131 |
const QDBusArgument &operator>>(QByteArray &arg) const; |
|
132 |
||
133 |
void beginStructure() const; |
|
134 |
void endStructure() const; |
|
135 |
void beginArray() const; |
|
136 |
void endArray() const; |
|
137 |
void beginMap() const; |
|
138 |
void endMap() const; |
|
139 |
void beginMapEntry() const; |
|
140 |
void endMapEntry() const; |
|
141 |
bool atEnd() const; |
|
142 |
||
143 |
QVariant asVariant() const; |
|
144 |
||
145 |
protected: |
|
146 |
QDBusArgument(QDBusArgumentPrivate *d); |
|
147 |
friend class QDBusArgumentPrivate; |
|
148 |
mutable QDBusArgumentPrivate *d; |
|
149 |
}; |
|
150 |
||
151 |
template<typename T> inline T qdbus_cast(const QDBusArgument &arg |
|
152 |
#ifndef Q_QDOC |
|
153 |
, T * = 0 |
|
154 |
#endif |
|
155 |
) |
|
156 |
{ |
|
157 |
T item; |
|
158 |
arg >> item; |
|
159 |
return item; |
|
160 |
} |
|
161 |
||
162 |
template<typename T> inline T qdbus_cast(const QVariant &v |
|
163 |
#ifndef Q_QDOC |
|
164 |
, T * = 0 |
|
165 |
#endif |
|
166 |
) |
|
167 |
{ |
|
168 |
int id = v.userType(); |
|
169 |
if (id == qMetaTypeId<QDBusArgument>()) |
|
170 |
return qdbus_cast<T>(qvariant_cast<QDBusArgument>(v)); |
|
171 |
else |
|
172 |
return qvariant_cast<T>(v); |
|
173 |
} |
|
174 |
||
175 |
// specialise for QVariant, allowing it to be used in place of QDBusVariant |
|
176 |
template<> inline QVariant qdbus_cast<QVariant>(const QDBusArgument &arg, QVariant *) |
|
177 |
{ |
|
178 |
QDBusVariant item; |
|
179 |
arg >> item; |
|
180 |
return item.variant(); |
|
181 |
} |
|
182 |
template<> inline QVariant qdbus_cast<QVariant>(const QVariant &v, QVariant *) |
|
183 |
{ |
|
184 |
return qdbus_cast<QDBusVariant>(v).variant(); |
|
185 |
} |
|
186 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
187 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QVariant &v); |
0 | 188 |
|
189 |
// QVariant types |
|
190 |
#ifndef QDBUS_NO_SPECIALTYPES |
|
191 |
||
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
192 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QDate &date); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
193 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QDate &date); |
0 | 194 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
195 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QTime &time); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
196 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QTime &time); |
0 | 197 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
198 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QDateTime &dt); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
199 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QDateTime &dt); |
0 | 200 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
201 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QRect &rect); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
202 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QRect &rect); |
0 | 203 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
204 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QRectF &rect); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
205 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QRectF &rect); |
0 | 206 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
207 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QSize &size); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
208 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QSize &size); |
0 | 209 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
210 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QSizeF &size); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
211 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QSizeF &size); |
0 | 212 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
213 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QPoint &pt); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
214 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QPoint &pt); |
0 | 215 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
216 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QPointF &pt); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
217 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QPointF &pt); |
0 | 218 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
219 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QLine &line); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
220 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QLine &line); |
0 | 221 |
|
33
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
222 |
Q_DBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QLineF &line); |
3e2da88830cd
Revision: 201031
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
223 |
Q_DBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QLineF &line); |
0 | 224 |
#endif |
225 |
||
226 |
template<template <typename> class Container, typename T> |
|
227 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<T> &list) |
|
228 |
{ |
|
229 |
int id = qMetaTypeId<T>(); |
|
230 |
arg.beginArray(id); |
|
231 |
typename Container<T>::const_iterator it = list.begin(); |
|
232 |
typename Container<T>::const_iterator end = list.end(); |
|
233 |
for ( ; it != end; ++it) |
|
234 |
arg << *it; |
|
235 |
arg.endArray(); |
|
236 |
return arg; |
|
237 |
} |
|
238 |
||
239 |
template<template <typename> class Container, typename T> |
|
240 |
inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<T> &list) |
|
241 |
{ |
|
242 |
arg.beginArray(); |
|
243 |
list.clear(); |
|
244 |
while (!arg.atEnd()) { |
|
245 |
T item; |
|
246 |
arg >> item; |
|
247 |
list.push_back(item); |
|
248 |
} |
|
249 |
||
250 |
arg.endArray(); |
|
251 |
return arg; |
|
252 |
} |
|
253 |
||
254 |
// QList specializations |
|
255 |
template<typename T> |
|
256 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QList<T> &list) |
|
257 |
{ |
|
258 |
int id = qMetaTypeId<T>(); |
|
259 |
arg.beginArray(id); |
|
260 |
typename QList<T>::ConstIterator it = list.constBegin(); |
|
261 |
typename QList<T>::ConstIterator end = list.constEnd(); |
|
262 |
for ( ; it != end; ++it) |
|
263 |
arg << *it; |
|
264 |
arg.endArray(); |
|
265 |
return arg; |
|
266 |
} |
|
267 |
||
268 |
template<typename T> |
|
269 |
inline const QDBusArgument &operator>>(const QDBusArgument &arg, QList<T> &list) |
|
270 |
{ |
|
271 |
arg.beginArray(); |
|
272 |
list.clear(); |
|
273 |
while (!arg.atEnd()) { |
|
274 |
T item; |
|
275 |
arg >> item; |
|
276 |
list.push_back(item); |
|
277 |
} |
|
278 |
arg.endArray(); |
|
279 |
||
280 |
return arg; |
|
281 |
} |
|
282 |
||
283 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantList &list) |
|
284 |
{ |
|
285 |
int id = qMetaTypeId<QDBusVariant>(); |
|
286 |
arg.beginArray(id); |
|
287 |
QVariantList::ConstIterator it = list.constBegin(); |
|
288 |
QVariantList::ConstIterator end = list.constEnd(); |
|
289 |
for ( ; it != end; ++it) |
|
290 |
arg << QDBusVariant(*it); |
|
291 |
arg.endArray(); |
|
292 |
return arg; |
|
293 |
} |
|
294 |
||
295 |
// QMap specializations |
|
296 |
template<typename Key, typename T> |
|
297 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QMap<Key, T> &map) |
|
298 |
{ |
|
299 |
int kid = qMetaTypeId<Key>(); |
|
300 |
int vid = qMetaTypeId<T>(); |
|
301 |
arg.beginMap(kid, vid); |
|
302 |
typename QMap<Key, T>::ConstIterator it = map.constBegin(); |
|
303 |
typename QMap<Key, T>::ConstIterator end = map.constEnd(); |
|
304 |
for ( ; it != end; ++it) { |
|
305 |
arg.beginMapEntry(); |
|
306 |
arg << it.key() << it.value(); |
|
307 |
arg.endMapEntry(); |
|
308 |
} |
|
309 |
arg.endMap(); |
|
310 |
return arg; |
|
311 |
} |
|
312 |
||
313 |
template<typename Key, typename T> |
|
314 |
inline const QDBusArgument &operator>>(const QDBusArgument &arg, QMap<Key, T> &map) |
|
315 |
{ |
|
316 |
arg.beginMap(); |
|
317 |
map.clear(); |
|
318 |
while (!arg.atEnd()) { |
|
319 |
Key key; |
|
320 |
T value; |
|
321 |
arg.beginMapEntry(); |
|
322 |
arg >> key >> value; |
|
323 |
map.insertMulti(key, value); |
|
324 |
arg.endMapEntry(); |
|
325 |
} |
|
326 |
arg.endMap(); |
|
327 |
return arg; |
|
328 |
} |
|
329 |
||
330 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map) |
|
331 |
{ |
|
332 |
arg.beginMap(QVariant::String, qMetaTypeId<QDBusVariant>()); |
|
333 |
QVariantMap::ConstIterator it = map.constBegin(); |
|
334 |
QVariantMap::ConstIterator end = map.constEnd(); |
|
335 |
for ( ; it != end; ++it) { |
|
336 |
arg.beginMapEntry(); |
|
337 |
arg << it.key() << QDBusVariant(it.value()); |
|
338 |
arg.endMapEntry(); |
|
339 |
} |
|
340 |
arg.endMap(); |
|
341 |
return arg; |
|
342 |
} |
|
343 |
||
344 |
// QHash specializations |
|
345 |
template<typename Key, typename T> |
|
346 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QHash<Key, T> &map) |
|
347 |
{ |
|
348 |
int kid = qMetaTypeId<Key>(); |
|
349 |
int vid = qMetaTypeId<T>(); |
|
350 |
arg.beginMap(kid, vid); |
|
351 |
typename QHash<Key, T>::ConstIterator it = map.constBegin(); |
|
352 |
typename QHash<Key, T>::ConstIterator end = map.constEnd(); |
|
353 |
for ( ; it != end; ++it) { |
|
354 |
arg.beginMapEntry(); |
|
355 |
arg << it.key() << it.value(); |
|
356 |
arg.endMapEntry(); |
|
357 |
} |
|
358 |
arg.endMap(); |
|
359 |
return arg; |
|
360 |
} |
|
361 |
||
362 |
template<typename Key, typename T> |
|
363 |
inline const QDBusArgument &operator>>(const QDBusArgument &arg, QHash<Key, T> &map) |
|
364 |
{ |
|
365 |
arg.beginMap(); |
|
366 |
map.clear(); |
|
367 |
while (!arg.atEnd()) { |
|
368 |
Key key; |
|
369 |
T value; |
|
370 |
arg.beginMapEntry(); |
|
371 |
arg >> key >> value; |
|
372 |
map.insertMulti(key, value); |
|
373 |
arg.endMapEntry(); |
|
374 |
} |
|
375 |
arg.endMap(); |
|
376 |
return arg; |
|
377 |
} |
|
378 |
||
379 |
QT_END_NAMESPACE |
|
380 |
||
381 |
Q_DECLARE_METATYPE(QDBusArgument) |
|
382 |
||
383 |
QT_END_HEADER |
|
384 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
385 |
#endif // QT_NO_DBUS |
0 | 386 |
#endif |