BluezQt

gattmanager.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 "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(descriptor->objectPath().path(), descriptor, QDBusConnection::ExportAdaptors)) {
52 qCDebug(BLUEZQT) << "Cannot register object" << descriptor->objectPath().path();
53 }
54 }
55
56 if (!DBusConnection::orgBluez().registerObject(charc->objectPath().path(), charc, QDBusConnection::ExportAdaptors)) {
57 qCDebug(BLUEZQT) << "Cannot register object" << charc->objectPath().path();
58 }
59 }
60
61 if (!DBusConnection::orgBluez().registerObject(service->objectPath().path(), service, QDBusConnection::ExportAdaptors)) {
62 qCDebug(BLUEZQT) << "Cannot register object" << service->objectPath().path();
63 }
64 }
65
66 new ObjectManagerAdaptor(application);
67
68 if (!DBusConnection::orgBluez().registerObject(application->objectPath().path(), application, QDBusConnection::ExportAdaptors)) {
69 qCDebug(BLUEZQT) << "Cannot register object" << application->objectPath().path();
70 }
71
72 return new PendingCall(d->m_dbusInterface.RegisterApplication(application->objectPath(), QVariantMap()), PendingCall::ReturnVoid, this);
73}
74
75PendingCall *GattManager::unregisterApplication(GattApplication *application)
76{
77 Q_ASSERT(application);
78
79 DBusConnection::orgBluez().unregisterObject(application->objectPath().path());
80
81 return new PendingCall(d->m_dbusInterface.UnregisterApplication(application->objectPath()), PendingCall::ReturnVoid, this);
82}
83
84} // namespace BluezQt
85
86#include "moc_gattmanager.cpp"
Bluetooth GattApplication.
Bluetooth GATT Descriptor.
Bluetooth GattService.
Pending method call.
QString path(const QString &relativePath)
QString path() const const
QList< T > findChildren(Qt::FindChildOptions options) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:18:02 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.