1 /****************************************************************************
3 ** Copyright (C) 2010 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 ** 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
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.
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>
60 QDBUS_EXPORT
void qDBusReplyFill(const QDBusMessage
&reply
, QDBusError
&error
, QVariant
&data
);
67 inline QDBusReply(const QDBusMessage
&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
);
79 inline QDBusReply(const QDBusPendingCall
&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
)
105 inline QDBusReply
& operator=(const QDBusReply
& other
)
107 m_error
= other
.m_error
;
108 m_data
= other
.m_data
;
112 inline bool isValid() const { return !m_error
.isValid(); }
114 inline const QDBusError
& error() { return m_error
; }
116 inline Type
value() const
121 inline operator Type () const
132 // specialize for QVariant:
133 template<> inline QDBusReply
<QVariant
>&
134 QDBusReply
<QVariant
>::operator=(const QDBusMessage
&reply
)
137 QVariant
data(qMetaTypeId
<QDBusVariant
>(), null
);
138 qDBusReplyFill(reply
, m_error
, data
);
139 m_data
= qvariant_cast
<QDBusVariant
>(data
).variant();
143 // specialize for void:
145 class QDBusReply
<void>
148 inline QDBusReply(const QDBusMessage
&reply
)
152 inline QDBusReply
& operator=(const QDBusMessage
&reply
)
157 inline QDBusReply(const QDBusError
&dbusError
= QDBusError())
161 inline QDBusReply(const QDBusPendingCall
&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
)
177 inline QDBusReply
& operator=(const QDBusReply
& other
)
179 m_error
= other
.m_error
;
183 inline bool isValid() const { return !m_error
.isValid(); }
185 inline const QDBusError
& error() { return m_error
; }