author | Eckhart Koeppen <eckhart.koppen@nokia.com> |
Thu, 29 Apr 2010 15:15:16 +0300 | |
branch | RCL_3 |
changeset 16 | 4b6ee5efea19 |
parent 4 | 3b1da2848fc7 |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
4
3b1da2848fc7
Revision: 201003
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 |
||
56 |
QT_BEGIN_HEADER |
|
57 |
||
58 |
QT_BEGIN_NAMESPACE |
|
59 |
||
60 |
QT_MODULE(DBus) |
|
61 |
||
62 |
class QDBusArgumentPrivate; |
|
63 |
class QDBusDemarshaller; |
|
64 |
class QDBusMarshaller; |
|
65 |
class QDBUS_EXPORT QDBusArgument |
|
66 |
{ |
|
67 |
public: |
|
68 |
enum ElementType { |
|
69 |
BasicType, |
|
70 |
VariantType, |
|
71 |
ArrayType, |
|
72 |
StructureType, |
|
73 |
MapType, |
|
74 |
MapEntryType, |
|
75 |
UnknownType = -1 |
|
76 |
}; |
|
77 |
||
78 |
QDBusArgument(); |
|
79 |
QDBusArgument(const QDBusArgument &other); |
|
80 |
QDBusArgument &operator=(const QDBusArgument &other); |
|
81 |
~QDBusArgument(); |
|
82 |
||
83 |
// used for marshalling (Qt -> D-BUS) |
|
84 |
QDBusArgument &operator<<(uchar arg); |
|
85 |
QDBusArgument &operator<<(bool arg); |
|
86 |
QDBusArgument &operator<<(short arg); |
|
87 |
QDBusArgument &operator<<(ushort arg); |
|
88 |
QDBusArgument &operator<<(int arg); |
|
89 |
QDBusArgument &operator<<(uint arg); |
|
90 |
QDBusArgument &operator<<(qlonglong arg); |
|
91 |
QDBusArgument &operator<<(qulonglong arg); |
|
92 |
QDBusArgument &operator<<(double arg); |
|
93 |
QDBusArgument &operator<<(const QString &arg); |
|
94 |
QDBusArgument &operator<<(const QDBusVariant &arg); |
|
95 |
QDBusArgument &operator<<(const QDBusObjectPath &arg); |
|
96 |
QDBusArgument &operator<<(const QDBusSignature &arg); |
|
97 |
QDBusArgument &operator<<(const QStringList &arg); |
|
98 |
QDBusArgument &operator<<(const QByteArray &arg); |
|
99 |
||
100 |
void beginStructure(); |
|
101 |
void endStructure(); |
|
102 |
void beginArray(int elementMetaTypeId); |
|
103 |
void endArray(); |
|
104 |
void beginMap(int keyMetaTypeId, int valueMetaTypeId); |
|
105 |
void endMap(); |
|
106 |
void beginMapEntry(); |
|
107 |
void endMapEntry(); |
|
108 |
||
109 |
void appendVariant(const QVariant &v); |
|
110 |
||
111 |
// used for de-marshalling (D-BUS -> Qt) |
|
112 |
QString currentSignature() const; |
|
113 |
ElementType currentType() const; |
|
114 |
||
115 |
const QDBusArgument &operator>>(uchar &arg) const; |
|
116 |
const QDBusArgument &operator>>(bool &arg) const; |
|
117 |
const QDBusArgument &operator>>(short &arg) const; |
|
118 |
const QDBusArgument &operator>>(ushort &arg) const; |
|
119 |
const QDBusArgument &operator>>(int &arg) const; |
|
120 |
const QDBusArgument &operator>>(uint &arg) const; |
|
121 |
const QDBusArgument &operator>>(qlonglong &arg) const; |
|
122 |
const QDBusArgument &operator>>(qulonglong &arg) const; |
|
123 |
const QDBusArgument &operator>>(double &arg) const; |
|
124 |
const QDBusArgument &operator>>(QString &arg) const; |
|
125 |
const QDBusArgument &operator>>(QDBusVariant &arg) const; |
|
126 |
const QDBusArgument &operator>>(QDBusObjectPath &arg) const; |
|
127 |
const QDBusArgument &operator>>(QDBusSignature &arg) const; |
|
128 |
const QDBusArgument &operator>>(QStringList &arg) const; |
|
129 |
const QDBusArgument &operator>>(QByteArray &arg) const; |
|
130 |
||
131 |
void beginStructure() const; |
|
132 |
void endStructure() const; |
|
133 |
void beginArray() const; |
|
134 |
void endArray() const; |
|
135 |
void beginMap() const; |
|
136 |
void endMap() const; |
|
137 |
void beginMapEntry() const; |
|
138 |
void endMapEntry() const; |
|
139 |
bool atEnd() const; |
|
140 |
||
141 |
QVariant asVariant() const; |
|
142 |
||
143 |
protected: |
|
144 |
QDBusArgument(QDBusArgumentPrivate *d); |
|
145 |
friend class QDBusArgumentPrivate; |
|
146 |
mutable QDBusArgumentPrivate *d; |
|
147 |
}; |
|
148 |
||
149 |
template<typename T> inline T qdbus_cast(const QDBusArgument &arg |
|
150 |
#ifndef Q_QDOC |
|
151 |
, T * = 0 |
|
152 |
#endif |
|
153 |
) |
|
154 |
{ |
|
155 |
T item; |
|
156 |
arg >> item; |
|
157 |
return item; |
|
158 |
} |
|
159 |
||
160 |
template<typename T> inline T qdbus_cast(const QVariant &v |
|
161 |
#ifndef Q_QDOC |
|
162 |
, T * = 0 |
|
163 |
#endif |
|
164 |
) |
|
165 |
{ |
|
166 |
int id = v.userType(); |
|
167 |
if (id == qMetaTypeId<QDBusArgument>()) |
|
168 |
return qdbus_cast<T>(qvariant_cast<QDBusArgument>(v)); |
|
169 |
else |
|
170 |
return qvariant_cast<T>(v); |
|
171 |
} |
|
172 |
||
173 |
// specialise for QVariant, allowing it to be used in place of QDBusVariant |
|
174 |
template<> inline QVariant qdbus_cast<QVariant>(const QDBusArgument &arg, QVariant *) |
|
175 |
{ |
|
176 |
QDBusVariant item; |
|
177 |
arg >> item; |
|
178 |
return item.variant(); |
|
179 |
} |
|
180 |
template<> inline QVariant qdbus_cast<QVariant>(const QVariant &v, QVariant *) |
|
181 |
{ |
|
182 |
return qdbus_cast<QDBusVariant>(v).variant(); |
|
183 |
} |
|
184 |
||
185 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QVariant &v); |
|
186 |
||
187 |
// QVariant types |
|
188 |
#ifndef QDBUS_NO_SPECIALTYPES |
|
189 |
||
190 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QDate &date); |
|
191 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QDate &date); |
|
192 |
||
193 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QTime &time); |
|
194 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QTime &time); |
|
195 |
||
196 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QDateTime &dt); |
|
197 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QDateTime &dt); |
|
198 |
||
199 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QRect &rect); |
|
200 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QRect &rect); |
|
201 |
||
202 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QRectF &rect); |
|
203 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QRectF &rect); |
|
204 |
||
205 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QSize &size); |
|
206 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QSize &size); |
|
207 |
||
208 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QSizeF &size); |
|
209 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QSizeF &size); |
|
210 |
||
211 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QPoint &pt); |
|
212 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QPoint &pt); |
|
213 |
||
214 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QPointF &pt); |
|
215 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QPointF &pt); |
|
216 |
||
217 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QLine &line); |
|
218 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QLine &line); |
|
219 |
||
220 |
QDBUS_EXPORT const QDBusArgument &operator>>(const QDBusArgument &a, QLineF &line); |
|
221 |
QDBUS_EXPORT QDBusArgument &operator<<(QDBusArgument &a, const QLineF &line); |
|
222 |
#endif |
|
223 |
||
224 |
template<template <typename> class Container, typename T> |
|
225 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const Container<T> &list) |
|
226 |
{ |
|
227 |
int id = qMetaTypeId<T>(); |
|
228 |
arg.beginArray(id); |
|
229 |
typename Container<T>::const_iterator it = list.begin(); |
|
230 |
typename Container<T>::const_iterator end = list.end(); |
|
231 |
for ( ; it != end; ++it) |
|
232 |
arg << *it; |
|
233 |
arg.endArray(); |
|
234 |
return arg; |
|
235 |
} |
|
236 |
||
237 |
template<template <typename> class Container, typename T> |
|
238 |
inline const QDBusArgument &operator>>(const QDBusArgument &arg, Container<T> &list) |
|
239 |
{ |
|
240 |
arg.beginArray(); |
|
241 |
list.clear(); |
|
242 |
while (!arg.atEnd()) { |
|
243 |
T item; |
|
244 |
arg >> item; |
|
245 |
list.push_back(item); |
|
246 |
} |
|
247 |
||
248 |
arg.endArray(); |
|
249 |
return arg; |
|
250 |
} |
|
251 |
||
252 |
// QList specializations |
|
253 |
template<typename T> |
|
254 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QList<T> &list) |
|
255 |
{ |
|
256 |
int id = qMetaTypeId<T>(); |
|
257 |
arg.beginArray(id); |
|
258 |
typename QList<T>::ConstIterator it = list.constBegin(); |
|
259 |
typename QList<T>::ConstIterator end = list.constEnd(); |
|
260 |
for ( ; it != end; ++it) |
|
261 |
arg << *it; |
|
262 |
arg.endArray(); |
|
263 |
return arg; |
|
264 |
} |
|
265 |
||
266 |
template<typename T> |
|
267 |
inline const QDBusArgument &operator>>(const QDBusArgument &arg, QList<T> &list) |
|
268 |
{ |
|
269 |
arg.beginArray(); |
|
270 |
list.clear(); |
|
271 |
while (!arg.atEnd()) { |
|
272 |
T item; |
|
273 |
arg >> item; |
|
274 |
list.push_back(item); |
|
275 |
} |
|
276 |
arg.endArray(); |
|
277 |
||
278 |
return arg; |
|
279 |
} |
|
280 |
||
281 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantList &list) |
|
282 |
{ |
|
283 |
int id = qMetaTypeId<QDBusVariant>(); |
|
284 |
arg.beginArray(id); |
|
285 |
QVariantList::ConstIterator it = list.constBegin(); |
|
286 |
QVariantList::ConstIterator end = list.constEnd(); |
|
287 |
for ( ; it != end; ++it) |
|
288 |
arg << QDBusVariant(*it); |
|
289 |
arg.endArray(); |
|
290 |
return arg; |
|
291 |
} |
|
292 |
||
293 |
// QMap specializations |
|
294 |
template<typename Key, typename T> |
|
295 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QMap<Key, T> &map) |
|
296 |
{ |
|
297 |
int kid = qMetaTypeId<Key>(); |
|
298 |
int vid = qMetaTypeId<T>(); |
|
299 |
arg.beginMap(kid, vid); |
|
300 |
typename QMap<Key, T>::ConstIterator it = map.constBegin(); |
|
301 |
typename QMap<Key, T>::ConstIterator end = map.constEnd(); |
|
302 |
for ( ; it != end; ++it) { |
|
303 |
arg.beginMapEntry(); |
|
304 |
arg << it.key() << it.value(); |
|
305 |
arg.endMapEntry(); |
|
306 |
} |
|
307 |
arg.endMap(); |
|
308 |
return arg; |
|
309 |
} |
|
310 |
||
311 |
template<typename Key, typename T> |
|
312 |
inline const QDBusArgument &operator>>(const QDBusArgument &arg, QMap<Key, T> &map) |
|
313 |
{ |
|
314 |
arg.beginMap(); |
|
315 |
map.clear(); |
|
316 |
while (!arg.atEnd()) { |
|
317 |
Key key; |
|
318 |
T value; |
|
319 |
arg.beginMapEntry(); |
|
320 |
arg >> key >> value; |
|
321 |
map.insertMulti(key, value); |
|
322 |
arg.endMapEntry(); |
|
323 |
} |
|
324 |
arg.endMap(); |
|
325 |
return arg; |
|
326 |
} |
|
327 |
||
328 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QVariantMap &map) |
|
329 |
{ |
|
330 |
arg.beginMap(QVariant::String, qMetaTypeId<QDBusVariant>()); |
|
331 |
QVariantMap::ConstIterator it = map.constBegin(); |
|
332 |
QVariantMap::ConstIterator end = map.constEnd(); |
|
333 |
for ( ; it != end; ++it) { |
|
334 |
arg.beginMapEntry(); |
|
335 |
arg << it.key() << QDBusVariant(it.value()); |
|
336 |
arg.endMapEntry(); |
|
337 |
} |
|
338 |
arg.endMap(); |
|
339 |
return arg; |
|
340 |
} |
|
341 |
||
342 |
// QHash specializations |
|
343 |
template<typename Key, typename T> |
|
344 |
inline QDBusArgument &operator<<(QDBusArgument &arg, const QHash<Key, T> &map) |
|
345 |
{ |
|
346 |
int kid = qMetaTypeId<Key>(); |
|
347 |
int vid = qMetaTypeId<T>(); |
|
348 |
arg.beginMap(kid, vid); |
|
349 |
typename QHash<Key, T>::ConstIterator it = map.constBegin(); |
|
350 |
typename QHash<Key, T>::ConstIterator end = map.constEnd(); |
|
351 |
for ( ; it != end; ++it) { |
|
352 |
arg.beginMapEntry(); |
|
353 |
arg << it.key() << it.value(); |
|
354 |
arg.endMapEntry(); |
|
355 |
} |
|
356 |
arg.endMap(); |
|
357 |
return arg; |
|
358 |
} |
|
359 |
||
360 |
template<typename Key, typename T> |
|
361 |
inline const QDBusArgument &operator>>(const QDBusArgument &arg, QHash<Key, T> &map) |
|
362 |
{ |
|
363 |
arg.beginMap(); |
|
364 |
map.clear(); |
|
365 |
while (!arg.atEnd()) { |
|
366 |
Key key; |
|
367 |
T value; |
|
368 |
arg.beginMapEntry(); |
|
369 |
arg >> key >> value; |
|
370 |
map.insertMulti(key, value); |
|
371 |
arg.endMapEntry(); |
|
372 |
} |
|
373 |
arg.endMap(); |
|
374 |
return arg; |
|
375 |
} |
|
376 |
||
377 |
QT_END_NAMESPACE |
|
378 |
||
379 |
Q_DECLARE_METATYPE(QDBusArgument) |
|
380 |
||
381 |
QT_END_HEADER |
|
382 |
||
383 |
#endif |