BluezQt

gattmanager.cpp
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 "gattmanager.h"
10 
11 #include "debug.h"
12 #include "gattapplication.h"
13 #include "gattcharacteristic.h"
14 #include "gattcharacteristicadaptor.h"
15 #include "gattmanager_p.h"
16 #include "gattservice.h"
17 #include "gattserviceadaptor.h"
18 #include "objectmanageradaptor.h"
19 #include "pendingcall.h"
20 #include "utils.h"
21 
22 #include <QDBusPendingCall>
23 
24 namespace BluezQt
25 {
26 GattManager::GattManager(const QString &path, QObject *parent)
27  : QObject(parent)
28  , d(new GattManagerPrivate(path))
29 {
30 }
31 
33 {
34  delete d;
35 }
36 
38 {
39  Q_ASSERT(application);
40 
41  const auto services = application->findChildren<GattService *>();
42  for (auto service : services) {
43  new GattServiceAdaptor(service);
44 
45  const auto charcs = service->findChildren<GattCharacteristic *>();
46  for (auto charc : charcs) {
47  new GattCharacteristicAdaptor(charc);
48  if (!DBusConnection::orgBluez().registerObject(charc->objectPath().path(), charc, QDBusConnection::ExportAdaptors)) {
49  qCDebug(BLUEZQT) << "Cannot register object" << charc->objectPath().path();
50  }
51  }
52 
53  if (!DBusConnection::orgBluez().registerObject(service->objectPath().path(), service, QDBusConnection::ExportAdaptors)) {
54  qCDebug(BLUEZQT) << "Cannot register object" << service->objectPath().path();
55  }
56  }
57 
58  new ObjectManagerAdaptor(application);
59 
60  if (!DBusConnection::orgBluez().registerObject(application->objectPath().path(), application, QDBusConnection::ExportAdaptors)) {
61  qCDebug(BLUEZQT) << "Cannot register object" << application->objectPath().path();
62  }
63 
64  return new PendingCall(d->m_dbusInterface.RegisterApplication(application->objectPath(), QVariantMap()), PendingCall::ReturnVoid, this);
65 }
66 
68 {
69  Q_ASSERT(application);
70 
71  DBusConnection::orgBluez().unregisterObject(application->objectPath().path());
72 
73  return new PendingCall(d->m_dbusInterface.UnregisterApplication(application->objectPath()), PendingCall::ReturnVoid, this);
74 }
75 
76 } // namespace BluezQt
~GattManager() override
Destroys a GattManager object.
Definition: gattmanager.cpp:32
QList< T > findChildren(const QString &name, Qt::FindChildOptions options) const const
QString path() const const
PendingCall * unregisterApplication(GattApplication *application)
This unregisters the services that has been previously registered.
Definition: gattmanager.cpp:67
QString path(const QString &relativePath)
PendingCall * registerApplication(GattApplication *application)
Registers a local GATT services hierarchy as described above (GATT Server) and/or GATT profiles (GATT...
Definition: gattmanager.cpp:37
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon May 8 2023 04:07:24 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.