Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qdbuspendingreply.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QDBUSPENDINGREPLY_H
5#define QDBUSPENDINGREPLY_H
6
7#include <QtDBus/qtdbusglobal.h>
8#include <QtDBus/qdbusargument.h>
9#include <QtDBus/qdbuspendingcall.h>
10
11#ifndef QT_NO_DBUS
12
14
15
16class Q_DBUS_EXPORT QDBusPendingReplyBase : public QDBusPendingCall
17{
18protected:
21 void assign(const QDBusPendingCall &call);
22 void assign(const QDBusMessage &message);
23
24 QVariant argumentAt(int index) const;
25 void setMetaTypes(int count, const QMetaType *metaTypes);
26};
27
29 template<int Index, typename T, typename... Types>
30 struct Select
31 {
32 typedef Select<Index - 1, Types...> Next;
33 typedef typename Next::Type Type;
34 };
35 template<typename T, typename... Types>
36 struct Select<0, T, Types...>
37 {
38 typedef T Type;
39 };
40
41 template<typename T> inline QMetaType metaTypeFor()
42 { return QMetaType::fromType<T>(); }
43 // specialize for QVariant, allowing it to be used in place of QDBusVariant
44 template<> inline QMetaType metaTypeFor<QVariant>()
45 { return QMetaType::fromType<QDBusVariant>(); }
46}
47
48
49template<typename... Types>
51{
52 template<int Index> using Select = QDBusPendingReplyTypes::Select<Index, Types...>;
53public:
54 enum { Count = std::is_same_v<typename Select<0>::Type, void> ? 0 : sizeof...(Types) };
55
56 inline constexpr int count() const { return Count; }
57
58
59 inline QDBusPendingReply() = default;
63 inline Q_IMPLICIT QDBusPendingReply(const QDBusPendingCall &call) // required by qdbusxml2cpp-generated code
64 { *this = call; }
67
69 { assign(other); return *this; }
71 { assign(call); return *this; }
73 { assign(message); return *this; }
74
76 template<int Index> inline
78 {
79 static_assert(Index >= 0 && Index < Count, "Index out of bounds");
80 typedef typename Select<Index>::Type ResultType;
81 return qdbus_cast<ResultType>(argumentAt(Index));
82 }
83
84#if defined(Q_QDOC)
85 bool isFinished() const;
86 void waitForFinished();
87 QVariant argumentAt(int index) const;
88
89 bool isValid() const;
90 bool isError() const;
91 QDBusError error() const;
92 QDBusMessage reply() const;
93#endif
94
95 inline typename Select<0>::Type value() const
96 {
97 return argumentAt<0>();
98 }
99
100 inline operator typename Select<0>::Type() const
101 {
102 return argumentAt<0>();
103 }
104
105private:
106 inline void calculateMetaTypes()
107 {
108 if (!d) return;
109 if constexpr (Count == 0) {
110 setMetaTypes(0, nullptr);
111 } else {
112 std::array<QMetaType, Count> typeIds = { QDBusPendingReplyTypes::metaTypeFor<Types>()... };
113 setMetaTypes(Count, typeIds.data());
114 }
115 }
116
117 inline void assign(const QDBusPendingCall &call)
118 {
120 calculateMetaTypes();
121 }
122
123 inline void assign(const QDBusMessage &message)
124 {
126 calculateMetaTypes();
127 }
128};
129
130template<>
132{
133public:
134 enum { Count = 0 };
135 inline int count() const { return Count; }
136
137 inline QDBusPendingReply() = default;
141 inline Q_IMPLICIT QDBusPendingReply(const QDBusPendingCall &call) // required by qdbusxml2cpp-generated code
142 { *this = call; }
144 { *this = message; }
145
147 { assign(other); return *this; }
149 { assign(call); return *this; }
151 { assign(message); return *this; }
152
153private:
154 inline void assign(const QDBusPendingCall &call)
155 {
157 if (d)
158 setMetaTypes(0, nullptr);
159 }
160
161 inline void assign(const QDBusMessage &message)
162 {
164 if (d)
165 setMetaTypes(0, nullptr);
166 }
167
168};
169
171
172#endif // QT_NO_DBUS
173#endif
\inmodule QtDBus
Definition qdbuserror.h:21
\inmodule QtDBus
\inmodule QtDBus
QExplicitlySharedDataPointer< QDBusPendingCallPrivate > d
QDBusError error() const
QDBusMessage reply() const
void setMetaTypes(int count, const QMetaType *metaTypes)
void assign(const QDBusPendingCall &call)
QVariant argumentAt(int index) const
QDBusPendingReply & operator=(const QDBusPendingReply &other)
QDBusPendingReply()=default
QDBusPendingReply(const QDBusPendingReply &other)
Q_IMPLICIT QDBusPendingReply(const QDBusPendingCall &call)
QDBusPendingReply & operator=(const QDBusPendingCall &call)
Q_IMPLICIT QDBusPendingReply(const QDBusMessage &message)
QDBusPendingReply & operator=(const QDBusMessage &message)
\inmodule QtDBus
QDBusPendingReply & operator=(const QDBusMessage &message)
Makes this object take its contents from the message message and drops the reference to the current p...
Q_IMPLICIT QDBusPendingReply(const QDBusMessage &message)
Creates a QDBusPendingReply object that will take its contents from the message message.
Q_IMPLICIT QDBusPendingReply(const QDBusPendingCall &call)
Creates a QDBusPendingReply object that will take its contents from the call pending asynchronous cal...
QDBusPendingReply(const QDBusPendingReply &other)
Creates a copy of the other QDBusPendingReply object.
constexpr int count() const
Return the number of arguments the reply is supposed to have.
QDBusPendingReply & operator=(const QDBusPendingReply &other)
Makes a copy of other and drops the reference to the current pending call.
Select< 0 >::Type value() const
Returns the first argument in this reply, cast to type Types[0] (the first template parameter of this...
QDBusPendingReply()=default
Creates an empty QDBusPendingReply object.
Select< Index >::Type argumentAt() const
Returns the argument at position index in the reply's contents.
QDBusPendingReply & operator=(const QDBusPendingCall &call)
Makes this object take its contents from the call pending call and drops the reference to the current...
\inmodule QtCore
Definition qmetatype.h:341
\inmodule QtCore
Definition qvariant.h:65
QMetaType metaTypeFor< QVariant >()
Combined button and popup list for selecting options.
#define Q_IMPLICIT
GLuint index
[2]
GLenum GLenum GLsizei count
GLuint GLsizei const GLchar * message
QSharedPointer< T > other(t)
[5]
Select< Index - 1, Types... > Next