| 1 | // Copyright (C) 2022 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef BLUEZ_PERIPHERAL_APPLICATION_P_H |
| 5 | #define BLUEZ_PERIPHERAL_APPLICATION_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include <QtBluetooth/private/qlowenergycontroller_bluezdbus_p.h> |
| 19 | #include "bluez5_helper_p.h" |
| 20 | |
| 21 | #include <QtBluetooth/QBluetoothAddress> |
| 22 | #include <QtCore/QCoreApplication> |
| 23 | |
| 24 | namespace QtBluetoothPrivate { |
| 25 | |
| 26 | class OrgFreedesktopDBusObjectManagerAdaptor; |
| 27 | class OrgBluezGattManager1Interface; |
| 28 | |
| 29 | } // namespace QtBluetoothPrivate |
| 30 | |
| 31 | QT_BEGIN_NAMESPACE |
| 32 | |
| 33 | class QLowEnergyControllerPrivateBluezDBus; |
| 34 | class QtBluezPeripheralService; |
| 35 | class QtBluezPeripheralCharacteristic; |
| 36 | class QtBluezPeripheralDescriptor; |
| 37 | class QtBluezPeripheralConnectionManager; |
| 38 | |
| 39 | class QtBluezPeripheralApplication : public QObject |
| 40 | { |
| 41 | Q_OBJECT |
| 42 | |
| 43 | public: |
| 44 | QtBluezPeripheralApplication(const QString& localAdapterPath, QObject* parent = nullptr); |
| 45 | ~QtBluezPeripheralApplication(); |
| 46 | |
| 47 | // Register the application and its services to DBus & Bluez |
| 48 | void registerApplication(); |
| 49 | // Unregister the application and its services from DBus & Bluez. |
| 50 | // Calling this doesn't invalidate the services |
| 51 | void unregisterApplication(); |
| 52 | // Unregister and release all resources, invalidates services |
| 53 | void reset(); |
| 54 | |
| 55 | void addService(const QLowEnergyServiceData &serviceData, |
| 56 | QSharedPointer<QLowEnergyServicePrivate> servicePrivate, |
| 57 | QLowEnergyHandle serviceHandle); |
| 58 | |
| 59 | // Call these when the user application has updated the attribute value |
| 60 | // Returns whether the new value was accepted |
| 61 | bool localCharacteristicWrite(QLowEnergyHandle handle, const QByteArray& value); |
| 62 | bool localDescriptorWrite(QLowEnergyHandle handle, const QByteArray& value); |
| 63 | |
| 64 | // Returns true if application has services and is not registered |
| 65 | bool registrationNeeded(); |
| 66 | |
| 67 | // org.freedesktop.DBus.ObjectManager |
| 68 | Q_INVOKABLE ManagedObjectList GetManagedObjects(); |
| 69 | |
| 70 | signals: |
| 71 | void errorOccurred(); |
| 72 | void registered(); |
| 73 | |
| 74 | // Emitted when remote device reads a characteristic |
| 75 | void remoteDeviceAccessEvent(const QString& remoteDeviceObjectPath, quint16 mtu); |
| 76 | |
| 77 | // These are emitted when remote has written a new value |
| 78 | void characteristicValueUpdatedByRemote(QLowEnergyHandle handle, const QByteArray& value); |
| 79 | void descriptorValueUpdatedByRemote(QLowEnergyHandle characteristicHandle, |
| 80 | QLowEnergyHandle descriptorHandle, |
| 81 | const QByteArray& value); |
| 82 | private: |
| 83 | void registerServices(); |
| 84 | void unregisterServices(); |
| 85 | |
| 86 | QLowEnergyHandle handleForCharacteristic(QBluetoothUuid uuid, |
| 87 | QSharedPointer<QLowEnergyServicePrivate> service); |
| 88 | QLowEnergyHandle handleForDescriptor(QBluetoothUuid uuid, |
| 89 | QSharedPointer<QLowEnergyServicePrivate> service, |
| 90 | QLowEnergyHandle characteristicHandle); |
| 91 | |
| 92 | QMap<QLowEnergyHandle, QtBluezPeripheralService*> m_services; |
| 93 | QMap<QLowEnergyHandle, QtBluezPeripheralCharacteristic*> m_characteristics; |
| 94 | QMap<QLowEnergyHandle, QtBluezPeripheralDescriptor*> m_descriptors; |
| 95 | |
| 96 | QString m_objectPath; |
| 97 | QtBluetoothPrivate::OrgFreedesktopDBusObjectManagerAdaptor* m_objectManager{}; |
| 98 | QtBluetoothPrivate::OrgBluezGattManager1Interface* m_gattManager{}; |
| 99 | bool m_applicationRegistered{false}; |
| 100 | }; |
| 101 | |
| 102 | QT_END_NAMESPACE |
| 103 | |
| 104 | #endif |
| 105 | |