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 ****************************************************************************/
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>
56 class QDBUS_EXPORT QDBusPendingReplyData
: public QDBusPendingCall
59 QDBusPendingReplyData();
60 ~QDBusPendingReplyData();
61 void assign(const QDBusPendingCall
&call
);
62 void assign(const QDBusMessage
&message
);
64 QVariant
argumentAt(int index
) const;
65 void setMetaTypes(int count
, const int *metaTypes
);
68 namespace QDBusPendingReplyTypes
{
70 typename T1
, typename T2
, typename T3
, typename T4
,
71 typename T5
, typename T6
, typename T7
, typename T8
>
74 typedef Select
<Index
- 1, T2
, T3
, T4
, T5
, T6
, T7
, T8
, void> Next
;
75 typedef typename
Next::Type Type
;
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
>
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
>(); }
90 template<typename T1
, typename T2
, typename T3
, typename T4
,
91 typename T5
, typename T6
, typename T7
, typename T8
>
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
)
98 *p
= metaTypeFor
<T1
>(0);
99 Next::fillMetaTypes(++p
);
103 struct ForEach
<void, void, void, void, void, void, void, void>
106 static inline void fillMetaTypes(int *)
109 } // namespace QDBusPendingReplyTypes
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
:
115 public QDBusPendingCall
117 public QDBusPendingReplyData
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
>
127 enum { Count
= ForEach::Total
};
129 inline QDBusPendingReply()
131 inline QDBusPendingReply(const QDBusPendingReply
&other
)
132 : QDBusPendingReplyData(other
)
134 inline QDBusPendingReply(const QDBusPendingCall
&call
)
136 inline QDBusPendingReply(const QDBusMessage
&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; }
145 inline int count() const { return Count
; }
147 #if defined(Q_QDOC) || defined(Q_NO_USING_KEYWORD)
148 inline QVariant
argumentAt(int index
) const
149 { return QDBusPendingReplyData::argumentAt(index
); }
151 using QDBusPendingReplyData::argumentAt
;
155 bool isFinished() const;
156 void waitForFinished();
158 bool isValid() const;
159 bool isError() const;
160 QDBusError
error() const;
161 QDBusMessage
reply() const;
163 template<int Index
> inline Type
argumentAt() const;
164 inline T1
value() const;
165 inline operator T1() const;
167 template<int Index
> inline
168 const typename Select
<Index
>::Type
argumentAt() const
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);
177 inline typename Select
<0>::Type
value() const
179 return argumentAt
<0>();
182 inline operator typename Select
<0>::Type() const
184 return argumentAt
<0>();
189 inline void calculateMetaTypes()
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
);
197 inline void assign(const QDBusPendingCall
&call
)
199 QDBusPendingReplyData::assign(call
);
200 calculateMetaTypes();
203 inline void assign(const QDBusMessage
&message
)
205 QDBusPendingReplyData::assign(message
);
206 calculateMetaTypes();