1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtBluetooth module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QLOWENERGYCONTROLLERPRIVATEBASE_P_H
41#define QLOWENERGYCONTROLLERPRIVATEBASE_P_H
42
43//
44// W A R N I N G
45// -------------
46//
47// This file is not part of the Qt API. It exists purely as an
48// implementation detail. This header file may change from version to
49// version without notice, or even be removed.
50//
51// We mean it.
52//
53
54#include <qglobal.h>
55#include <QtCore/qobject.h>
56
57#include <QtBluetooth/qlowenergycontroller.h>
58
59#include "qlowenergyserviceprivate_p.h"
60
61QT_BEGIN_NAMESPACE
62
63typedef QMap<QBluetoothUuid, QSharedPointer<QLowEnergyServicePrivate> > ServiceDataMap;
64
65class QLowEnergyControllerPrivate : public QObject
66{
67 Q_OBJECT
68public:
69 // This class is required to enable selection of multiple
70 // alternative QLowEnergyControllerPrivate implementations on BlueZ.
71 // Bluez has a low level ATT protocol stack implementation and a DBus
72 // implementation.
73
74 QLowEnergyControllerPrivate();
75 virtual ~QLowEnergyControllerPrivate();
76
77 // interface definition
78 virtual void init() = 0;
79 virtual void connectToDevice() = 0;
80 virtual void disconnectFromDevice() = 0;
81
82 virtual void discoverServices() = 0;
83 virtual void discoverServiceDetails(const QBluetoothUuid &/*service*/) = 0;
84
85 virtual void readCharacteristic(
86 const QSharedPointer<QLowEnergyServicePrivate> /*service*/,
87 const QLowEnergyHandle /*charHandle*/) = 0;
88 virtual void readDescriptor(
89 const QSharedPointer<QLowEnergyServicePrivate> /*service*/,
90 const QLowEnergyHandle /*charHandle*/,
91 const QLowEnergyHandle /*descriptorHandle*/) = 0;
92
93 virtual void writeCharacteristic(
94 const QSharedPointer<QLowEnergyServicePrivate> /*service*/,
95 const QLowEnergyHandle /*charHandle*/,
96 const QByteArray &/*newValue*/,
97 QLowEnergyService::WriteMode /*writeMode*/) = 0;
98 virtual void writeDescriptor(
99 const QSharedPointer<QLowEnergyServicePrivate> /*service*/,
100 const QLowEnergyHandle /*charHandle*/,
101 const QLowEnergyHandle /*descriptorHandle*/,
102 const QByteArray &/*newValue*/) = 0;
103
104 virtual void startAdvertising(
105 const QLowEnergyAdvertisingParameters &/* params */,
106 const QLowEnergyAdvertisingData &/* advertisingData */,
107 const QLowEnergyAdvertisingData &/* scanResponseData */) = 0;
108 virtual void stopAdvertising() = 0;
109
110 virtual void requestConnectionUpdate(
111 const QLowEnergyConnectionParameters & /* params */) = 0;
112 virtual void addToGenericAttributeList(
113 const QLowEnergyServiceData &/* service */,
114 QLowEnergyHandle /* startHandle */) = 0;
115
116
117 virtual QLowEnergyService *addServiceHelper(
118 const QLowEnergyServiceData &service);
119
120 // common backend methods
121 bool isValidLocalAdapter();
122 void setError(QLowEnergyController::Error newError);
123 void setState(QLowEnergyController::ControllerState newState);
124
125 // public variables
126 QLowEnergyController::Role role;
127 QLowEnergyController::RemoteAddressType addressType;
128
129 // list of all found service uuids on remote device
130 ServiceDataMap serviceList;
131 // list of all found service uuids on local peripheral device
132 ServiceDataMap localServices;
133
134 //common helper functions
135 QSharedPointer<QLowEnergyServicePrivate> serviceForHandle(QLowEnergyHandle handle);
136 QLowEnergyCharacteristic characteristicForHandle(QLowEnergyHandle handle);
137 QLowEnergyDescriptor descriptorForHandle(QLowEnergyHandle handle);
138 quint16 updateValueOfCharacteristic(QLowEnergyHandle charHandle,
139 const QByteArray &value,
140 bool appendValue);
141 quint16 updateValueOfDescriptor(QLowEnergyHandle charHandle,
142 QLowEnergyHandle descriptorHandle,
143 const QByteArray &value,
144 bool appendValue);
145 void invalidateServices();
146
147protected:
148 QLowEnergyController::ControllerState state = QLowEnergyController::UnconnectedState;
149 QLowEnergyController::Error error = QLowEnergyController::NoError;
150 QString errorString;
151
152 QBluetoothAddress remoteDevice;
153 QBluetoothAddress localAdapter;
154
155 QLowEnergyHandle lastLocalHandle{};
156
157 QString remoteName; // device name of the remote
158 QBluetoothUuid deviceUuid; // quite useless anywhere but Darwin (CoreBluetooth).
159
160 Q_DECLARE_PUBLIC(QLowEnergyController)
161 QLowEnergyController *q_ptr;
162};
163
164QT_END_NAMESPACE
165
166#endif // QLOWENERGYCONTROLLERPRIVATEBASE_P_H
167

source code of qtconnectivity/src/bluetooth/qlowenergycontrollerbase_p.h