1 | /* |
2 | * BluezQt - Asynchronous BlueZ wrapper library |
3 | * |
4 | * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> |
5 | * |
6 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
7 | */ |
8 | |
9 | #ifndef BLUEZQT_PENDINGCALL_H |
10 | #define BLUEZQT_PENDINGCALL_H |
11 | |
12 | #include <functional> |
13 | |
14 | #include <QObject> |
15 | |
16 | #include "bluezqt_export.h" |
17 | |
18 | #include <memory> |
19 | |
20 | class QDBusError; |
21 | class QDBusPendingCall; |
22 | class QDBusPendingCallWatcher; |
23 | |
24 | namespace BluezQt |
25 | { |
26 | /*! |
27 | * \inmodule BluezQt |
28 | * \class BluezQt::PendingCall |
29 | * \inheaderfile BluezQt/PendingCall |
30 | * \brief Pending method call. |
31 | * |
32 | * This class represents a pending method call. It is a convenient wrapper |
33 | * around QDBusPendingReply and QDBusPendingCallWatcher. |
34 | */ |
35 | class BLUEZQT_EXPORT PendingCall : public QObject |
36 | { |
37 | Q_OBJECT |
38 | |
39 | /*! \property BluezQt::PendingCall::value */ |
40 | Q_PROPERTY(QVariant value READ value) |
41 | /*! \property BluezQt::PendingCall::values */ |
42 | Q_PROPERTY(QVariantList values READ values) |
43 | /*! \property BluezQt::PendingCall::error */ |
44 | Q_PROPERTY(int error READ error) |
45 | /*! \property BluezQt::PendingCall::errorText */ |
46 | Q_PROPERTY(QString errorText READ errorText) |
47 | /*! \property BluezQt::PendingCall::isFinished */ |
48 | Q_PROPERTY(bool isFinished READ isFinished) |
49 | /*! \property BluezQt::PendingCall::userData */ |
50 | Q_PROPERTY(QVariant userData READ userData WRITE setUserData) |
51 | |
52 | public: |
53 | /*! |
54 | * \enum BluezQt::PendingCall::Error |
55 | * \brief Known error types. |
56 | * \value NoError |
57 | * Indicates there is no error. |
58 | * \value NotReady |
59 | * Indicates that the device is not ready. |
60 | * \value Failed |
61 | * Indicates that the action have failed. |
62 | * \value Rejected |
63 | * Indicates that the action was rejected. |
64 | * \value Canceled |
65 | * Indicates that the action was canceled. |
66 | * \value InvalidArguments |
67 | * Indicates that invalid arguments were passed. |
68 | * \value AlreadyExists |
69 | * Indicates that an agent or pairing record already exists. |
70 | * \value DoesNotExist |
71 | * Indicates that an agent, service or pairing operation does not exists. |
72 | * \value InProgress |
73 | * Indicates that the action is already in progress. |
74 | * \value NotInProgress |
75 | * Indicates that the action is not in progress. |
76 | * \value AlreadyConnected |
77 | * Indicates that the device is already connected. |
78 | * \value ConnectFailed |
79 | * Indicates that the connection to the device have failed. |
80 | * \value NotConnected |
81 | * Indicates that the device is not connected. |
82 | * \value NotSupported |
83 | * Indicates that the action is not supported. |
84 | * \value NotAuthorized |
85 | * Indicates that the caller is not authorized to do the action. |
86 | * \value AuthenticationCanceled |
87 | * Indicates that the authentication was canceled. |
88 | * \value AuthenticationFailed |
89 | * Indicates that the authentication have failed. |
90 | * \value AuthenticationRejected |
91 | * Indicates that the authentication was rejected. |
92 | * \value AuthenticationTimeout |
93 | * Indicates that the authentication timed out. |
94 | * \value ConnectionAttemptFailed |
95 | * Indicates that the connection attempt have failed. |
96 | * \value InvalidLength |
97 | * Indicates that the data provided generates a data packet which is too long. |
98 | * \value NotPermitted |
99 | * Indicates that the action is not permitted (e.g. maximum reached or socket locked). |
100 | * \value DBusError |
101 | * Indicates an error with D-Bus. |
102 | * \value InternalError |
103 | * Indicates an internal error. |
104 | * \value UnknownError |
105 | * Indicates an unknown error. |
106 | */ |
107 | enum Error { |
108 | NoError = 0, |
109 | NotReady = 1, |
110 | Failed = 2, |
111 | Rejected = 3, |
112 | Canceled = 4, |
113 | InvalidArguments = 5, |
114 | AlreadyExists = 6, |
115 | DoesNotExist = 7, |
116 | InProgress = 8, |
117 | NotInProgress = 9, |
118 | AlreadyConnected = 10, |
119 | ConnectFailed = 11, |
120 | NotConnected = 12, |
121 | NotSupported = 13, |
122 | NotAuthorized = 14, |
123 | AuthenticationCanceled = 15, |
124 | AuthenticationFailed = 16, |
125 | AuthenticationRejected = 17, |
126 | AuthenticationTimeout = 18, |
127 | ConnectionAttemptFailed = 19, |
128 | InvalidLength = 20, |
129 | NotPermitted = 21, |
130 | DBusError = 98, |
131 | InternalError = 99, |
132 | UnknownError = 100, |
133 | }; |
134 | Q_ENUM(Error) |
135 | |
136 | ~PendingCall() override; |
137 | |
138 | /*! |
139 | * Returns a first return value of the call. |
140 | */ |
141 | QVariant value() const; |
142 | |
143 | /*! |
144 | * Returns all values of the call. |
145 | */ |
146 | QVariantList values() const; |
147 | |
148 | /*! |
149 | * Returns an error code. |
150 | * \sa Error |
151 | */ |
152 | int error() const; |
153 | |
154 | /*! |
155 | * Returns an error text. |
156 | */ |
157 | QString errorText() const; |
158 | |
159 | /*! |
160 | * Returns whether the call is finished. |
161 | */ |
162 | bool isFinished() const; |
163 | |
164 | /*! |
165 | * Waits for the call to finish. |
166 | * \warning This method blocks until the call finishes! |
167 | */ |
168 | void waitForFinished(); |
169 | |
170 | /*! |
171 | * Returns the user data of the call. |
172 | */ |
173 | QVariant userData() const; |
174 | |
175 | /*! |
176 | * Sets the \a userData of the call. |
177 | */ |
178 | void setUserData(const QVariant &userData); |
179 | |
180 | Q_SIGNALS: |
181 | /*! |
182 | * Indicates that the \a call has finished. |
183 | */ |
184 | void finished(PendingCall *call); |
185 | |
186 | private: |
187 | enum ReturnType { |
188 | ReturnVoid, |
189 | ReturnUint32, |
190 | ReturnString, |
191 | ReturnStringList, |
192 | ReturnObjectPath, |
193 | ReturnFileTransferList, |
194 | ReturnTransferWithProperties, |
195 | ReturnByteArray |
196 | }; |
197 | |
198 | BLUEZQT_NO_EXPORT explicit PendingCall(Error error, const QString &errorText, QObject *parent = nullptr); |
199 | BLUEZQT_NO_EXPORT explicit PendingCall(const QDBusPendingCall &call, ReturnType type, QObject *parent = nullptr); |
200 | |
201 | // exported because called from template BluezQt::TPendingCall constructor |
202 | using ErrorProcessor = std::function<void(const QDBusError &error)>; |
203 | using ExternalProcessor = std::function<void(QDBusPendingCallWatcher *watcher, ErrorProcessor errorProcessor, QVariantList *values)>; |
204 | explicit PendingCall(const QDBusPendingCall &call, ExternalProcessor externalProcessor, QObject *parent = nullptr); |
205 | |
206 | std::unique_ptr<class PendingCallPrivate> const d; |
207 | |
208 | friend class PendingCallPrivate; |
209 | friend class Manager; |
210 | friend class Adapter; |
211 | friend class GattServiceRemote; |
212 | friend class GattCharacteristicRemote; |
213 | friend class GattDescriptorRemote; |
214 | friend class Device; |
215 | friend class GattManager; |
216 | friend class LEAdvertisingManager; |
217 | friend class Media; |
218 | friend class MediaPlayer; |
219 | friend class MediaTransport; |
220 | friend class ObexManager; |
221 | friend class ObexTransfer; |
222 | friend class ObexSession; |
223 | friend class ObexObjectPush; |
224 | friend class ObexFileTransfer; |
225 | template<class... T> |
226 | friend class TPendingCall; |
227 | }; |
228 | |
229 | } // namespace BluezQt |
230 | |
231 | #endif // BLUEZQT_PENDINGCALL_H |
232 | |