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

source code of bluez-qt/src/pendingcall.h