1 | /* |
2 | * BluezQt - Asynchronous BlueZ wrapper library |
3 | * |
4 | * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de> |
5 | * |
6 | * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
7 | */ |
8 | |
9 | #ifndef BLUEZQT_GATTCHARACTERISTIC_H |
10 | #define BLUEZQT_GATTCHARACTERISTIC_H |
11 | |
12 | #include "bluezqt_export.h" |
13 | |
14 | #include <QDBusObjectPath> |
15 | |
16 | #include <memory> |
17 | |
18 | namespace BluezQt |
19 | { |
20 | class GattService; |
21 | |
22 | /*! |
23 | * \inmodule BluezQt |
24 | * \class BluezQt::GattCharacteristic |
25 | * \inheaderfile BluezQt/GattCharacteristic |
26 | */ |
27 | class BLUEZQT_EXPORT GattCharacteristic : public QObject |
28 | { |
29 | Q_OBJECT |
30 | |
31 | public: |
32 | /*! |
33 | * Creates a new GattCharacteristic object with the given \a uuid and a parent \a service. |
34 | * |
35 | * This constructor creates a characteristic with the Read and Write flags set. |
36 | */ |
37 | explicit GattCharacteristic(const QString &uuid, GattService *service); |
38 | |
39 | /*! |
40 | * Creates a new GattCharacteristic object with the given \a uuid and a parent \a service. |
41 | * |
42 | * The \a flags can be used to indicate the characteristic usage. |
43 | * |
44 | * \since 6.0 |
45 | */ |
46 | GattCharacteristic(const QString &uuid, const QStringList &flags, GattService *service); |
47 | |
48 | ~GattCharacteristic() override; |
49 | |
50 | /*! |
51 | * Reads the value of the characteristic. |
52 | */ |
53 | QByteArray readValue(); |
54 | |
55 | /*! |
56 | * Writes the \a value of the characteristic. |
57 | */ |
58 | void writeValue(const QByteArray &value); |
59 | |
60 | /*! |
61 | * \typealias BluezQt::GattCharacteristic::ReadCallback |
62 | */ |
63 | using ReadCallback = std::function<QByteArray()>; |
64 | |
65 | /*! |
66 | * Provide a read \a callback to operate in \e pull mode. |
67 | */ |
68 | void setReadCallback(ReadCallback callback); |
69 | |
70 | /*! |
71 | * Returns the 128-bit GATT characteristic UUID. |
72 | */ |
73 | QString uuid() const; |
74 | |
75 | /*! |
76 | * The GATT service the characteristic belongs to. |
77 | */ |
78 | const GattService *service() const; |
79 | |
80 | /*! |
81 | * Returns flags associated with this characteristic. |
82 | * \since 6.0 |
83 | */ |
84 | QStringList flags() const; |
85 | |
86 | /*! |
87 | * Enables notifications for this characteristic, if supported. Does nothing otherwise. |
88 | * \since 6.0 |
89 | */ |
90 | void startNotify(); |
91 | |
92 | /*! |
93 | * Disables notifications for this characteristic. |
94 | * \since 6.0 |
95 | */ |
96 | void stopNotify(); |
97 | |
98 | /*! |
99 | * Indicates if this characteristic currently has notifications enabled. |
100 | * \since 6.0 |
101 | */ |
102 | bool isNotifying() const; |
103 | |
104 | Q_SIGNALS: |
105 | /*! |
106 | * Indicates that a \a value was written. |
107 | */ |
108 | void valueWritten(const QByteArray &value); |
109 | |
110 | protected: |
111 | /*! |
112 | * Returns the D-Bus object path of the GattCharacteristic. |
113 | * |
114 | * The path where the GattCharacteristic will be registered. |
115 | * |
116 | * \note You must provide valid object path! |
117 | */ |
118 | virtual QDBusObjectPath objectPath() const; |
119 | |
120 | private: |
121 | std::unique_ptr<class GattCharacterisiticPrivate> const d; |
122 | |
123 | friend class GattApplicationPrivate; |
124 | friend class GattCharacteristicAdaptor; |
125 | friend class GattDescriptor; |
126 | friend class GattDescriptorPrivate; |
127 | friend class GattManager; |
128 | }; |
129 | |
130 | } // namespace BluezQt |
131 | |
132 | #endif |
133 | |