BluezQt

gattcharacteristic.h
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
18namespace BluezQt
19{
20class GattService;
21
22class BLUEZQT_EXPORT GattCharacteristic : public QObject
23{
24 Q_OBJECT
25
26public:
27 /**
28 * Creates a new GattCharacteristic object.
29 *
30 * This constructor creates a characteristic with the Read and Write flags set.
31 *
32 * @param uuid The UUID of the characteristic.
33 * @param service The parent service.
34 */
35 explicit GattCharacteristic(const QString &uuid, GattService *service);
36
37 /**
38 * Creates a new GattCharacteristic object.
39 *
40 * @param uuid The UUID of the characteristic.
41 * @param flags Flags indicating the characteristic usage.
42 * @param service The parent service.
43 *
44 * @since 6.0
45 */
46 GattCharacteristic(const QString &uuid, const QStringList &flags, GattService *service);
47
48 /**
49 * Destroys a GattCharacteristic object.
50 */
51 ~GattCharacteristic() override;
52
53 /**
54 * Reads the value of the characteristic.
55 */
56 QByteArray readValue();
57
58 /**
59 * Writes the value of the characteristic.
60 */
61 void writeValue(const QByteArray &value);
62
63 /**
64 * Provide a read callback to operate in *pull* mode.
65 */
66 using ReadCallback = std::function<QByteArray()>;
67 void setReadCallback(ReadCallback callback);
68
69 /**
70 * 128-bit GATT characteristic UUID.
71 *
72 * @return uuid of characteristic
73 */
74 QString uuid() const;
75
76 /**
77 * The GATT service the characteristic belongs to.
78 *
79 * @return service this characteristic belongs to
80 */
81 const GattService *service() const;
82
83 /**
84 * The flags of this characteristic.
85 *
86 * @return flags associated with this characteristic
87 *
88 * @since 6.0
89 */
90 QStringList flags() const;
91
92 /**
93 * Enables notifications for this characteristic, if supported. Does nothing otherwise.
94 *
95 * @since 6.0
96 */
97 void startNotify();
98
99 /**
100 * Disables notifications for this characteristic.
101 *
102 * @since 6.0
103 */
104 void stopNotify();
105
106 /**
107 * Indicates if this characteristic currently has notifications enabled.
108 *
109 * @return True if notifications are enabled, false otherwise
110 *
111 * @since 6.0
112 */
113 bool isNotifying() const;
114
115Q_SIGNALS:
116 /**
117 * Indicates that a value was written.
118 */
119 void valueWritten(const QByteArray &value);
120
121protected:
122 /**
123 * D-Bus object path of the GattCharacteristic.
124 *
125 * The path where the GattCharacteristic will be registered.
126 *
127 * @note You must provide valid object path!
128 *
129 * @return object path of GattCharacteristic
130 */
131 virtual QDBusObjectPath objectPath() const;
132
133private:
134 std::unique_ptr<class GattCharacterisiticPrivate> const d;
135
136 friend class GattApplicationPrivate;
137 friend class GattCharacteristicAdaptor;
138 friend class GattDescriptor;
139 friend class GattDescriptorPrivate;
140 friend class GattManager;
141};
142
143} // namespace BluezQt
144
145#endif
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:46:08 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.