BluezQt

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

KDE's Doxygen guidelines are available online.