source: trunk/src/dbus/qdbusreply.h@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 5.3 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 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#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#ifndef QT_NO_DBUS
55
56QT_BEGIN_HEADER
57
58QT_BEGIN_NAMESPACE
59
60QT_MODULE(DBus)
61
62Q_DBUS_EXPORT void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data);
63
64template<typename T>
65class QDBusReply
66{
67 typedef T Type;
68public:
69 inline QDBusReply(const QDBusMessage &reply)
70 {
71 *this = reply;
72 }
73 inline QDBusReply& operator=(const QDBusMessage &reply)
74 {
75 QVariant data(qMetaTypeId(&m_data), reinterpret_cast<void*>(0));
76 qDBusReplyFill(reply, m_error, data);
77 m_data = qvariant_cast<Type>(data);
78 return *this;
79 }
80
81 inline QDBusReply(const QDBusPendingCall &pcall)
82 {
83 *this = pcall;
84 }
85 inline QDBusReply &operator=(const QDBusPendingCall &pcall)
86 {
87 QDBusPendingCall other(pcall);
88 other.waitForFinished();
89 return *this = other.reply();
90 }
91 inline QDBusReply(const QDBusPendingReply<T> &reply)
92 {
93 *this = static_cast<QDBusPendingCall>(reply);
94 }
95
96 inline QDBusReply(const QDBusError &dbusError = QDBusError())
97 : m_error(dbusError), m_data(Type())
98 {
99 }
100 inline QDBusReply& operator=(const QDBusError& dbusError)
101 {
102 m_error = dbusError;
103 m_data = Type();
104 return *this;
105 }
106
107 inline QDBusReply& operator=(const QDBusReply& other)
108 {
109 m_error = other.m_error;
110 m_data = other.m_data;
111 return *this;
112 }
113
114 inline bool isValid() const { return !m_error.isValid(); }
115
116 inline const QDBusError& error() { return m_error; }
117
118 inline Type value() const
119 {
120 return m_data;
121 }
122
123 inline operator Type () const
124 {
125 return m_data;
126 }
127
128private:
129 QDBusError m_error;
130 Type m_data;
131};
132
133# ifndef Q_QDOC
134// specialize for QVariant:
135template<> inline QDBusReply<QVariant>&
136QDBusReply<QVariant>::operator=(const QDBusMessage &reply)
137{
138 void *null = 0;
139 QVariant data(qMetaTypeId<QDBusVariant>(), null);
140 qDBusReplyFill(reply, m_error, data);
141 m_data = qvariant_cast<QDBusVariant>(data).variant();
142 return *this;
143}
144
145// specialize for void:
146template<>
147class QDBusReply<void>
148{
149public:
150 inline QDBusReply(const QDBusMessage &reply)
151 : m_error(reply)
152 {
153 }
154 inline QDBusReply& operator=(const QDBusMessage &reply)
155 {
156 m_error = reply;
157 return *this;
158 }
159 inline QDBusReply(const QDBusError &dbusError = QDBusError())
160 : m_error(dbusError)
161 {
162 }
163 inline QDBusReply(const QDBusPendingCall &pcall)
164 {
165 *this = pcall;
166 }
167 inline QDBusReply &operator=(const QDBusPendingCall &pcall)
168 {
169 QDBusPendingCall other(pcall);
170 other.waitForFinished();
171 return *this = other.reply();
172 }
173 inline QDBusReply& operator=(const QDBusError& dbusError)
174 {
175 m_error = dbusError;
176 return *this;
177 }
178
179 inline QDBusReply& operator=(const QDBusReply& other)
180 {
181 m_error = other.m_error;
182 return *this;
183 }
184
185 inline bool isValid() const { return !m_error.isValid(); }
186
187 inline const QDBusError& error() { return m_error; }
188
189private:
190 QDBusError m_error;
191};
192# endif
193
194QT_END_NAMESPACE
195
196QT_END_HEADER
197
198#endif // QT_NO_DBUS
199#endif
Note: See TracBrowser for help on using the repository browser.