Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
4
5#ifndef QDBUSPENDINGREPLY_H
6#define QDBUSPENDINGREPLY_H
7
8#include <QtDBus/qtdbusglobal.h>
9#include <QtDBus/qdbusargument.h>
10#include <QtDBus/qdbuspendingcall.h>
11
12#ifndef QT_NO_DBUS
13
14class tst_QDBusPendingReply;
15
17
18
19class Q_DBUS_EXPORT QDBusPendingReplyBase : public QDBusPendingCall
20{
21protected:
22 QDBusPendingReplyBase();
23#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
24 ~QDBusPendingReplyBase();
25 QDBusPendingReplyBase(const QDBusPendingReplyBase &) = default;
26 QDBusPendingReplyBase &operator=(const QDBusPendingReplyBase &) = default;
27 QDBusPendingReplyBase(QDBusPendingReplyBase &&) noexcept = default;
28 QDBusPendingReplyBase &operator=(QDBusPendingReplyBase &&) noexcept = default;
29#endif
30
31 void assign(const QDBusPendingCall &call);
32 void assign(const QDBusMessage &message);
33
34 QVariant argumentAt(int index) const;
35 void setMetaTypes(int count, const QMetaType *metaTypes);
36};
37
39 template<int Index, typename T, typename... Types>
40 struct Select
41 {
42 typedef Select<Index - 1, Types...> Next;
43 typedef typename Next::Type Type;
44 };
45 template<typename T, typename... Types>
46 struct Select<0, T, Types...>
47 {
48 typedef T Type;
49 };
50
51 template<typename T> inline QMetaType metaTypeFor()
52 { return QMetaType::fromType<T>(); }
53 // specialize for QVariant, allowing it to be used in place of QDBusVariant
54 template<> inline QMetaType metaTypeFor<QVariant>()
55 { return QMetaType::fromType<QDBusVariant>(); }
56}
57
58
59template<typename... Types>
61{
62 friend class ::tst_QDBusPendingReply;
63 template<int Index> using Select = QDBusPendingReplyTypes::Select<Index, Types...>;
64public:
65 enum { Count = std::is_same_v<typename Select<0>::Type, void> ? 0 : sizeof...(Types) };
66
67 inline constexpr int count() const { return Count; }
68
69 inline QDBusPendingReply() = default;
70 // Rule Of Zero applies!
71
72 inline Q_IMPLICIT QDBusPendingReply(const QDBusPendingCall &call) // required by qdbusxml2cpp-generated code
73 { *this = call; }
76
77 inline QDBusPendingReply &operator=(const QDBusPendingCall &call)
78 { assign(call); return *this; }
79 inline QDBusPendingReply &operator=(const QDBusMessage &message)
80 { assign(message); return *this; }
81
82 using QDBusPendingReplyBase::argumentAt;
83 template<int Index> inline
84 typename Select<Index>::Type argumentAt() const
85 {
86 static_assert(Index >= 0 && Index < Count, "Index out of bounds");
87 typedef typename Select<Index>::Type ResultType;
88 return qdbus_cast<ResultType>(argumentAt(Index));
89 }
90
91#if defined(Q_QDOC)
92 bool isFinished() const;
93 void waitForFinished();
94 QVariant argumentAt(int index) const;
95
96 bool isValid() const;
97 bool isError() const;
98 QDBusError error() const;
99 QDBusMessage reply() const;
100#endif
101
102 inline typename Select<0>::Type value() const
103 {
104 return argumentAt<0>();
105 }
106
107 inline operator typename Select<0>::Type() const
108 {
109 return argumentAt<0>();
110 }
111
112private:
113 inline void calculateMetaTypes()
114 {
115 if (!d) return;
116 if constexpr (Count == 0) {
117 setMetaTypes(0, nullptr);
118 } else {
121 }
122 }
123
124 inline void assign(const QDBusPendingCall &call)
125 {
128 }
129
130 inline void assign(const QDBusMessage &message)
131 {
134 }
135};
136
137template<>
139{
140 friend class ::tst_QDBusPendingReply;
141public:
142 enum { Count = 0 };
143 inline int count() const { return Count; }
144
145 inline QDBusPendingReply() = default;
146 // Rule Of Zero applies!
147
148 inline Q_IMPLICIT QDBusPendingReply(const QDBusPendingCall &call) // required by qdbusxml2cpp-generated code
149 { *this = call; }
151 { *this = message; }
152
153 inline QDBusPendingReply &operator=(const QDBusPendingCall &call)
154 { assign(call); return *this; }
155 inline QDBusPendingReply &operator=(const QDBusMessage &message)
156 { assign(message); return *this; }
157
158private:
159 inline void assign(const QDBusPendingCall &call)
160 {
161 QDBusPendingReplyBase::assign(call);
162 if (d)
163 setMetaTypes(0, nullptr);
164 }
165
166 inline void assign(const QDBusMessage &message)
167 {
168 QDBusPendingReplyBase::assign(message);
169 if (d)
170 setMetaTypes(0, nullptr);
171 }
172
173};
174
175QT_END_NAMESPACE
176
177#endif // QT_NO_DBUS
178#endif
QDBusPendingReply()=default
QDBusPendingReply & operator=(const QDBusPendingCall &call)
\inmodule QtDBus
Select< Index >::Type argumentAt() const
Returns the argument at position index in the reply's contents.
constexpr int count() const
Return the number of arguments the reply is supposed to have.
QDBusPendingReply()=default
Creates an empty QDBusPendingReply object.
Select< 0 >::Type value() const
Returns the first argument in this reply, cast to type Types[0] (the first template parameter of this...
QDBusPendingReply & operator=(const QDBusPendingCall &call)
Makes this object take its contents from the call pending call and drops the reference to the current...
Select< Index - 1, Types... > Next