File indexing completed on 2024-12-01 12:29:47
0001 /* 0002 * BluezQt - Asynchronous Bluez wrapper library 0003 * 0004 * SPDX-FileCopyrightText: 2019 Manuel Weichselbaumer <mincequi@web.de> 0005 * 0006 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "gattapplication.h" 0010 0011 #include "gattapplication_p.h" 0012 #include "gattcharacteristic.h" 0013 #include "gattcharacteristicadaptor.h" 0014 #include "gattservice.h" 0015 #include "gattserviceadaptor.h" 0016 0017 #include <QDBusObjectPath> 0018 #include <QMetaProperty> 0019 0020 namespace BluezQt 0021 { 0022 GattApplication::GattApplication(QObject *parent) 0023 : GattApplication(QStringLiteral("/org/kde/bluezqt"), parent) 0024 { 0025 } 0026 0027 GattApplication::GattApplication(const QString &objectPathPrefix, QObject *parent) 0028 : QObject(parent) 0029 , d(new GattApplicationPrivate(objectPathPrefix, this)) 0030 { 0031 } 0032 0033 GattApplication::~GattApplication() 0034 { 0035 delete d; 0036 } 0037 0038 DBusManagerStruct GattApplicationPrivate::getManagedObjects() const 0039 { 0040 DBusManagerStruct objects; 0041 0042 const auto serviceAdaptors = q->findChildren<GattServiceAdaptor *>(); 0043 const auto charcAdaptors = q->findChildren<GattCharacteristicAdaptor *>(); 0044 0045 for (const GattServiceAdaptor *serviceAdaptor : serviceAdaptors) { 0046 QVariantMap properties; 0047 for (int i = serviceAdaptor->metaObject()->propertyOffset(); i < serviceAdaptor->metaObject()->propertyCount(); ++i) { 0048 auto propertyName = serviceAdaptor->metaObject()->property(i).name(); 0049 properties.insert(QString::fromLatin1(propertyName), serviceAdaptor->property(propertyName)); 0050 } 0051 0052 GattService *service = qobject_cast<GattService *>(serviceAdaptor->parent()); 0053 if (service) { 0054 objects[service->objectPath()].insert(QStringLiteral("org.bluez.GattService1"), properties); 0055 } 0056 } 0057 0058 for (const GattCharacteristicAdaptor *charcAdaptor : charcAdaptors) { 0059 QVariantMap properties; 0060 for (int i = charcAdaptor->metaObject()->propertyOffset(); i < charcAdaptor->metaObject()->propertyCount(); ++i) { 0061 auto propertyName = charcAdaptor->metaObject()->property(i).name(); 0062 properties.insert(QString::fromLatin1(propertyName), charcAdaptor->property(propertyName)); 0063 } 0064 0065 GattCharacteristic *charc = qobject_cast<GattCharacteristic *>(charcAdaptor->parent()); 0066 if (charc) { 0067 objects[charc->objectPath()].insert(QStringLiteral("org.bluez.GattCharacteristic1"), properties); 0068 } 0069 } 0070 0071 return objects; 0072 } 0073 0074 QDBusObjectPath GattApplication::objectPath() const 0075 { 0076 return d->m_objectPath; 0077 } 0078 0079 } // namespace BluezQt 0080 0081 #include "moc_gattapplication.cpp"