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 | class OrgFreedesktopDBusObjectManagerAdaptor; |
25 | class OrgBluezGattManager1Interface; |
26 | |
27 | QT_BEGIN_NAMESPACE |
28 | |
29 | class QLowEnergyControllerPrivateBluezDBus; |
30 | class QtBluezPeripheralService; |
31 | class QtBluezPeripheralCharacteristic; |
32 | class QtBluezPeripheralDescriptor; |
33 | class QtBluezPeripheralConnectionManager; |
34 | |
35 | class QtBluezPeripheralApplication : public QObject |
36 | { |
37 | Q_OBJECT |
38 | |
39 | public: |
40 | QtBluezPeripheralApplication(const QString& localAdapterPath, QObject* parent = nullptr); |
41 | ~QtBluezPeripheralApplication(); |
42 | |
43 | // Register the application and its services to DBus & Bluez |
44 | void registerApplication(); |
45 | // Unregister the application and its services from DBus & Bluez. |
46 | // Calling this doesn't invalidate the services |
47 | void unregisterApplication(); |
48 | // Unregister and release all resources, invalidates services |
49 | void reset(); |
50 | |
51 | void addService(const QLowEnergyServiceData &serviceData, |
52 | QSharedPointer<QLowEnergyServicePrivate> servicePrivate, |
53 | QLowEnergyHandle serviceHandle); |
54 | |
55 | // Call these when the user application has updated the attribute value |
56 | // Returns whether the new value was accepted |
57 | bool localCharacteristicWrite(QLowEnergyHandle handle, const QByteArray& value); |
58 | bool localDescriptorWrite(QLowEnergyHandle handle, const QByteArray& value); |
59 | |
60 | // Returns true if application has services and is not registered |
61 | bool registrationNeeded(); |
62 | |
63 | // org.freedesktop.DBus.ObjectManager |
64 | Q_INVOKABLE ManagedObjectList GetManagedObjects(); |
65 | |
66 | signals: |
67 | void errorOccurred(); |
68 | void registered(); |
69 | |
70 | // Emitted when remote device reads a characteristic |
71 | void remoteDeviceAccessEvent(const QString& remoteDeviceObjectPath, quint16 mtu); |
72 | |
73 | // These are emitted when remote has written a new value |
74 | void characteristicValueUpdatedByRemote(QLowEnergyHandle handle, const QByteArray& value); |
75 | void descriptorValueUpdatedByRemote(QLowEnergyHandle characteristicHandle, |
76 | QLowEnergyHandle descriptorHandle, |
77 | const QByteArray& value); |
78 | private: |
79 | void registerServices(); |
80 | void unregisterServices(); |
81 | |
82 | QLowEnergyHandle handleForCharacteristic(QBluetoothUuid uuid, |
83 | QSharedPointer<QLowEnergyServicePrivate> service); |
84 | QLowEnergyHandle handleForDescriptor(QBluetoothUuid uuid, |
85 | QSharedPointer<QLowEnergyServicePrivate> service, |
86 | QLowEnergyHandle characteristicHandle); |
87 | |
88 | QMap<QLowEnergyHandle, QtBluezPeripheralService*> m_services; |
89 | QMap<QLowEnergyHandle, QtBluezPeripheralCharacteristic*> m_characteristics; |
90 | QMap<QLowEnergyHandle, QtBluezPeripheralDescriptor*> m_descriptors; |
91 | |
92 | QString m_objectPath; |
93 | OrgFreedesktopDBusObjectManagerAdaptor* m_objectManager{}; |
94 | OrgBluezGattManager1Interface* m_gattManager{}; |
95 | bool m_applicationRegistered{false}; |
96 | }; |
97 | |
98 | QT_END_NAMESPACE |
99 | |
100 | #endif |
101 | |