1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the QtDBus module of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QDBUSPENDINGREPLY_H
43 #define QDBUSPENDINGREPLY_H
45 #include <QtCore/qglobal.h>
46 #include <QtDBus/qdbusmacros.h>
47 #include <QtDBus/qdbusargument.h>
48 #include <QtDBus/qdbuspendingcall.h>
57 class Q_DBUS_EXPORT QDBusPendingReplyData: public QDBusPendingCall
60 QDBusPendingReplyData();
61 ~QDBusPendingReplyData();
62 void assign(const QDBusPendingCall &call);
63 void assign(const QDBusMessage &message);
65 QVariant argumentAt(int index) const;
66 void setMetaTypes(int count, const int *metaTypes);
69 namespace QDBusPendingReplyTypes {
71 typename T1, typename T2, typename T3, typename T4,
72 typename T5, typename T6, typename T7, typename T8>
75 typedef Select<Index - 1, T2, T3, T4, T5, T6, T7, T8, void> Next;
76 typedef typename Next::Type Type;
78 template<typename T1, typename T2, typename T3, typename T4,
79 typename T5, typename T6, typename T7, typename T8>
80 struct Select<0, T1, T2, T3, T4, T5, T6, T7, T8>
85 template<typename T1> inline int metaTypeFor(T1 * = 0)
86 { return qMetaTypeId<T1>(); }
87 // specialize for QVariant, allowing it to be used in place of QDBusVariant
88 template<> inline int metaTypeFor<QVariant>(QVariant *)
89 { return qMetaTypeId<QDBusVariant>(); }
91 template<typename T1, typename T2, typename T3, typename T4,
92 typename T5, typename T6, typename T7, typename T8>
95 typedef ForEach<T2, T3, T4, T5, T6, T7, T8, void> Next;
96 enum { Total = Next::Total + 1 };
97 static inline void fillMetaTypes(int *p)
99 *p = metaTypeFor<T1>(0);
100 Next::fillMetaTypes(++p);
104 struct ForEach<void, void, void, void, void, void, void, void>
107 static inline void fillMetaTypes(int *)
110 } // namespace QDBusPendingReplyTypes
112 template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void,
113 typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
114 class QDBusPendingReply:
116 public QDBusPendingCall
118 public QDBusPendingReplyData
121 typedef QDBusPendingReplyTypes::ForEach<T1, T2, T3, T4, T5, T6, T7, T8> ForEach;
122 template<int Index> struct Select :
123 QDBusPendingReplyTypes::Select<Index, T1, T2, T3, T4, T5, T6, T7, T8>
128 enum { Count = ForEach::Total };
130 inline QDBusPendingReply()
132 inline QDBusPendingReply(const QDBusPendingReply &other)
133 : QDBusPendingReplyData(other)
135 inline /*implicit*/ QDBusPendingReply(const QDBusPendingCall &call) // required by qdbusxml2cpp-generated code
137 inline /*implicit*/ QDBusPendingReply(const QDBusMessage &message)
139 inline QDBusPendingReply &operator=(const QDBusPendingReply &other)
140 { assign(other); return *this; }
141 inline QDBusPendingReply &operator=(const QDBusPendingCall &call)
142 { assign(call); return *this; }
143 inline QDBusPendingReply &operator=(const QDBusMessage &message)
144 { assign(message); return *this; }
146 inline int count() const { return Count; }
148 #if defined(Q_QDOC) || defined(Q_NO_USING_KEYWORD)
149 inline QVariant argumentAt(int index) const
150 { return QDBusPendingReplyData::argumentAt(index); }
152 using QDBusPendingReplyData::argumentAt;
156 bool isFinished() const;
157 void waitForFinished();
159 bool isValid() const;
160 bool isError() const;
161 QDBusError error() const;
162 QDBusMessage reply() const;
164 template<int Index> inline Type argumentAt() const;
165 inline T1 value() const;
166 inline operator T1() const;
168 template<int Index> inline
169 const typename Select<Index>::Type argumentAt() const
172 Q_ASSERT_X(Index < count() && Index >= 0, "QDBusPendingReply::argumentAt",
173 "Index out of bounds");
174 typedef typename Select<Index>::Type ResultType;
175 return qdbus_cast<ResultType>(argumentAt(Index), 0);
178 inline typename Select<0>::Type value() const
180 return argumentAt<0>();
183 inline operator typename Select<0>::Type() const
185 return argumentAt<0>();
190 inline void calculateMetaTypes()
193 int typeIds[Count > 0 ? Count : 1]; // use at least one since zero-sized arrays aren't valid
194 ForEach::fillMetaTypes(typeIds);
195 setMetaTypes(Count, typeIds);
198 inline void assign(const QDBusPendingCall &call)
200 QDBusPendingReplyData::assign(call);
201 calculateMetaTypes();
204 inline void assign(const QDBusMessage &message)
206 QDBusPendingReplyData::assign(message);
207 calculateMetaTypes();