1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2009 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 QDBUSPENDINGREPLY_H
|
---|
43 | #define QDBUSPENDINGREPLY_H
|
---|
44 |
|
---|
45 | #include <QtCore/qglobal.h>
|
---|
46 | #include <QtDBus/qdbusmacros.h>
|
---|
47 | #include <QtDBus/qdbusargument.h>
|
---|
48 | #include <QtDBus/qdbuspendingcall.h>
|
---|
49 |
|
---|
50 | QT_BEGIN_HEADER
|
---|
51 |
|
---|
52 | QT_BEGIN_NAMESPACE
|
---|
53 |
|
---|
54 | QT_MODULE(DBus)
|
---|
55 |
|
---|
56 | class QDBUS_EXPORT QDBusPendingReplyData: public QDBusPendingCall
|
---|
57 | {
|
---|
58 | protected:
|
---|
59 | QDBusPendingReplyData();
|
---|
60 | ~QDBusPendingReplyData();
|
---|
61 | void assign(const QDBusPendingCall &call);
|
---|
62 | void assign(const QDBusMessage &message);
|
---|
63 |
|
---|
64 | QVariant argumentAt(int index) const;
|
---|
65 | void setMetaTypes(int count, const int *metaTypes);
|
---|
66 | };
|
---|
67 |
|
---|
68 | namespace QDBusPendingReplyTypes {
|
---|
69 | template<int Index,
|
---|
70 | typename T1, typename T2, typename T3, typename T4,
|
---|
71 | typename T5, typename T6, typename T7, typename T8>
|
---|
72 | struct Select
|
---|
73 | {
|
---|
74 | typedef Select<Index - 1, T2, T3, T4, T5, T6, T7, T8, void> Next;
|
---|
75 | typedef typename Next::Type Type;
|
---|
76 | };
|
---|
77 | template<typename T1, typename T2, typename T3, typename T4,
|
---|
78 | typename T5, typename T6, typename T7, typename T8>
|
---|
79 | struct Select<0, T1, T2, T3, T4, T5, T6, T7, T8>
|
---|
80 | {
|
---|
81 | typedef T1 Type;
|
---|
82 | };
|
---|
83 |
|
---|
84 | template<typename T1> inline int metaTypeFor(T1 * = 0)
|
---|
85 | { return qMetaTypeId<T1>(); }
|
---|
86 | // specialise for QVariant, allowing it to be used in place of QDBusVariant
|
---|
87 | template<> inline int metaTypeFor<QVariant>(QVariant *)
|
---|
88 | { return qMetaTypeId<QDBusVariant>(); }
|
---|
89 |
|
---|
90 | template<typename T1, typename T2, typename T3, typename T4,
|
---|
91 | typename T5, typename T6, typename T7, typename T8>
|
---|
92 | struct ForEach
|
---|
93 | {
|
---|
94 | typedef ForEach<T2, T3, T4, T5, T6, T7, T8, void> Next;
|
---|
95 | enum { Total = Next::Total + 1 };
|
---|
96 | static inline void fillMetaTypes(int *p)
|
---|
97 | {
|
---|
98 | *p = metaTypeFor<T1>(0);
|
---|
99 | Next::fillMetaTypes(++p);
|
---|
100 | }
|
---|
101 | };
|
---|
102 | template<>
|
---|
103 | struct ForEach<void, void, void, void, void, void, void, void>
|
---|
104 | {
|
---|
105 | enum { Total = 0 };
|
---|
106 | static inline void fillMetaTypes(int *)
|
---|
107 | { }
|
---|
108 | };
|
---|
109 | } // namespace QDBusPendingReplyTypes
|
---|
110 |
|
---|
111 | template<typename T1 = void, typename T2 = void, typename T3 = void, typename T4 = void,
|
---|
112 | typename T5 = void, typename T6 = void, typename T7 = void, typename T8 = void>
|
---|
113 | class QDBusPendingReply:
|
---|
114 | #ifdef Q_QDOC
|
---|
115 | public QDBusPendingCall
|
---|
116 | #else
|
---|
117 | public QDBusPendingReplyData
|
---|
118 | #endif
|
---|
119 | {
|
---|
120 | typedef QDBusPendingReplyTypes::ForEach<T1, T2, T3, T4, T5, T6, T7, T8> ForEach;
|
---|
121 | template<int Index> struct Select :
|
---|
122 | QDBusPendingReplyTypes::Select<Index, T1, T2, T3, T4, T5, T6, T7, T8>
|
---|
123 | {
|
---|
124 | };
|
---|
125 |
|
---|
126 | public:
|
---|
127 | enum { Count = ForEach::Total };
|
---|
128 |
|
---|
129 | inline QDBusPendingReply()
|
---|
130 | { }
|
---|
131 | inline QDBusPendingReply(const QDBusPendingReply &other)
|
---|
132 | : QDBusPendingReplyData(other)
|
---|
133 | { }
|
---|
134 | inline QDBusPendingReply(const QDBusPendingCall &call)
|
---|
135 | { *this = call; }
|
---|
136 | inline QDBusPendingReply(const QDBusMessage &message)
|
---|
137 | { *this = message; }
|
---|
138 | inline QDBusPendingReply &operator=(const QDBusPendingReply &other)
|
---|
139 | { assign(other); return *this; }
|
---|
140 | inline QDBusPendingReply &operator=(const QDBusPendingCall &call)
|
---|
141 | { assign(call); return *this; }
|
---|
142 | inline QDBusPendingReply &operator=(const QDBusMessage &message)
|
---|
143 | { assign(message); return *this; }
|
---|
144 |
|
---|
145 | inline int count() const { return Count; }
|
---|
146 |
|
---|
147 | #if defined(Q_QDOC) || defined(Q_NO_USING_KEYWORD)
|
---|
148 | inline QVariant argumentAt(int index) const
|
---|
149 | { return QDBusPendingReplyData::argumentAt(index); }
|
---|
150 | #else
|
---|
151 | using QDBusPendingReplyData::argumentAt;
|
---|
152 | #endif
|
---|
153 |
|
---|
154 | #if defined(Q_QDOC)
|
---|
155 | bool isFinished() const;
|
---|
156 | void waitForFinished();
|
---|
157 |
|
---|
158 | bool isValid() const;
|
---|
159 | bool isError() const;
|
---|
160 | QDBusError error() const;
|
---|
161 | QDBusMessage reply() const;
|
---|
162 |
|
---|
163 | template<int Index> inline Type argumentAt() const;
|
---|
164 | inline T1 value() const;
|
---|
165 | inline operator T1() const;
|
---|
166 | #else
|
---|
167 | template<int Index> inline
|
---|
168 | const typename Select<Index>::Type argumentAt() const
|
---|
169 | {
|
---|
170 | // static assert?
|
---|
171 | Q_ASSERT_X(Index < count() && Index >= 0, "QDBusPendingReply::argumentAt",
|
---|
172 | "Index out of bounds");
|
---|
173 | typedef typename Select<Index>::Type ResultType;
|
---|
174 | return qdbus_cast<ResultType>(argumentAt(Index), 0);
|
---|
175 | }
|
---|
176 |
|
---|
177 | inline typename Select<0>::Type value() const
|
---|
178 | {
|
---|
179 | return argumentAt<0>();
|
---|
180 | }
|
---|
181 |
|
---|
182 | inline operator typename Select<0>::Type() const
|
---|
183 | {
|
---|
184 | return argumentAt<0>();
|
---|
185 | }
|
---|
186 | #endif
|
---|
187 |
|
---|
188 | private:
|
---|
189 | inline void calculateMetaTypes()
|
---|
190 | {
|
---|
191 | if (!d) return;
|
---|
192 | int typeIds[Count > 0 ? Count : 1]; // use at least one since zero-sized arrays aren't valid
|
---|
193 | ForEach::fillMetaTypes(typeIds);
|
---|
194 | setMetaTypes(Count, typeIds);
|
---|
195 | }
|
---|
196 |
|
---|
197 | inline void assign(const QDBusPendingCall &call)
|
---|
198 | {
|
---|
199 | QDBusPendingReplyData::assign(call);
|
---|
200 | calculateMetaTypes();
|
---|
201 | }
|
---|
202 |
|
---|
203 | inline void assign(const QDBusMessage &message)
|
---|
204 | {
|
---|
205 | QDBusPendingReplyData::assign(message);
|
---|
206 | calculateMetaTypes();
|
---|
207 | }
|
---|
208 | };
|
---|
209 |
|
---|
210 | QT_END_NAMESPACE
|
---|
211 |
|
---|
212 | QT_END_HEADER
|
---|
213 |
|
---|
214 | #endif
|
---|