| 1 |
/* |
| 2 |
* BluezQt - Asynchronous Bluez wrapper library |
| 3 |
* |
| 4 |
* SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <[email protected]> |
| 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(i).name(); |
| 49 |
properties.insert(QString::fromLatin1(propertyName), serviceAdaptor->property(propertyName)); |
| 50 |
} |
| 51 |
|
| 52 |
GattService *service = qobject_cast<GattService *>(serviceAdaptor->parent()); |
| 53 |
if (service) { |
| 54 |
objects[service->objectPath()].insert(QStringLiteral("org.bluez.GattService1"), 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(i).name(); |
| 62 |
properties.insert(QString::fromLatin1(propertyName), charcAdaptor->property(propertyName)); |
| 63 |
} |
| 64 |
|
| 65 |
GattCharacteristic *charc = qobject_cast<GattCharacteristic *>(charcAdaptor->parent()); |
| 66 |
if (charc) { |
| 67 |
objects[charc->objectPath()].insert(QStringLiteral("org.bluez.GattCharacteristic1"), 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(i).name(); |
| 75 |
properties.insert(QString::fromLatin1(propertyName), descAdaptor->property(propertyName)); |
| 76 |
} |
| 77 |
|
| 78 |
GattDescriptor *desc = qobject_cast<GattDescriptor *>(descAdaptor->parent()); |
| 79 |
if (desc) { |
| 80 |
objects[desc->objectPath()].insert(QStringLiteral("org.bluez.GattDescriptor1"), 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" |