author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Fri, 16 Apr 2010 15:50:13 +0300 | |
changeset 18 | 2f34d5167611 |
parent 0 | 1918ee327afb |
child 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 QDBUSREPLY_H |
|
43 |
#define QDBUSREPLY_H |
|
44 |
||
45 |
#include <QtCore/qglobal.h> |
|
46 |
#include <QtCore/qvariant.h> |
|
47 |
||
48 |
#include <QtDBus/qdbusmacros.h> |
|
49 |
#include <QtDBus/qdbusmessage.h> |
|
50 |
#include <QtDBus/qdbuserror.h> |
|
51 |
#include <QtDBus/qdbusextratypes.h> |
|
52 |
#include <QtDBus/qdbuspendingreply.h> |
|
53 |
||
54 |
QT_BEGIN_HEADER |
|
55 |
||
56 |
QT_BEGIN_NAMESPACE |
|
57 |
||
58 |
QT_MODULE(DBus) |
|
59 |
||
60 |
QDBUS_EXPORT void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data); |
|
61 |
||
62 |
template<typename T> |
|
63 |
class QDBusReply |
|
64 |
{ |
|
65 |
typedef T Type; |
|
66 |
public: |
|
67 |
inline QDBusReply(const QDBusMessage &reply) |
|
68 |
{ |
|
69 |
*this = reply; |
|
70 |
} |
|
71 |
inline QDBusReply& operator=(const QDBusMessage &reply) |
|
72 |
{ |
|
73 |
QVariant data(qMetaTypeId(&m_data), reinterpret_cast<void*>(0)); |
|
74 |
qDBusReplyFill(reply, m_error, data); |
|
75 |
m_data = qvariant_cast<Type>(data); |
|
76 |
return *this; |
|
77 |
} |
|
78 |
||
79 |
inline QDBusReply(const QDBusPendingCall &pcall) |
|
80 |
{ |
|
81 |
*this = pcall; |
|
82 |
} |
|
83 |
inline QDBusReply &operator=(const QDBusPendingCall &pcall) |
|
84 |
{ |
|
85 |
QDBusPendingCall other(pcall); |
|
86 |
other.waitForFinished(); |
|
87 |
return *this = other.reply(); |
|
88 |
} |
|
89 |
inline QDBusReply(const QDBusPendingReply<T> &reply) |
|
90 |
{ |
|
91 |
*this = static_cast<QDBusPendingCall>(reply); |
|
92 |
} |
|
93 |
||
94 |
inline QDBusReply(const QDBusError &dbusError = QDBusError()) |
|
95 |
: m_error(dbusError), m_data(Type()) |
|
96 |
{ |
|
97 |
} |
|
98 |
inline QDBusReply& operator=(const QDBusError& dbusError) |
|
99 |
{ |
|
100 |
m_error = dbusError; |
|
101 |
m_data = Type(); |
|
102 |
return *this; |
|
103 |
} |
|
104 |
||
105 |
inline QDBusReply& operator=(const QDBusReply& other) |
|
106 |
{ |
|
107 |
m_error = other.m_error; |
|
108 |
m_data = other.m_data; |
|
109 |
return *this; |
|
110 |
} |
|
111 |
||
112 |
inline bool isValid() const { return !m_error.isValid(); } |
|
113 |
||
114 |
inline const QDBusError& error() { return m_error; } |
|
115 |
||
116 |
inline Type value() const |
|
117 |
{ |
|
118 |
return m_data; |
|
119 |
} |
|
120 |
||
121 |
inline operator Type () const |
|
122 |
{ |
|
123 |
return m_data; |
|
124 |
} |
|
125 |
||
126 |
private: |
|
127 |
QDBusError m_error; |
|
128 |
Type m_data; |
|
129 |
}; |
|
130 |
||
131 |
# ifndef Q_QDOC |
|
132 |
// specialize for QVariant: |
|
133 |
template<> inline QDBusReply<QVariant>& |
|
134 |
QDBusReply<QVariant>::operator=(const QDBusMessage &reply) |
|
135 |
{ |
|
136 |
void *null = 0; |
|
137 |
QVariant data(qMetaTypeId<QDBusVariant>(), null); |
|
138 |
qDBusReplyFill(reply, m_error, data); |
|
139 |
m_data = qvariant_cast<QDBusVariant>(data).variant(); |
|
140 |
return *this; |
|
141 |
} |
|
142 |
||
143 |
// specialize for void: |
|
144 |
template<> |
|
145 |
class QDBusReply<void> |
|
146 |
{ |
|
147 |
public: |
|
148 |
inline QDBusReply(const QDBusMessage &reply) |
|
149 |
: m_error(reply) |
|
150 |
{ |
|
151 |
} |
|
152 |
inline QDBusReply& operator=(const QDBusMessage &reply) |
|
153 |
{ |
|
154 |
m_error = reply; |
|
155 |
return *this; |
|
156 |
} |
|
157 |
inline QDBusReply(const QDBusError &dbusError = QDBusError()) |
|
158 |
: m_error(dbusError) |
|
159 |
{ |
|
160 |
} |
|
161 |
inline QDBusReply(const QDBusPendingCall &pcall) |
|
162 |
{ |
|
163 |
*this = pcall; |
|
164 |
} |
|
165 |
inline QDBusReply &operator=(const QDBusPendingCall &pcall) |
|
166 |
{ |
|
167 |
QDBusPendingCall other(pcall); |
|
168 |
other.waitForFinished(); |
|
169 |
return *this = other.reply(); |
|
170 |
} |
|
171 |
inline QDBusReply& operator=(const QDBusError& dbusError) |
|
172 |
{ |
|
173 |
m_error = dbusError; |
|
174 |
return *this; |
|
175 |
} |
|
176 |
||
177 |
inline QDBusReply& operator=(const QDBusReply& other) |
|
178 |
{ |
|
179 |
m_error = other.m_error; |
|
180 |
return *this; |
|
181 |
} |
|
182 |
||
183 |
inline bool isValid() const { return !m_error.isValid(); } |
|
184 |
||
185 |
inline const QDBusError& error() { return m_error; } |
|
186 |
||
187 |
private: |
|
188 |
QDBusError m_error; |
|
189 |
}; |
|
190 |
# endif |
|
191 |
||
192 |
QT_END_NAMESPACE |
|
193 |
||
194 |
QT_END_HEADER |
|
195 |
||
196 |
#endif |