File indexing completed on 2024-12-01 12:29:51
0001 /* 0002 * BluezQt - Asynchronous BlueZ wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2014-2015 David Rosca <nowrep@gmail.com> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef BLUEZQT_PENDINGCALL_H 0010 #define BLUEZQT_PENDINGCALL_H 0011 0012 #include <functional> 0013 0014 #include <QObject> 0015 0016 #include "bluezqt_export.h" 0017 0018 class QDBusError; 0019 class QDBusPendingCall; 0020 class QDBusPendingCallWatcher; 0021 0022 namespace BluezQt 0023 { 0024 /** 0025 * @class BluezQt::PendingCall pendingcall.h <BluezQt/PendingCall> 0026 * 0027 * Pending method call. 0028 * 0029 * This class represents a pending method call. It is a convenient wrapper 0030 * around QDBusPendingReply and QDBusPendingCallWatcher. 0031 */ 0032 class BLUEZQT_EXPORT PendingCall : public QObject 0033 { 0034 Q_OBJECT 0035 0036 Q_PROPERTY(QVariant value READ value) 0037 Q_PROPERTY(QVariantList values READ values) 0038 Q_PROPERTY(int error READ error) 0039 Q_PROPERTY(QString errorText READ errorText) 0040 Q_PROPERTY(bool isFinished READ isFinished) 0041 Q_PROPERTY(QVariant userData READ userData WRITE setUserData) 0042 0043 public: 0044 /** 0045 * Known error types. 0046 */ 0047 enum Error { 0048 /** Indicates there is no error. */ 0049 NoError = 0, 0050 /** Indicates that the device is not ready. */ 0051 NotReady = 1, 0052 /** Indicates that the action have failed. */ 0053 Failed = 2, 0054 /** Indicates that the action was rejected. */ 0055 Rejected = 3, 0056 /** Indicates that the action was canceled. */ 0057 Canceled = 4, 0058 /** Indicates that invalid arguments were passed. */ 0059 InvalidArguments = 5, 0060 /** Indicates that an agent or pairing record already exists. */ 0061 AlreadyExists = 6, 0062 /** Indicates that an agent, service or pairing operation does not exists. */ 0063 DoesNotExist = 7, 0064 /** Indicates that the action is already in progress. */ 0065 InProgress = 8, 0066 /** Indicates that the action is not in progress. */ 0067 NotInProgress = 9, 0068 /** Indicates that the device is already connected. */ 0069 AlreadyConnected = 10, 0070 /** Indicates that the connection to the device have failed. */ 0071 ConnectFailed = 11, 0072 /** Indicates that the device is not connected. */ 0073 NotConnected = 12, 0074 /** Indicates that the action is not supported. */ 0075 NotSupported = 13, 0076 /** Indicates that the caller is not authorized to do the action. */ 0077 NotAuthorized = 14, 0078 /** Indicates that the authentication was canceled. */ 0079 AuthenticationCanceled = 15, 0080 /** Indicates that the authentication have failed. */ 0081 AuthenticationFailed = 16, 0082 /** Indicates that the authentication was rejected. */ 0083 AuthenticationRejected = 17, 0084 /** Indicates that the authentication timed out. */ 0085 AuthenticationTimeout = 18, 0086 /** Indicates that the connection attempt have failed. */ 0087 ConnectionAttemptFailed = 19, 0088 /** Indicates that the data provided generates a data packet which is too long. */ 0089 InvalidLength = 20, 0090 /** Indicates that the action is not permitted (e.g. maximum reached or socket locked). */ 0091 NotPermitted = 21, 0092 /** Indicates an error with D-Bus. */ 0093 DBusError = 98, 0094 /** Indicates an internal error. */ 0095 InternalError = 99, 0096 /** Indicates an unknown error. */ 0097 UnknownError = 100, 0098 }; 0099 Q_ENUM(Error) 0100 0101 /** 0102 * Destroys a PendingCall object. 0103 */ 0104 ~PendingCall() override; 0105 0106 /** 0107 * Returns a first return value of the call. 0108 * 0109 * @return first return value 0110 */ 0111 QVariant value() const; 0112 0113 /** 0114 * Returns all values of the call. 0115 * 0116 * @return all return values 0117 */ 0118 QVariantList values() const; 0119 0120 /** 0121 * Returns an error code. 0122 * 0123 * @return error code 0124 * @see Error 0125 */ 0126 int error() const; 0127 0128 /** 0129 * Returns an error text. 0130 * 0131 * @return error text 0132 */ 0133 QString errorText() const; 0134 0135 /** 0136 * Returns whether the call is finished. 0137 * 0138 * @return true if call is finished 0139 */ 0140 bool isFinished() const; 0141 0142 /** 0143 * Waits for the call to finish. 0144 * 0145 * @warning This method blocks until the call finishes! 0146 */ 0147 void waitForFinished(); 0148 0149 /** 0150 * Returns the user data of the call. 0151 * 0152 * @return user data of call 0153 */ 0154 QVariant userData() const; 0155 0156 /** 0157 * Sets the user data of the call. 0158 * 0159 * @param userData user data 0160 */ 0161 void setUserData(const QVariant &userData); 0162 0163 Q_SIGNALS: 0164 /** 0165 * Indicates that the call have finished. 0166 */ 0167 void finished(PendingCall *call); 0168 0169 private: 0170 enum ReturnType { 0171 ReturnVoid, 0172 ReturnUint32, 0173 ReturnString, 0174 ReturnStringList, 0175 ReturnObjectPath, 0176 ReturnFileTransferList, 0177 ReturnTransferWithProperties, 0178 ReturnByteArray 0179 }; 0180 0181 BLUEZQT_NO_EXPORT explicit PendingCall(Error error, const QString &errorText, QObject *parent = nullptr); 0182 BLUEZQT_NO_EXPORT explicit PendingCall(const QDBusPendingCall &call, ReturnType type, QObject *parent = nullptr); 0183 0184 // exported because called from template BluezQt::TPendingCall constructor 0185 using ErrorProcessor = std::function<void(const QDBusError &error)>; 0186 using ExternalProcessor = std::function<void(QDBusPendingCallWatcher *watcher, ErrorProcessor errorProcessor, QVariantList *values)>; 0187 explicit PendingCall(const QDBusPendingCall &call, ExternalProcessor externalProcessor, QObject *parent = nullptr); 0188 0189 class PendingCallPrivate *const d; 0190 0191 friend class PendingCallPrivate; 0192 friend class Manager; 0193 friend class Adapter; 0194 friend class GattServiceRemote; 0195 friend class GattCharacteristicRemote; 0196 friend class GattDescriptorRemote; 0197 friend class Device; 0198 friend class GattManager; 0199 friend class LEAdvertisingManager; 0200 friend class Media; 0201 friend class MediaPlayer; 0202 friend class ObexManager; 0203 friend class ObexTransfer; 0204 friend class ObexSession; 0205 friend class ObexObjectPush; 0206 friend class ObexFileTransfer; 0207 template<class... T> 0208 friend class TPendingCall; 0209 }; 0210 0211 } // namespace BluezQt 0212 0213 #endif // BLUEZQT_PENDINGCALL_H