Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
bluezperipheralobjects_p.h
Go to the documentation of this file.
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_OBJECTS_P_H
5#define BLUEZ_PERIPHERAL_OBJECTS_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
19
20#include <QtBluetooth/qbluetooth.h>
21#include <QtBluetooth/QBluetoothUuid>
22#include <QtBluetooth/QLowEnergyDescriptorData>
23#include <QtBluetooth/QLowEnergyCharacteristicData>
24#include <QtBluetooth/QLowEnergyServiceData>
25
26namespace QtBluetoothPrivate {
27
30class OrgBluezGattDescriptor1Adaptor;
32
33} // namespace QtBluetoothPrivate
34
35QT_BEGIN_NAMESPACE
36
37// The QtBluezPeripheralGattObject is the base class for services, characteristics, and descriptors
38class QtBluezPeripheralGattObject : public QObject
39{
40 Q_OBJECT
41
42public:
43 QtBluezPeripheralGattObject(const QString& objectPath, const QString& uuid,
44 QLowEnergyHandle handle, QObject* parent = nullptr);
45 virtual ~QtBluezPeripheralGattObject();
46
47 // List of properties exposed by this object, used when Bluez inquiries details
48 virtual InterfaceList properties() const = 0;
49
50 bool registerObject();
51 void unregisterObject();
52
53public:
54 // DBus object path
55 QString objectPath;
56 // UUID of the gatt object
57 QString uuid;
58 // QtBluetooth internal handle and reference to the application
59 // to read and write values towards the Qt API
60 QLowEnergyHandle handle;
61 // Bluez DBus Gatt objects need to provide this
62 QtBluetoothPrivate::OrgFreedesktopDBusPropertiesAdaptor* propertiesAdaptor{};
63
64signals:
65 void remoteDeviceAccessEvent(const QString& remoteDeviceObjectPath, quint16 mtu);
66
67protected:
68 void accessEvent(const QVariantMap& options);
69
70private:
71 bool m_registered = false;
72};
73
74class QtBluezPeripheralDescriptor : public QtBluezPeripheralGattObject
75{
77
78public:
83
84 InterfaceList properties() const final;
85
86 // org.bluez.GattDescriptor1
87 // This function is invoked when remote device reads the value. Sets error if any
88 Q_INVOKABLE QByteArray ReadValue(const QVariantMap &options, QString &error);
89
90 // org.bluez.GattDescriptor1
91 // This function is invoked when remote device writes a value. Returns Bluez DBus error if any
92 Q_INVOKABLE QString WriteValue(const QByteArray &value, const QVariantMap &options);
93
94 // Call this function when value has been updated locally (server/user application side)
95 bool localValueUpdate(const QByteArray& value);
96
100
101private:
102 void initializeFlags(const QLowEnergyDescriptorData& data);
103
104 QtBluetoothPrivate::OrgBluezGattDescriptor1Adaptor* m_adaptor{};
105 QString m_characteristicPath;
106 QByteArray m_value;
107 QStringList m_flags;
108 QLowEnergyHandle m_characteristicHandle;
109};
110
111
112class QtBluezPeripheralCharacteristic : public QtBluezPeripheralGattObject
113{
115
116public:
120
121 InterfaceList properties() const final;
122
123 // org.bluez.GattCharacteristic1
124 // This function is invoked when remote device reads the value. Sets error if any
125 Q_INVOKABLE QByteArray ReadValue(const QVariantMap &options, QString& error);
126
127 // org.bluez.GattCharacteristic1
128 // This function is invoked when remote device writes a value. Returns Bluez DBus error if any
129 Q_INVOKABLE QString WriteValue(const QByteArray &value, const QVariantMap &options);
130
131 // org.bluez.GattCharacteristic1
132 // These are called when remote client enables or disables NTF/IND
134 Q_INVOKABLE void StopNotify();
135
136 // Call this function when value has been updated locally (server/user application side)
137 bool localValueUpdate(const QByteArray& value);
138
139signals:
141
142private:
143 void initializeValue(const QByteArray& value);
144 void initializeFlags(const QLowEnergyCharacteristicData& data);
145
147 QString m_servicePath;
148 bool m_notifying{false};
149 QByteArray m_value;
150 QStringList m_flags;
151 int m_minimumValueLength;
152 int m_maximumValueLength;
153};
154
155class QtBluezPeripheralService : public QtBluezPeripheralGattObject
156{
158public:
162
163 InterfaceList properties() const final;
164 void addIncludedService(const QString& objectPath);
165
166private:
167 const bool m_isPrimary;
169 QList<QDBusObjectPath> m_includedServices;
170};
171
172
173QT_END_NAMESPACE
174
175#endif
QMap< QDBusObjectPath, InterfaceList > ManagedObjectList
QMap< QString, QVariantMap > InterfaceList
static constexpr QLatin1String appObjectPathTemplate
bool localDescriptorWrite(QLowEnergyHandle handle, const QByteArray &value)
void remoteDeviceAccessEvent(const QString &remoteDeviceObjectPath, quint16 mtu)
void addService(const QLowEnergyServiceData &serviceData, QSharedPointer< QLowEnergyServicePrivate > servicePrivate, QLowEnergyHandle serviceHandle)
void characteristicValueUpdatedByRemote(QLowEnergyHandle handle, const QByteArray &value)
bool localCharacteristicWrite(QLowEnergyHandle handle, const QByteArray &value)
void descriptorValueUpdatedByRemote(QLowEnergyHandle characteristicHandle, QLowEnergyHandle descriptorHandle, const QByteArray &value)
InterfaceList properties() const final
bool localValueUpdate(const QByteArray &value)
bool localValueUpdate(const QByteArray &value)
InterfaceList properties() const final
void addIncludedService(const QString &objectPath)
InterfaceList properties() const final