File indexing completed on 2024-04-28 15:17:52

0001 /*
0002  * BluezQt - Asynchronous Bluez wrapper library
0003  *
0004  * SPDX-FileCopyrightText: 2021 Ivan Podkurkov <podkiva2@gmail.com>
0005  *
0006  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0007  */
0008 
0009 #include "gattdescriptorremote_p.h"
0010 #include "gattdescriptorremote.h"
0011 #include "device_p.h"
0012 #include "device.h"
0013 #include "adapter.h"
0014 #include "input.h"
0015 #include "input_p.h"
0016 #include "mediaplayer.h"
0017 #include "mediaplayer_p.h"
0018 #include "utils.h"
0019 #include "macros.h"
0020 
0021 namespace BluezQt
0022 {
0023 
0024 GattDescriptorRemotePrivate::GattDescriptorRemotePrivate(const QString &path, const QVariantMap &properties, const GattCharacteristicRemotePtr &characteristic)
0025     : QObject()
0026     , m_dbusProperties(nullptr)
0027     , m_handle()
0028     , m_characteristic(characteristic)
0029 {
0030     m_bluezGattDescriptor = new BluezGattDescriptor(Strings::orgBluez(), path, DBusConnection::orgBluez(), this);
0031 
0032     init(properties);
0033 }
0034 
0035 void GattDescriptorRemotePrivate::init(const QVariantMap &properties)
0036 {
0037     m_dbusProperties = new DBusProperties(Strings::orgBluez(), m_bluezGattDescriptor->path(),
0038                                           DBusConnection::orgBluez(), this);
0039 
0040     // Init properties
0041     m_uuid = properties.value(QStringLiteral("UUID")).toString();
0042     m_value = properties.value(QStringLiteral("Value")).toByteArray();
0043     m_flags = properties.value(QStringLiteral("Flags")).toStringList();
0044     m_handle = properties.value(QStringLiteral("Handle")).value<quint16>();
0045 }
0046 
0047 QDBusPendingReply<> GattDescriptorRemotePrivate::setDBusProperty(const QString &name, const QVariant &value)
0048 {
0049     return m_dbusProperties->Set(Strings::orgBluezGattDescriptor1(), name, QDBusVariant(value));
0050 }
0051 
0052 void GattDescriptorRemotePrivate::propertiesChanged(const QString &path, const QString &interface, const QVariantMap &changed, const QStringList &invalidated)
0053 {
0054     Q_UNUSED(path)
0055 
0056     if (interface != Strings::orgBluezGattDescriptor1()) {
0057         return;
0058     }
0059 
0060     QVariantMap::const_iterator i;
0061     for (i = changed.constBegin(); i != changed.constEnd(); ++i) {
0062         const QVariant &value = i.value();
0063         const QString &property = i.key();
0064 
0065         if (property == QLatin1String("UUID")) {
0066             PROPERTY_CHANGED(m_uuid, toString, uuidChanged);
0067         } else if (property == QLatin1String("Value")) {
0068             PROPERTY_CHANGED(m_value, toByteArray, valueChanged);
0069         } else if (property == QLatin1String("Flags")) {
0070             PROPERTY_CHANGED2(m_flags, value.toStringList(), flagsChanged);
0071         } else if (property == QLatin1String("Handle")) {
0072             PROPERTY_CHANGED2(m_handle, value.value<quint16>(), handleChanged);
0073         }
0074     }
0075 
0076     for (auto& property : invalidated) {
0077         if (property == QLatin1String("UUID")) {
0078             PROPERTY_INVALIDATED(m_uuid, QString(), uuidChanged);
0079         } else if (property == QLatin1String("Value")) {
0080             PROPERTY_INVALIDATED(m_value, QByteArray(), valueChanged);
0081         } else if (property == QLatin1String("Flags")) {
0082             PROPERTY_INVALIDATED(m_flags, QStringList(), flagsChanged);
0083         } else if (property == QLatin1String("Handle")) {
0084             PROPERTY_INVALIDATED(m_handle, quint16(), handleChanged);
0085         }
0086     }
0087 
0088     Q_EMIT q.lock().data()->descriptorChanged(q.toStrongRef());
0089 }
0090 
0091 } // namespace BluezQt
0092 
0093 #include "moc_gattdescriptorremote_p.cpp"