| 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 "gattapplication.h" |
| 10 | |
| 11 | #include "gattapplication_p.h" |
| 12 | #include "gattcharacteristic.h" |
| 13 | #include "gattcharacteristicadaptor.h" |
| 14 | #include "gattdescriptor.h" |
| 15 | #include "gattdescriptoradaptor.h" |
| 16 | #include "gattservice.h" |
| 17 | #include "gattserviceadaptor.h" |
| 18 | |
| 19 | #include <QDBusObjectPath> |
| 20 | #include <QMetaProperty> |
| 21 | |
| 22 | namespace BluezQt |
| 23 | { |
| 24 | GattApplication::GattApplication(QObject *parent) |
| 25 | : GattApplication(QStringLiteral("/org/kde/bluezqt" ), parent) |
| 26 | { |
| 27 | } |
| 28 | |
| 29 | GattApplication::GattApplication(const QString &objectPathPrefix, QObject *parent) |
| 30 | : QObject(parent) |
| 31 | , d(new GattApplicationPrivate(objectPathPrefix, this)) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | GattApplication::~GattApplication() = default; |
| 36 | |
| 37 | DBusManagerStruct GattApplicationPrivate::getManagedObjects() const |
| 38 | { |
| 39 | DBusManagerStruct objects; |
| 40 | |
| 41 | const auto serviceAdaptors = q->findChildren<GattServiceAdaptor *>(); |
| 42 | const auto charcAdaptors = q->findChildren<GattCharacteristicAdaptor *>(); |
| 43 | const auto descriptorAdaptors = q->findChildren<GattDescriptorAdaptor *>(); |
| 44 | |
| 45 | for (const GattServiceAdaptor *serviceAdaptor : serviceAdaptors) { |
| 46 | QVariantMap properties; |
| 47 | for (int i = serviceAdaptor->metaObject()->propertyOffset(); i < serviceAdaptor->metaObject()->propertyCount(); ++i) { |
| 48 | auto propertyName = serviceAdaptor->metaObject()->property(index: i).name(); |
| 49 | properties.insert(key: QString::fromLatin1(ba: propertyName), value: serviceAdaptor->property(name: propertyName)); |
| 50 | } |
| 51 | |
| 52 | GattService *service = qobject_cast<GattService *>(object: serviceAdaptor->parent()); |
| 53 | if (service) { |
| 54 | objects[service->objectPath()].insert(QStringLiteral("org.bluez.GattService1" ), value: properties); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | for (const GattCharacteristicAdaptor *charcAdaptor : charcAdaptors) { |
| 59 | QVariantMap properties; |
| 60 | for (int i = charcAdaptor->metaObject()->propertyOffset(); i < charcAdaptor->metaObject()->propertyCount(); ++i) { |
| 61 | auto propertyName = charcAdaptor->metaObject()->property(index: i).name(); |
| 62 | properties.insert(key: QString::fromLatin1(ba: propertyName), value: charcAdaptor->property(name: propertyName)); |
| 63 | } |
| 64 | |
| 65 | GattCharacteristic *charc = qobject_cast<GattCharacteristic *>(object: charcAdaptor->parent()); |
| 66 | if (charc) { |
| 67 | objects[charc->objectPath()].insert(QStringLiteral("org.bluez.GattCharacteristic1" ), value: properties); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | for (const GattDescriptorAdaptor *descAdaptor : descriptorAdaptors) { |
| 72 | QVariantMap properties; |
| 73 | for (int i = descAdaptor->metaObject()->propertyOffset(); i < descAdaptor->metaObject()->propertyCount(); ++i) { |
| 74 | auto propertyName = descAdaptor->metaObject()->property(index: i).name(); |
| 75 | properties.insert(key: QString::fromLatin1(ba: propertyName), value: descAdaptor->property(name: propertyName)); |
| 76 | } |
| 77 | |
| 78 | GattDescriptor *desc = qobject_cast<GattDescriptor *>(object: descAdaptor->parent()); |
| 79 | if (desc) { |
| 80 | objects[desc->objectPath()].insert(QStringLiteral("org.bluez.GattDescriptor1" ), value: properties); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | return objects; |
| 85 | } |
| 86 | |
| 87 | QDBusObjectPath GattApplication::objectPath() const |
| 88 | { |
| 89 | return d->m_objectPath; |
| 90 | } |
| 91 | |
| 92 | } // namespace BluezQt |
| 93 | |
| 94 | #include "moc_gattapplication.cpp" |
| 95 | |