Merge branch 'master' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into master-integration
[qt-netbsd.git] / src / dbus / qdbusreply.h
blob092ffcb064bc0384cb94dc080addc20f8369769b
1 /****************************************************************************
2 **
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
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.
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.
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.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
42 #ifndef QDBUSREPLY_H
43 #define QDBUSREPLY_H
45 #include <QtCore/qglobal.h>
46 #include <QtCore/qvariant.h>
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>
54 QT_BEGIN_HEADER
56 QT_BEGIN_NAMESPACE
58 QT_MODULE(DBus)
60 QDBUS_EXPORT void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data);
62 template<typename T>
63 class QDBusReply
65 typedef T Type;
66 public:
67 inline QDBusReply(const QDBusMessage &reply)
69 *this = reply;
71 inline QDBusReply& operator=(const QDBusMessage &reply)
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;
79 inline QDBusReply(const QDBusPendingCall &pcall)
81 *this = pcall;
83 inline QDBusReply &operator=(const QDBusPendingCall &pcall)
85 QDBusPendingCall other(pcall);
86 other.waitForFinished();
87 return *this = other.reply();
89 inline QDBusReply(const QDBusPendingReply<T> &reply)
91 *this = static_cast<QDBusPendingCall>(reply);
94 inline QDBusReply(const QDBusError &dbusError = QDBusError())
95 : m_error(dbusError), m_data(Type())
98 inline QDBusReply& operator=(const QDBusError& dbusError)
100 m_error = dbusError;
101 m_data = Type();
102 return *this;
105 inline QDBusReply& operator=(const QDBusReply& other)
107 m_error = other.m_error;
108 m_data = other.m_data;
109 return *this;
112 inline bool isValid() const { return !m_error.isValid(); }
114 inline const QDBusError& error() { return m_error; }
116 inline Type value() const
118 return m_data;
121 inline operator Type () const
123 return m_data;
126 private:
127 QDBusError m_error;
128 Type m_data;
131 # ifndef Q_QDOC
132 // specialize for QVariant:
133 template<> inline QDBusReply<QVariant>&
134 QDBusReply<QVariant>::operator=(const QDBusMessage &reply)
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;
143 // specialize for void:
144 template<>
145 class QDBusReply<void>
147 public:
148 inline QDBusReply(const QDBusMessage &reply)
149 : m_error(reply)
152 inline QDBusReply& operator=(const QDBusMessage &reply)
154 m_error = reply;
155 return *this;
157 inline QDBusReply(const QDBusError &dbusError = QDBusError())
158 : m_error(dbusError)
161 inline QDBusReply(const QDBusPendingCall &pcall)
163 *this = pcall;
165 inline QDBusReply &operator=(const QDBusPendingCall &pcall)
167 QDBusPendingCall other(pcall);
168 other.waitForFinished();
169 return *this = other.reply();
171 inline QDBusReply& operator=(const QDBusError& dbusError)
173 m_error = dbusError;
174 return *this;
177 inline QDBusReply& operator=(const QDBusReply& other)
179 m_error = other.m_error;
180 return *this;
183 inline bool isValid() const { return !m_error.isValid(); }
185 inline const QDBusError& error() { return m_error; }
187 private:
188 QDBusError m_error;
190 # endif
192 QT_END_NAMESPACE
194 QT_END_HEADER
196 #endif