1/*
2 * BluezQt - Asynchronous Bluez wrapper library
3 *
4 * SPDX-FileCopyrightText: 2021 Ivan Podkurkov <podkiva2@gmail.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "gattdescriptorremote_p.h"
10#include "gattdescriptorremote.h"
11#include "device_p.h"
12#include "device.h"
13#include "adapter.h"
14#include "input.h"
15#include "input_p.h"
16#include "mediaplayer.h"
17#include "mediaplayer_p.h"
18#include "utils.h"
19#include "macros.h"
20
21namespace BluezQt
22{
23
24GattDescriptorRemotePrivate::GattDescriptorRemotePrivate(const QString &path, const QVariantMap &properties, const GattCharacteristicRemotePtr &characteristic)
25 : QObject()
26 , m_dbusProperties(nullptr)
27 , m_handle()
28 , m_characteristic(characteristic)
29{
30 m_bluezGattDescriptor = new BluezGattDescriptor(Strings::orgBluez(), path, DBusConnection::orgBluez(), this);
31
32 init(properties);
33}
34
35void GattDescriptorRemotePrivate::init(const QVariantMap &properties)
36{
37 m_dbusProperties = new DBusProperties(Strings::orgBluez(), m_bluezGattDescriptor->path(),
38 DBusConnection::orgBluez(), this);
39
40 // Init properties
41 m_uuid = properties.value(QStringLiteral("UUID")).toString();
42 m_value = properties.value(QStringLiteral("Value")).toByteArray();
43 m_flags = properties.value(QStringLiteral("Flags")).toStringList();
44 m_handle = properties.value(QStringLiteral("Handle")).value<quint16>();
45}
46
47QDBusPendingReply<> GattDescriptorRemotePrivate::setDBusProperty(const QString &name, const QVariant &value)
48{
49 return m_dbusProperties->Set(interface_name: Strings::orgBluezGattDescriptor1(), property_name: name, value: QDBusVariant(value));
50}
51
52void GattDescriptorRemotePrivate::propertiesChanged(const QString &path, const QString &interface, const QVariantMap &changed, const QStringList &invalidated)
53{
54 Q_UNUSED(path)
55
56 if (interface != Strings::orgBluezGattDescriptor1()) {
57 return;
58 }
59
60 QVariantMap::const_iterator i;
61 for (i = changed.constBegin(); i != changed.constEnd(); ++i) {
62 const QVariant &value = i.value();
63 const QString &property = i.key();
64
65 if (property == QLatin1String("UUID")) {
66 PROPERTY_CHANGED(m_uuid, toString, uuidChanged);
67 } else if (property == QLatin1String("Value")) {
68 PROPERTY_CHANGED(m_value, toByteArray, valueChanged);
69 } else if (property == QLatin1String("Flags")) {
70 PROPERTY_CHANGED2(m_flags, value.toStringList(), flagsChanged);
71 } else if (property == QLatin1String("Handle")) {
72 PROPERTY_CHANGED2(m_handle, value.value<quint16>(), handleChanged);
73 }
74 }
75
76 for (auto& property : invalidated) {
77 if (property == QLatin1String("UUID")) {
78 PROPERTY_INVALIDATED(m_uuid, QString(), uuidChanged);
79 } else if (property == QLatin1String("Value")) {
80 PROPERTY_INVALIDATED(m_value, QByteArray(), valueChanged);
81 } else if (property == QLatin1String("Flags")) {
82 PROPERTY_INVALIDATED(m_flags, QStringList(), flagsChanged);
83 } else if (property == QLatin1String("Handle")) {
84 PROPERTY_INVALIDATED(m_handle, quint16(), handleChanged);
85 }
86 }
87
88 Q_EMIT q.lock().data()->descriptorChanged(descriptor: q.toStrongRef());
89}
90
91} // namespace BluezQt
92
93#include "moc_gattdescriptorremote_p.cpp"
94

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