diff --git a/src/gattapplication.cpp b/src/gattapplication.cpp index 0a2216b..5d5d4b4 100644 --- a/src/gattapplication.cpp +++ b/src/gattapplication.cpp @@ -1,97 +1,97 @@ /* * BluezQt - Asynchronous Bluez wrapper library * * Copyright (C) 2019 Manuel Weichselbaumer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "gattapplication.h" #include "gattapplication_p.h" #include "gattcharacteristic.h" #include "gattcharacteristicadaptor.h" #include "gattservice.h" #include "gattserviceadaptor.h" #include #include #include namespace BluezQt { GattApplication::GattApplication(QObject *parent) : GattApplication(QStringLiteral("/org/kde/bluezqt"), parent) { } GattApplication::GattApplication(const QString &objectPathPrefix, QObject *parent) : QObject(parent) , d(new GattApplicationPrivate(objectPathPrefix)) { } GattApplication::~GattApplication() { delete d; } -DBusManagerStruct GattApplication::getManagedObjects() const +DBusManagerStruct GattApplicationPrivate::getManagedObjects() const { DBusManagerStruct objects; - const auto serviceAdaptors = findChildren(); - const auto charcAdaptors = findChildren(); + const auto serviceAdaptors = q->findChildren(); + const auto charcAdaptors = q->findChildren(); for (const GattServiceAdaptor *serviceAdaptor : serviceAdaptors) { QVariantMap properties; for (int i = serviceAdaptor->metaObject()->propertyOffset(); i < serviceAdaptor->metaObject()->propertyCount(); ++i) { auto propertyName = serviceAdaptor->metaObject()->property(i).name(); properties.insert(QString::fromLatin1(propertyName), serviceAdaptor->property(propertyName)); } GattService *service = qobject_cast(serviceAdaptor->parent()); if (service) { objects[service->objectPath()].insert(QStringLiteral("org.bluez.GattService1"), properties); } } for (const GattCharacteristicAdaptor *charcAdaptor : charcAdaptors) { QVariantMap properties; for (int i = charcAdaptor->metaObject()->propertyOffset(); i < charcAdaptor->metaObject()->propertyCount(); ++i) { auto propertyName = charcAdaptor->metaObject()->property(i).name(); properties.insert(QString::fromLatin1(propertyName), charcAdaptor->property(propertyName)); } GattCharacteristic *charc = qobject_cast(charcAdaptor->parent()); if (charc) { objects[charc->objectPath()].insert(QStringLiteral("org.bluez.GattCharacteristic1"), properties); } } return objects; } QDBusObjectPath GattApplication::objectPath() const { return d->m_objectPath; } } // namespace BluezQt diff --git a/src/gattapplication.h b/src/gattapplication.h index 9f621f6..9ede557 100644 --- a/src/gattapplication.h +++ b/src/gattapplication.h @@ -1,105 +1,97 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * * Copyright (C) 2019 Manuel Weichselbaumer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #pragma once -#include "bluezqt_dbustypes.h" +#include + #include "bluezqt_export.h" +class QDBusObjectPath; + namespace BluezQt { /** * @class BluezQt::GattApplication GattApplication.h * * Bluetooth GattApplication. * * This class represents a Bluetooth GattApplication, which is the root node of * a GATT object hierarchy. Its child nodes can be GattServices, * GattCharacteristics and GattDescriptors that belong to that GattApplication. * The object path prefix for GattApplications is freely definable and its * children's paths follow the application path hierarchy automatically, while * all instances are enumerated automatically as well. * * Object path: [variable prefix]/appXX/serviceYY/charZZ * */ class BLUEZQT_EXPORT GattApplication : public QObject { Q_OBJECT public: /** * Creates a new GattApplication object with default object path prefix. * * Object path: /org/kde/bluezqt/appXX/serviceYY/charZZ * * @param parent */ explicit GattApplication(QObject *parent = nullptr); /** * Creates a new GattApplication object with custom object path prefix. * * Object path: [objectPathPrefix]/appXX/serviceYY/charZZ * * @param objectPathPrefix * @param parent */ explicit GattApplication(const QString &objectPathPrefix, QObject *parent = nullptr); /** * Destroys a GattApplication object. */ ~GattApplication(); private: /** * D-Bus object path of the GATT application. * * The path where the GATT application will be registered. * * @note You must provide valid object path! * * @return object path of GATT application */ virtual QDBusObjectPath objectPath() const; - /** - * Gets all GattServices, GattCharacteristics and GattDescriptors that - * belong to this GattApplication. - * - * The return value of this method is a dict whose keys are object paths. - * Each value is a dict whose keys are interfaces names. Each value in this - * inner dict is another dict with property names (as key) and property - * values (as value). - */ - DBusManagerStruct getManagedObjects() const; - class GattApplicationPrivate *const d; friend class GattManager; friend class GattService; friend class ObjectManagerAdaptor; }; } // namespace BluezQt diff --git a/src/gattapplication_p.h b/src/gattapplication_p.h index 1b8163b..090b4a1 100644 --- a/src/gattapplication_p.h +++ b/src/gattapplication_p.h @@ -1,38 +1,45 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * * Copyright (C) 2019 Manuel Weichselbaumer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #pragma once +#include "bluezqt_dbustypes.h" + #include namespace BluezQt { +class GattApplication; + class GattApplicationPrivate { public: GattApplicationPrivate(const QString &objectPathPrefix); + DBusManagerStruct getManagedObjects() const; + + GattApplication *q; QDBusObjectPath m_objectPath; }; } // namespace BluezQt diff --git a/src/gattcharacteristic.h b/src/gattcharacteristic.h index 4fe7cda..343a3cb 100644 --- a/src/gattcharacteristic.h +++ b/src/gattcharacteristic.h @@ -1,106 +1,106 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * * Copyright (C) 2019 Manuel Weichselbaumer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #pragma once #include "bluezqt_export.h" #include namespace BluezQt { class GattService; class BLUEZQT_EXPORT GattCharacteristic : public QObject { Q_OBJECT public: /** * Creates a new GattCharacteristic object. * * @param parent */ explicit GattCharacteristic(const QString &uuid, GattService *service); /** * Destroys a GattCharacteristic object. */ ~GattCharacteristic(); /** * Reads the value of the characteristic. */ QByteArray readValue(); /** * Writes the value of the characteristic. */ void writeValue(const QByteArray &value); /** * Provide a read callback to operate in *pull* mode. */ using ReadCallback = std::function; void setReadCallback(ReadCallback callback); /** * 128-bit GATT characteristic UUID. * * @return uuid of characteristic */ QString uuid() const; /** * The GATT service the characteristic belongs to. * * @return service this characteristic belongs to */ const GattService *service() const; Q_SIGNALS: /** * Indicates that a value was written. */ void valueWritten(const QByteArray &value); protected: /** * D-Bus object path of the GattCharacteristic. * * The path where the GattCharacteristic will be registered. * * @note You must provide valid object path! * * @return object path of GattCharacteristic */ virtual QDBusObjectPath objectPath() const; private: class GattCharacterisiticPrivate *const d; - friend class GattApplication; + friend class GattApplicationPrivate; friend class GattCharacteristicAdaptor; friend class GattManager; }; } // namespace BluezQt diff --git a/src/gattmanager.h b/src/gattmanager.h index 3a799bb..629f0eb 100644 --- a/src/gattmanager.h +++ b/src/gattmanager.h @@ -1,109 +1,108 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * * Copyright (C) 2019 Manuel Weichselbaumer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #pragma once #include -#include "bluezqt_dbustypes.h" #include "bluezqt_export.h" namespace BluezQt { class GattApplication; class PendingCall; /** * @class BluezQt::GattManager GattManager.h * * Bluetooth GattManager. * * GATT Manager allows external applications to register GATT services and * profiles. * * Registering a profile allows applications to subscribe to *remote* services. * These must implement the GattProfile1 interface defined above. * * Registering a service allows applications to publish a *local* GATT service, * which then becomes available to remote devices. A GATT service is represented by * a D-Bus object hierarchy where the root node corresponds to a service and the * child nodes represent characteristics and descriptors that belong to that * service. Each node must implement one of GattService1, GattCharacteristic1, * or GattDescriptor1 interfaces described above, based on the attribute it * represents. Each node must also implement the standard D-Bus Properties * interface to expose their properties. These objects collectively represent a * GATT service definition. * * @see GattApplication */ class BLUEZQT_EXPORT GattManager : public QObject { Q_OBJECT public: /** * Destroys a GattManager object. */ ~GattManager(); /** * Registers a local GATT services hierarchy as described * above (GATT Server) and/or GATT profiles (GATT Client). * * The application object path together with the D-Bus * system bus connection ID define the identification of * the application registering a GATT based * service or profile. * * Possible errors: org.bluez.Error.InvalidArguments * org.bluez.Error.AlreadyExists * * @param application application to be registered * @return void pending call */ PendingCall *registerApplication(GattApplication *application); /** * This unregisters the services that has been * previously registered. The object path parameter * must match the same value that has been used * on registration. * * Possible errors: org.bluez.Error.InvalidArguments * org.bluez.Error.DoesNotExist * * @param application application to be unregistered * @return void pending call */ PendingCall *unregisterApplication(GattApplication *application); private: explicit GattManager(const QString &path, QObject *parent = nullptr); class GattManagerPrivate *const d; friend class AdapterPrivate; }; } // namespace BluezQt diff --git a/src/gattservice.h b/src/gattservice.h index 363326c..20310b6 100644 --- a/src/gattservice.h +++ b/src/gattservice.h @@ -1,93 +1,93 @@ /* * BluezQt - Asynchronous BlueZ wrapper library * * Copyright (C) 2019 Manuel Weichselbaumer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #pragma once #include "bluezqt_export.h" #include "types.h" #include namespace BluezQt { /** * @class BluezQt::GattService GattService.h * * Bluetooth GattService. * * This class represents a Bluetooth GattService. */ class BLUEZQT_EXPORT GattService : public QObject { Q_OBJECT public: /** * Creates a new GattService object. * * @param parent */ explicit GattService(const QString &uuid, bool isPrimary, GattApplication *parent); /** * Destroys a GattService object. */ ~GattService(); /** * 128-bit service UUID. * * @return uuid of gatt service */ QString uuid() const; /** * Indicates whether or not this GATT service is a * primary service. If false, the service is secondary. * * @return true if gatt service is primary */ bool isPrimary() const; protected: /** * D-Bus object path of the GattService. * * The path where the GattService will be registered. * * @note You must provide valid object path! * * @return object path of GattService */ virtual QDBusObjectPath objectPath() const; private: class GattServicePrivate *const d; - friend class GattApplication; + friend class GattApplicationPrivate; friend class GattCharacterisiticPrivate; friend class GattCharacteristicAdaptor; friend class GattManager; }; } // namespace BluezQt diff --git a/src/objectmanageradaptor.cpp b/src/objectmanageradaptor.cpp index 2a17284..8b86183 100644 --- a/src/objectmanageradaptor.cpp +++ b/src/objectmanageradaptor.cpp @@ -1,44 +1,45 @@ /* * BluezQt - Asynchronous Bluez wrapper library * * Copyright (C) 2019 Manuel Weichselbaumer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "objectmanageradaptor.h" #include "gattapplication.h" +#include "gattapplication_p.h" namespace BluezQt { ObjectManagerAdaptor::ObjectManagerAdaptor(QObject *parent) : QDBusAbstractAdaptor(parent) , m_gattApplication(qobject_cast(parent)) { } DBusManagerStruct ObjectManagerAdaptor::GetManagedObjects() { if (m_gattApplication) { - return m_gattApplication->getManagedObjects(); + return m_gattApplication->d->getManagedObjects(); } return {}; } } // namespace BluezQt