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 "gattmanager.h"
10
11#include "debug.h"
12#include "gattapplication.h"
13#include "gattcharacteristic.h"
14#include "gattcharacteristicadaptor.h"
15#include "gattdescriptor.h"
16#include "gattdescriptoradaptor.h"
17#include "gattmanager_p.h"
18#include "gattservice.h"
19#include "gattserviceadaptor.h"
20#include "objectmanageradaptor.h"
21#include "pendingcall.h"
22#include "utils.h"
23
24#include <QDBusPendingCall>
25
26namespace BluezQt
27{
28GattManager::GattManager(const QString &path, QObject *parent)
29 : QObject(parent)
30 , d(new GattManagerPrivate(path))
31{
32}
33
34GattManager::~GattManager() = default;
35
36PendingCall *GattManager::registerApplication(GattApplication *application)
37{
38 Q_ASSERT(application);
39
40 const auto services = application->findChildren<GattService *>();
41 for (auto service : services) {
42 new GattServiceAdaptor(service);
43
44 const auto charcs = service->findChildren<GattCharacteristic *>();
45 for (auto charc : charcs) {
46 new GattCharacteristicAdaptor(charc);
47
48 for (auto descriptor : charc->findChildren<GattDescriptor *>()) {
49 new GattDescriptorAdaptor(descriptor);
50
51 if (!DBusConnection::orgBluez().registerObject(path: descriptor->objectPath().path(), object: descriptor, options: QDBusConnection::ExportAdaptors)) {
52 qCDebug(BLUEZQT) << "Cannot register object" << descriptor->objectPath().path();
53 }
54 }
55
56 if (!DBusConnection::orgBluez().registerObject(path: charc->objectPath().path(), object: charc, options: QDBusConnection::ExportAdaptors)) {
57 qCDebug(BLUEZQT) << "Cannot register object" << charc->objectPath().path();
58 }
59 }
60
61 if (!DBusConnection::orgBluez().registerObject(path: service->objectPath().path(), object: service, options: QDBusConnection::ExportAdaptors)) {
62 qCDebug(BLUEZQT) << "Cannot register object" << service->objectPath().path();
63 }
64 }
65
66 new ObjectManagerAdaptor(application);
67
68 if (!DBusConnection::orgBluez().registerObject(path: application->objectPath().path(), object: application, options: QDBusConnection::ExportAdaptors)) {
69 qCDebug(BLUEZQT) << "Cannot register object" << application->objectPath().path();
70 }
71
72 return new PendingCall(d->m_dbusInterface.RegisterApplication(application: application->objectPath(), options: QVariantMap()), PendingCall::ReturnVoid, this);
73}
74
75PendingCall *GattManager::unregisterApplication(GattApplication *application)
76{
77 Q_ASSERT(application);
78
79 DBusConnection::orgBluez().unregisterObject(path: application->objectPath().path());
80
81 return new PendingCall(d->m_dbusInterface.UnregisterApplication(application: application->objectPath()), PendingCall::ReturnVoid, this);
82}
83
84} // namespace BluezQt
85
86#include "moc_gattmanager.cpp"
87

source code of bluez-qt/src/gattmanager.cpp