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#include "gattcharacteristic.h"
10#include "gattcharacteristic_p.h"
11#include "gattservice.h"
12#include "utils.h"
13
14namespace BluezQt
15{
16GattCharacteristic::GattCharacteristic(const QString &uuid, GattService *service)
17 : GattCharacteristic(uuid, {QLatin1String("read"), QLatin1String("write")}, service)
18{
19}
20
21GattCharacteristic::GattCharacteristic(const QString &uuid, const QStringList &flags, GattService *service)
22 : QObject(service)
23 , d(new GattCharacterisiticPrivate(uuid, flags, service))
24{
25}
26
27GattCharacteristic::~GattCharacteristic() = default;
28
29QByteArray GattCharacteristic::readValue()
30{
31 if (d->m_readCallback) {
32 d->m_value = d->m_readCallback();
33 }
34
35 return d->m_value;
36}
37
38void GattCharacteristic::writeValue(const QByteArray &value)
39{
40 d->m_value = value;
41
42 if (isNotifying()) {
43 d->emitPropertyChanged(updatedProperties: {{QLatin1String("Value"), value}});
44 }
45
46 Q_EMIT valueWritten(value: d->m_value);
47}
48
49QString GattCharacteristic::uuid() const
50{
51 return d->m_uuid;
52}
53
54const GattService *GattCharacteristic::service() const
55{
56 return d->m_service;
57}
58
59QStringList GattCharacteristic::flags() const
60{
61 return d->m_flags;
62}
63
64void GattCharacteristic::startNotify()
65{
66 if (d->m_canNotify) {
67 d->m_notifying = true;
68 }
69}
70
71void GattCharacteristic::stopNotify()
72{
73 d->m_notifying = false;
74}
75
76bool GattCharacteristic::isNotifying() const
77{
78 return d->m_notifying;
79}
80
81QDBusObjectPath GattCharacteristic::objectPath() const
82{
83 return d->m_objectPath;
84}
85
86void GattCharacteristic::setReadCallback(ReadCallback callback)
87{
88 d->m_readCallback = callback;
89}
90
91} // namespace BluezQt
92
93#include "moc_gattcharacteristic.cpp"
94

source code of bluez-qt/src/gattcharacteristic.cpp