File indexing completed on 2025-01-19 06:44:36
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 "gattmanager.h" 0010 0011 #include "debug.h" 0012 #include "gattapplication.h" 0013 #include "gattcharacteristic.h" 0014 #include "gattcharacteristicadaptor.h" 0015 #include "gattdescriptor.h" 0016 #include "gattdescriptoradaptor.h" 0017 #include "gattmanager_p.h" 0018 #include "gattservice.h" 0019 #include "gattserviceadaptor.h" 0020 #include "objectmanageradaptor.h" 0021 #include "pendingcall.h" 0022 #include "utils.h" 0023 0024 #include <QDBusPendingCall> 0025 0026 namespace BluezQt 0027 { 0028 GattManager::GattManager(const QString &path, QObject *parent) 0029 : QObject(parent) 0030 , d(new GattManagerPrivate(path)) 0031 { 0032 } 0033 0034 GattManager::~GattManager() = default; 0035 0036 PendingCall *GattManager::registerApplication(GattApplication *application) 0037 { 0038 Q_ASSERT(application); 0039 0040 const auto services = application->findChildren<GattService *>(); 0041 for (auto service : services) { 0042 new GattServiceAdaptor(service); 0043 0044 const auto charcs = service->findChildren<GattCharacteristic *>(); 0045 for (auto charc : charcs) { 0046 new GattCharacteristicAdaptor(charc); 0047 0048 for (auto descriptor : charc->findChildren<GattDescriptor *>()) { 0049 new GattDescriptorAdaptor(descriptor); 0050 0051 if (!DBusConnection::orgBluez().registerObject(descriptor->objectPath().path(), descriptor, QDBusConnection::ExportAdaptors)) { 0052 qCDebug(BLUEZQT) << "Cannot register object" << descriptor->objectPath().path(); 0053 } 0054 } 0055 0056 if (!DBusConnection::orgBluez().registerObject(charc->objectPath().path(), charc, QDBusConnection::ExportAdaptors)) { 0057 qCDebug(BLUEZQT) << "Cannot register object" << charc->objectPath().path(); 0058 } 0059 } 0060 0061 if (!DBusConnection::orgBluez().registerObject(service->objectPath().path(), service, QDBusConnection::ExportAdaptors)) { 0062 qCDebug(BLUEZQT) << "Cannot register object" << service->objectPath().path(); 0063 } 0064 } 0065 0066 new ObjectManagerAdaptor(application); 0067 0068 if (!DBusConnection::orgBluez().registerObject(application->objectPath().path(), application, QDBusConnection::ExportAdaptors)) { 0069 qCDebug(BLUEZQT) << "Cannot register object" << application->objectPath().path(); 0070 } 0071 0072 return new PendingCall(d->m_dbusInterface.RegisterApplication(application->objectPath(), QVariantMap()), PendingCall::ReturnVoid, this); 0073 } 0074 0075 PendingCall *GattManager::unregisterApplication(GattApplication *application) 0076 { 0077 Q_ASSERT(application); 0078 0079 DBusConnection::orgBluez().unregisterObject(application->objectPath().path()); 0080 0081 return new PendingCall(d->m_dbusInterface.UnregisterApplication(application->objectPath()), PendingCall::ReturnVoid, this); 0082 } 0083 0084 } // namespace BluezQt 0085 0086 #include "moc_gattmanager.cpp"