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 QLOWENERGYCONTROLLERPRIVATEBASE_P_H |
5 | #define QLOWENERGYCONTROLLERPRIVATEBASE_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 <qglobal.h> |
19 | #include <QtCore/qobject.h> |
20 | |
21 | #include <QtBluetooth/qlowenergycontroller.h> |
22 | |
23 | #include "qlowenergyserviceprivate_p.h" |
24 | |
25 | QT_BEGIN_NAMESPACE |
26 | |
27 | typedef QMap<QBluetoothUuid, QSharedPointer<QLowEnergyServicePrivate> > ServiceDataMap; |
28 | |
29 | class QLowEnergyControllerPrivate : public QObject |
30 | { |
31 | Q_OBJECT |
32 | public: |
33 | // This class is required to enable selection of multiple |
34 | // alternative QLowEnergyControllerPrivate implementations on BlueZ. |
35 | // Bluez has a low level ATT protocol stack implementation and a DBus |
36 | // implementation. |
37 | |
38 | QLowEnergyControllerPrivate(); |
39 | virtual ~QLowEnergyControllerPrivate(); |
40 | |
41 | // interface definition |
42 | virtual void init() = 0; |
43 | virtual void connectToDevice() = 0; |
44 | virtual void disconnectFromDevice() = 0; |
45 | |
46 | virtual void discoverServices() = 0; |
47 | virtual void discoverServiceDetails(const QBluetoothUuid &service, |
48 | QLowEnergyService::DiscoveryMode mode) = 0; |
49 | |
50 | virtual void readCharacteristic( |
51 | const QSharedPointer<QLowEnergyServicePrivate> service, |
52 | const QLowEnergyHandle charHandle) = 0; |
53 | virtual void readDescriptor( |
54 | const QSharedPointer<QLowEnergyServicePrivate> service, |
55 | const QLowEnergyHandle charHandle, |
56 | const QLowEnergyHandle descriptorHandle) = 0; |
57 | |
58 | virtual void writeCharacteristic( |
59 | const QSharedPointer<QLowEnergyServicePrivate> service, |
60 | const QLowEnergyHandle charHandle, |
61 | const QByteArray &newValue, |
62 | QLowEnergyService::WriteMode writeMode) = 0; |
63 | virtual void writeDescriptor( |
64 | const QSharedPointer<QLowEnergyServicePrivate> service, |
65 | const QLowEnergyHandle charHandle, |
66 | const QLowEnergyHandle descriptorHandle, |
67 | const QByteArray &newValue) = 0; |
68 | |
69 | virtual void startAdvertising( |
70 | const QLowEnergyAdvertisingParameters ¶ms, |
71 | const QLowEnergyAdvertisingData &advertisingData, |
72 | const QLowEnergyAdvertisingData &scanResponseData) = 0; |
73 | virtual void stopAdvertising() = 0; |
74 | |
75 | virtual void requestConnectionUpdate( |
76 | const QLowEnergyConnectionParameters & params) = 0; |
77 | virtual void addToGenericAttributeList( |
78 | const QLowEnergyServiceData &service, |
79 | QLowEnergyHandle startHandle) = 0; |
80 | |
81 | virtual int mtu() const = 0; |
82 | virtual void (); |
83 | |
84 | virtual QLowEnergyService *addServiceHelper( |
85 | const QLowEnergyServiceData &service); |
86 | |
87 | // common backend methods |
88 | bool isValidLocalAdapter(); |
89 | void setError(QLowEnergyController::Error newError); |
90 | void setState(QLowEnergyController::ControllerState newState); |
91 | |
92 | // public variables |
93 | QLowEnergyController::Role role; |
94 | QLowEnergyController::RemoteAddressType addressType; |
95 | |
96 | // list of all found service uuids on remote device |
97 | ServiceDataMap serviceList; |
98 | // list of all found service uuids on local peripheral device |
99 | ServiceDataMap localServices; |
100 | |
101 | //common helper functions |
102 | QSharedPointer<QLowEnergyServicePrivate> serviceForHandle(QLowEnergyHandle handle); |
103 | QLowEnergyCharacteristic characteristicForHandle(QLowEnergyHandle handle); |
104 | QLowEnergyDescriptor descriptorForHandle(QLowEnergyHandle handle); |
105 | quint16 updateValueOfCharacteristic(QLowEnergyHandle charHandle, |
106 | const QByteArray &value, |
107 | bool appendValue); |
108 | quint16 updateValueOfDescriptor(QLowEnergyHandle charHandle, |
109 | QLowEnergyHandle descriptorHandle, |
110 | const QByteArray &value, |
111 | bool appendValue); |
112 | void invalidateServices(); |
113 | |
114 | protected: |
115 | QLowEnergyController::ControllerState state = QLowEnergyController::UnconnectedState; |
116 | QLowEnergyController::Error error = QLowEnergyController::NoError; |
117 | QString errorString; |
118 | |
119 | QBluetoothAddress remoteDevice; |
120 | QBluetoothAddress localAdapter; |
121 | |
122 | QLowEnergyHandle lastLocalHandle{}; |
123 | |
124 | QString remoteName; // device name of the remote |
125 | QBluetoothUuid deviceUuid; // quite useless anywhere but Darwin (CoreBluetooth). |
126 | |
127 | Q_DECLARE_PUBLIC(QLowEnergyController) |
128 | QLowEnergyController *q_ptr; |
129 | }; |
130 | |
131 | QT_END_NAMESPACE |
132 | |
133 | #endif // QLOWENERGYCONTROLLERPRIVATEBASE_P_H |
134 | |