File indexing completed on 2024-12-01 12:29:47
0001 /* 0002 * BluezQt - Asynchronous Bluez wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2021 Ivan Podkurkov <podkiva2@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_GATTCHARACTERISTICREMOTE_H 0010 #define BLUEZQT_GATTCHARACTERISTICREMOTE_H 0011 0012 #include "bluezqt_export.h" 0013 #include "gattdescriptorremote.h" 0014 #include "types.h" 0015 #include <QList> 0016 #include <QMap> 0017 #include <QObject> 0018 namespace BluezQt 0019 { 0020 0021 class GattServiceRemote; 0022 class PendingCall; 0023 0024 /** 0025 * @class BluezQt::GattCharacteristicRemote gattcharacteristicremote.h <BluezQt/GattCharacteristicRemote> 0026 * 0027 * Bluetooth LE GATT characteristic. 0028 * 0029 * This class represents a Bluetooth LE GATT characteristic for the clients. 0030 */ 0031 class BLUEZQT_EXPORT GattCharacteristicRemote : public QObject 0032 { 0033 Q_OBJECT 0034 Q_PROPERTY(QString ubi READ ubi CONSTANT) 0035 Q_PROPERTY(QString uuid READ uuid NOTIFY uuidChanged) 0036 Q_PROPERTY(QByteArray value READ value NOTIFY valueChanged) 0037 Q_PROPERTY(bool writeAcquired READ isWriteAcquired NOTIFY writeAcquiredChanged) 0038 Q_PROPERTY(bool notifyAcquired READ isNotifyAcquired NOTIFY notifyAcquiredChanged) 0039 Q_PROPERTY(bool notifying READ isNotifying NOTIFY notifyingChanged) 0040 Q_PROPERTY(QStringList flags READ flags NOTIFY flagsChanged) 0041 Q_PROPERTY(quint16 handle READ handle NOTIFY handleChanged) 0042 Q_PROPERTY(quint16 MTU READ MTU NOTIFY MTUChanged) 0043 Q_PROPERTY(GattServiceRemotePtr service READ service CONSTANT) 0044 Q_PROPERTY(QList<GattDescriptorRemotePtr> descriptors READ descriptors NOTIFY descriptorsChanged) 0045 0046 0047 public: 0048 /** 0049 * Destroys a GattCharacteristic object. 0050 */ 0051 ~GattCharacteristicRemote() override; 0052 0053 /** 0054 * Returns a shared pointer from this. 0055 * 0056 * @return DevicePtr 0057 */ 0058 GattCharacteristicRemotePtr toSharedPtr() const; 0059 0060 /** 0061 * Returns an UBI of the GATT characteristic. 0062 * 0063 * Example UBI: "/org/bluez/hci0/dev_40_79_6A_0C_39_75" 0064 * 0065 * @return UBI of device 0066 */ 0067 QString ubi() const; 0068 0069 /** 0070 * Returns an uuid of the characteristic. 0071 * 0072 * @return uuid of the characteristic 0073 */ 0074 QString uuid() const; 0075 0076 /** 0077 * Returns an value of the characteristic. 0078 * 0079 * @return value of the characteristic 0080 */ 0081 QByteArray value() const; 0082 0083 /** 0084 * Returns whether writeAcquired for the characteristic. 0085 * 0086 * @return true if write is acquired 0087 */ 0088 bool isWriteAcquired() const; 0089 0090 /** 0091 * Returns whether notifyAcquired for the characteristic. 0092 * 0093 * @return true if notify is acquired 0094 */ 0095 bool isNotifyAcquired() const; 0096 0097 /** 0098 * Returns whether the characteristic is notifying. 0099 * 0100 * @return true if notifying 0101 */ 0102 bool isNotifying() const; 0103 0104 /** 0105 * Returns flags the characteristic. 0106 * 0107 * @return flags of characteristic 0108 */ 0109 QStringList flags() const; 0110 0111 /** 0112 * Returns characteristic handle. 0113 * 0114 * @return qint16 characteristic handle 0115 */ 0116 quint16 handle() const; 0117 0118 /** 0119 * Sets the characteristic handle. 0120 * 0121 * @param handle characteristic handle 0122 * @return void pending call 0123 */ 0124 PendingCall *setHandle(quint16 handle); 0125 0126 /** 0127 * Returns characteristic MTU. 0128 * 0129 * @return qint16 characteristic MTU 0130 */ 0131 quint16 MTU() const; 0132 0133 /** 0134 * Returns a service that owns that characteristic. 0135 * 0136 * @return service of characteristic 0137 */ 0138 GattServiceRemotePtr service() const; 0139 0140 /** 0141 * Returns object paths representing the included 0142 * services of this service. 0143 * 0144 * @return Object paths of included services 0145 */ 0146 QList<GattDescriptorRemotePtr> descriptors() const; 0147 0148 public Q_SLOTS: 0149 /** 0150 * Read the value of the GATT characteristic. 0151 * 0152 * Issues a request to read the value of the characteristic and 0153 * returns the value if the operation was successful. 0154 * 0155 * Possible errors: PendingCall::NotReady, PendingCall::Failed, 0156 * PendingCall::InProgress, PendingCall::AlreadyConnected 0157 * 0158 * @return QByteArray pending call 0159 */ 0160 PendingCall *readValue(const QVariantMap &options); 0161 0162 /** 0163 * Write the value of the GATT characteristic. 0164 * 0165 * Issues a request to write the value of the characteristic. 0166 * 0167 * Possible errors: PendingCall::NotReady, PendingCall::Failed, 0168 * PendingCall::InProgress, PendingCall::AlreadyConnected 0169 * 0170 * @return void pending call 0171 */ 0172 PendingCall *writeValue(const QByteArray &value, const QVariantMap &options); 0173 0174 /** 0175 * Start notifying the value of the GATT characteristic. 0176 * 0177 * Starts a notification session from this characteristic if it supports 0178 * value notifications or indications. 0179 * 0180 * Possible errors: PendingCall::NotReady, PendingCall::Failed, 0181 * PendingCall::InProgress, PendingCall::AlreadyConnected 0182 * 0183 * @return void pending call 0184 */ 0185 PendingCall *startNotify(); 0186 0187 /** 0188 * Stop notifying the value of the GATT characteristic. 0189 * 0190 * This method will cancel any previous StartNotify transaction. 0191 * Note that notifications from a characteristic are shared between 0192 * sessions thus calling StopNotify will release a single session. 0193 * 0194 * Possible errors: PendingCall::NotReady, PendingCall::Failed, 0195 * PendingCall::InProgress, PendingCall::AlreadyConnected 0196 * 0197 * @return void pending call 0198 */ 0199 PendingCall *stopNotify(); 0200 0201 /** 0202 * Confirmation that value of the characteristic was received. 0203 * 0204 * This method doesn't expect a reply so it is just a confirmation 0205 * that value was received. 0206 * 0207 * Possible errors: PendingCall::NotReady, PendingCall::Failed, 0208 * PendingCall::InProgress, PendingCall::AlreadyConnected 0209 * 0210 * @return void pending call 0211 */ 0212 PendingCall *confirm(); 0213 0214 Q_SIGNALS: 0215 /** 0216 * Indicates that at least one of the characteristic's properties have changed. 0217 */ 0218 void characteristicChanged(GattCharacteristicRemotePtr characteristic); 0219 0220 /** 0221 * Indicates that a new descriptor was added (eg. found by connection). 0222 */ 0223 void gattDescriptorAdded(GattDescriptorRemotePtr descriptor); 0224 0225 /** 0226 * Indicates that characteristic descriptors list has changed 0227 */ 0228 void descriptorsChanged(QList<GattDescriptorRemotePtr> descriptors); 0229 0230 /** 0231 * Indicates that a descriptor was removed. 0232 */ 0233 void gattDescriptorRemoved(GattDescriptorRemotePtr descriptor); 0234 0235 /** 0236 * Indicates that at least one of the descriptor's properties have changed. 0237 */ 0238 void gattDescriptorChanged(GattDescriptorRemotePtr descriptor); 0239 0240 /** 0241 * Indicates that characteristic's uuid have changed. 0242 */ 0243 void uuidChanged(const QString &uuid); 0244 0245 /** 0246 * Indicates that characteristic's value have changed. 0247 */ 0248 void valueChanged(const QByteArray value); 0249 0250 /** 0251 * Indicates that characteristic's writeAcquired state have changed. 0252 */ 0253 void writeAcquiredChanged(bool writeAcquired); 0254 0255 /** 0256 * Indicates that characteristic's notifyAcquired state have changed. 0257 */ 0258 void notifyAcquiredChanged(bool notifyAcquired); 0259 0260 /** 0261 * Indicates that characteristic's notifying state have changed. 0262 */ 0263 void notifyingChanged(bool notifying); 0264 0265 /** 0266 * Indicates that characteristic's flags have changed. 0267 */ 0268 void flagsChanged(QStringList flags); 0269 0270 /** 0271 * Indicates that characteristic's handle have changed. 0272 */ 0273 void handleChanged(quint16 handle); 0274 0275 /** 0276 * Indicates that characteristic's MTU have changed. 0277 */ 0278 void MTUChanged(quint16 MTU); 0279 0280 private: 0281 BLUEZQT_NO_EXPORT explicit GattCharacteristicRemote(const QString &path, const QVariantMap &properties, GattServiceRemotePtr service); 0282 0283 const std::unique_ptr<class GattCharacteristicRemotePrivate> d; 0284 0285 friend class DevicePrivate; 0286 friend class GattServiceRemotePrivate; 0287 friend class GattCharacteristicRemotePrivate; 0288 friend class ManagerPrivate; 0289 friend class Adapter; 0290 }; 0291 0292 } // namespace BluezQt 0293 0294 #endif // BLUEZQT_GATTCHARACTERISTICREMOTE_H