1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtDBus module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
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>
62 Q_DBUS_EXPORT void qDBusReplyFill(const QDBusMessage &reply, QDBusError &error, QVariant &data);
69 inline QDBusReply(const QDBusMessage &reply)
73 inline QDBusReply& operator=(const QDBusMessage &reply)
75 QVariant data(qMetaTypeId(&m_data), reinterpret_cast<void*>(0));
76 qDBusReplyFill(reply, m_error, data);
77 m_data = qvariant_cast<Type>(data);
81 inline QDBusReply(const QDBusPendingCall &pcall)
85 inline QDBusReply &operator=(const QDBusPendingCall &pcall)
87 QDBusPendingCall other(pcall);
88 other.waitForFinished();
89 return *this = other.reply();
91 inline QDBusReply(const QDBusPendingReply<T> &reply)
93 *this = static_cast<QDBusPendingCall>(reply);
96 inline QDBusReply(const QDBusError &dbusError = QDBusError())
97 : m_error(dbusError), m_data(Type())
100 inline QDBusReply& operator=(const QDBusError& dbusError)
107 inline QDBusReply& operator=(const QDBusReply& other)
109 m_error = other.m_error;
110 m_data = other.m_data;
114 inline bool isValid() const { return !m_error.isValid(); }
116 inline const QDBusError& error() { return m_error; }
118 inline Type value() const
123 inline operator Type () const
134 // specialize for QVariant:
135 template<> inline QDBusReply<QVariant>&
136 QDBusReply<QVariant>::operator=(const QDBusMessage &reply)
139 QVariant data(qMetaTypeId<QDBusVariant>(), null);
140 qDBusReplyFill(reply, m_error, data);
141 m_data = qvariant_cast<QDBusVariant>(data).variant();
145 // specialize for void:
147 class QDBusReply<void>
150 inline QDBusReply(const QDBusMessage &reply)
154 inline QDBusReply& operator=(const QDBusMessage &reply)
159 inline QDBusReply(const QDBusError &dbusError = QDBusError())
163 inline QDBusReply(const QDBusPendingCall &pcall)
167 inline QDBusReply &operator=(const QDBusPendingCall &pcall)
169 QDBusPendingCall other(pcall);
170 other.waitForFinished();
171 return *this = other.reply();
173 inline QDBusReply& operator=(const QDBusError& dbusError)
179 inline QDBusReply& operator=(const QDBusReply& other)
181 m_error = other.m_error;
185 inline bool isValid() const { return !m_error.isValid(); }
187 inline const QDBusError& error() { return m_error; }