BluezQt

gattapplication.cpp
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
22namespace BluezQt
23{
25 : GattApplication(QStringLiteral("/org/kde/bluezqt"), parent)
26{
27}
28
30 : QObject(parent)
31 , d(new GattApplicationPrivate(objectPathPrefix, this))
32{
33}
34
36
37DBusManagerStruct 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
87QDBusObjectPath GattApplication::objectPath() const
88{
89 return d->m_objectPath;
90}
91
92} // namespace BluezQt
93
94#include "moc_gattapplication.cpp"
Bluetooth GattApplication.
~GattApplication() override
Destroys a GattApplication object.
GattApplication(QObject *parent=nullptr)
Creates a new GattApplication object with default object path prefix.
D-Bus request.
Definition request.h:39
KGuiItem properties()
iterator insert(const Key &key, const T &value)
QString fromLatin1(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:51 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.