File indexing completed on 2024-12-08 12:15:33
0001 /* 0002 * BluezQt - Asynchronous BlueZ wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #ifndef BLUEZQT_GATTCHARACTERISTIC_H 0010 #define BLUEZQT_GATTCHARACTERISTIC_H 0011 0012 #include "bluezqt_export.h" 0013 0014 #include <QDBusObjectPath> 0015 0016 namespace BluezQt 0017 { 0018 class GattService; 0019 0020 class BLUEZQT_EXPORT GattCharacteristic : public QObject 0021 { 0022 Q_OBJECT 0023 0024 public: 0025 /** 0026 * Creates a new GattCharacteristic object. 0027 * 0028 * @param parent 0029 */ 0030 explicit GattCharacteristic(const QString &uuid, GattService *service); 0031 0032 /** 0033 * Destroys a GattCharacteristic object. 0034 */ 0035 ~GattCharacteristic() override; 0036 0037 /** 0038 * Reads the value of the characteristic. 0039 */ 0040 QByteArray readValue(); 0041 0042 /** 0043 * Writes the value of the characteristic. 0044 */ 0045 void writeValue(const QByteArray &value); 0046 0047 /** 0048 * Provide a read callback to operate in *pull* mode. 0049 */ 0050 using ReadCallback = std::function<QByteArray()>; 0051 void setReadCallback(ReadCallback callback); 0052 0053 /** 0054 * 128-bit GATT characteristic UUID. 0055 * 0056 * @return uuid of characteristic 0057 */ 0058 QString uuid() const; 0059 0060 /** 0061 * The GATT service the characteristic belongs to. 0062 * 0063 * @return service this characteristic belongs to 0064 */ 0065 const GattService *service() const; 0066 0067 Q_SIGNALS: 0068 /** 0069 * Indicates that a value was written. 0070 */ 0071 void valueWritten(const QByteArray &value); 0072 0073 protected: 0074 /** 0075 * D-Bus object path of the GattCharacteristic. 0076 * 0077 * The path where the GattCharacteristic will be registered. 0078 * 0079 * @note You must provide valid object path! 0080 * 0081 * @return object path of GattCharacteristic 0082 */ 0083 virtual QDBusObjectPath objectPath() const; 0084 0085 private: 0086 class GattCharacterisiticPrivate *const d; 0087 0088 friend class GattApplicationPrivate; 0089 friend class GattCharacteristicAdaptor; 0090 friend class GattManager; 0091 }; 0092 0093 } // namespace BluezQt 0094 0095 #endif