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
qlowenergycontroller_bluezdbus_p.h
Go to the documentation of this file.
1// Copyright (C) 2017 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 QLOWENERGYCONTROLLERPRIVATEDBUS_P_H
5#define QLOWENERGYCONTROLLERPRIVATEDBUS_P_H
6
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
22
23#include <QtDBus/QDBusObjectPath>
24
25namespace QtBluetoothPrivate {
26
35
36} // namespace QtBluetoothPrivate
37
38QT_BEGIN_NAMESPACE
39
40class QtBluezPeripheralApplication;
42class QDBusPendingCallWatcher;
43
45{
47public:
50
51 void init() override;
52 void connectToDevice() override;
53 void disconnectFromDevice() override;
54
55 void discoverServices() override;
56 void discoverServiceDetails(const QBluetoothUuid &service,
57 QLowEnergyService::DiscoveryMode mode) override;
58
60 const QSharedPointer<QLowEnergyServicePrivate> service,
61 const QLowEnergyHandle charHandle) override;
62 void readDescriptor(
63 const QSharedPointer<QLowEnergyServicePrivate> service,
64 const QLowEnergyHandle charHandle,
65 const QLowEnergyHandle descriptorHandle) override;
66
68 const QSharedPointer<QLowEnergyServicePrivate> service,
69 const QLowEnergyHandle charHandle,
70 const QByteArray &newValue,
71 QLowEnergyService::WriteMode writeMode) override;
72 void writeDescriptor(
73 const QSharedPointer<QLowEnergyServicePrivate> service,
74 const QLowEnergyHandle charHandle,
75 const QLowEnergyHandle descriptorHandle,
76 const QByteArray &newValue) override;
77
79 const QLowEnergyAdvertisingParameters &params,
80 const QLowEnergyAdvertisingData &advertisingData,
81 const QLowEnergyAdvertisingData &scanResponseData) override;
82 void stopAdvertising() override;
83
85 const QLowEnergyConnectionParameters & params) override;
87 const QLowEnergyServiceData &service,
88 QLowEnergyHandle startHandle) override;
89
90 int mtu() const override;
91
92private:
93 void connectToDeviceHelper();
94 void resetController();
95
96 void scheduleNextJob();
97
98private slots:
101 void characteristicPropertiesChanged(QLowEnergyHandle charHandle, const QString &interface,
102 const QVariantMap &changedProperties,
103 const QStringList &invalidatedProperties);
104 void interfacesRemoved(const QDBusObjectPath &objectPath, const QStringList &interfaces);
105
106 void onCharReadFinished(QDBusPendingCallWatcher *call);
107 void onDescReadFinished(QDBusPendingCallWatcher *call);
108 void onCharWriteFinished(QDBusPendingCallWatcher *call);
109 void onDescWriteFinished(QDBusPendingCallWatcher *call);
110private:
111
116 QString adapterPathWithPeripheralSupport;
117
118 int remoteMtu{-1};
119 QtBluezPeripheralApplication* peripheralApplication{};
120 QtBluezPeripheralConnectionManager* peripheralConnectionManager{};
121 QLeDBusAdvertiser *advertiser{};
122 void handleAdvertisingError();
123 void handlePeripheralApplicationError();
124 void handlePeripheralApplicationRegistered();
125 void handlePeripheralConnectivityChanged(bool connected);
126 void handlePeripheralCharacteristicValueUpdate(QLowEnergyHandle handle,
127 const QByteArray& value);
128 void handlePeripheralDescriptorValueUpdate(QLowEnergyHandle characteristicHandle,
129 QLowEnergyHandle descriptorHandle,
130 const QByteArray& value);
131 void handlePeripheralRemoteDeviceChanged(const QBluetoothAddress& address,
132 const QString& name,
133 quint16 mtu);
134 bool pendingConnect = false;
135 bool disconnectSignalRequired = false;
136
137 struct GattCharacteristic
138 {
139 QSharedPointer<QtBluetoothPrivate::OrgBluezGattCharacteristic1Interface> characteristic;
140 QSharedPointer<QtBluetoothPrivate::OrgFreedesktopDBusPropertiesInterface> charMonitor;
141 QList<QSharedPointer<QtBluetoothPrivate::OrgBluezGattDescriptor1Interface>> descriptors;
142 };
143
144 struct GattService
145 {
146 QString servicePath;
147 QList<GattCharacteristic> characteristics;
148
149 bool hasBatteryService = false;
150 QSharedPointer<QtBluetoothPrivate::OrgBluezBattery1Interface> batteryInterface;
151 };
152
153 QHash<QBluetoothUuid, GattService> dbusServices;
154 QLowEnergyHandle runningHandle = 1;
155
156 struct GattJob {
157 enum JobFlag {
158 Unset = 0x00,
159 CharRead = 0x01,
160 CharWrite = 0x02,
161 DescRead = 0x04,
162 DescWrite = 0x08,
163 ServiceDiscovery = 0x10,
164 LastServiceDiscovery = 0x20
165 };
166 Q_DECLARE_FLAGS(JobFlags, JobFlag)
167
168 JobFlags flags = GattJob::Unset;
169 QLowEnergyHandle handle;
170 QByteArray value;
171 QLowEnergyService::WriteMode writeMode = QLowEnergyService::WriteWithResponse;
172 QSharedPointer<QLowEnergyServicePrivate> service;
173 };
174
175 QList<GattJob> jobs;
176 bool jobPending = false;
177
178 void prepareNextJob();
179 void discoverBatteryServiceDetails(GattService &dbusData,
180 QSharedPointer<QLowEnergyServicePrivate> serviceData);
181 void executeClose(QLowEnergyController::Error newError);
182};
183
184QT_END_NAMESPACE
185
186#endif // QLOWENERGYCONTROLLERPRIVATEDBUS_P_H
QMap< QDBusObjectPath, InterfaceList > ManagedObjectList
QMap< QString, QVariantMap > InterfaceList
void requestConnectionUpdate(const QLowEnergyConnectionParameters &params) override
QLowEnergyControllerPrivateBluezDBus(const QString &adapterPathWithPeripheralSupport={})
void startAdvertising(const QLowEnergyAdvertisingParameters &params, const QLowEnergyAdvertisingData &advertisingData, const QLowEnergyAdvertisingData &scanResponseData) override
void discoverServiceDetails(const QBluetoothUuid &service, QLowEnergyService::DiscoveryMode mode) override
void addToGenericAttributeList(const QLowEnergyServiceData &service, QLowEnergyHandle startHandle) override
void writeCharacteristic(const QSharedPointer< QLowEnergyServicePrivate > service, const QLowEnergyHandle charHandle, const QByteArray &newValue, QLowEnergyService::WriteMode writeMode) override
void writeDescriptor(const QSharedPointer< QLowEnergyServicePrivate > service, const QLowEnergyHandle charHandle, const QLowEnergyHandle descriptorHandle, const QByteArray &newValue) override
void readDescriptor(const QSharedPointer< QLowEnergyServicePrivate > service, const QLowEnergyHandle charHandle, const QLowEnergyHandle descriptorHandle) override
void readCharacteristic(const QSharedPointer< QLowEnergyServicePrivate > service, const QLowEnergyHandle charHandle) override