1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Copyright (C) 2016 Javier S. Pedro <maemo@javispedro.com> |
5 | ** Contact: https://www.qt.io/licensing/ |
6 | ** |
7 | ** This file is part of the QtBluetooth module of the Qt Toolkit. |
8 | ** |
9 | ** $QT_BEGIN_LICENSE:LGPL$ |
10 | ** Commercial License Usage |
11 | ** Licensees holding valid commercial Qt licenses may use this file in |
12 | ** accordance with the commercial license agreement provided with the |
13 | ** Software or, alternatively, in accordance with the terms contained in |
14 | ** a written agreement between you and The Qt Company. For licensing terms |
15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
16 | ** information use the contact form at https://www.qt.io/contact-us. |
17 | ** |
18 | ** GNU Lesser General Public License Usage |
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
20 | ** General Public License version 3 as published by the Free Software |
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
22 | ** packaging of this file. Please review the following information to |
23 | ** ensure the GNU Lesser General Public License version 3 requirements |
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
25 | ** |
26 | ** GNU General Public License Usage |
27 | ** Alternatively, this file may be used under the terms of the GNU |
28 | ** General Public License version 2.0 or (at your option) the GNU General |
29 | ** Public license version 3 or any later version approved by the KDE Free |
30 | ** Qt Foundation. The licenses are as published by the Free Software |
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
32 | ** included in the packaging of this file. Please review the following |
33 | ** information to ensure the GNU General Public License requirements will |
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
36 | ** |
37 | ** $QT_END_LICENSE$ |
38 | ** |
39 | ****************************************************************************/ |
40 | #ifndef QLOWENERGYSERVICE_H |
41 | #define QLOWENERGYSERVICE_H |
42 | |
43 | #include <QtBluetooth/QBluetoothAddress> |
44 | #include <QtBluetooth/QBluetoothUuid> |
45 | #include <QtBluetooth/QLowEnergyCharacteristic> |
46 | |
47 | QT_BEGIN_NAMESPACE |
48 | |
49 | class QLowEnergyServicePrivate; |
50 | class Q_BLUETOOTH_EXPORT QLowEnergyService : public QObject |
51 | { |
52 | Q_OBJECT |
53 | public: |
54 | enum ServiceType { |
55 | PrimaryService = 0x0001, |
56 | IncludedService = 0x0002 |
57 | }; |
58 | Q_ENUM(ServiceType) |
59 | Q_DECLARE_FLAGS(ServiceTypes, ServiceType) |
60 | |
61 | enum ServiceError { |
62 | NoError = 0, |
63 | OperationError, |
64 | CharacteristicWriteError, |
65 | DescriptorWriteError, |
66 | UnknownError, |
67 | CharacteristicReadError, |
68 | DescriptorReadError |
69 | }; |
70 | Q_ENUM(ServiceError) |
71 | |
72 | enum ServiceState { |
73 | InvalidService = 0, |
74 | DiscoveryRequired, // we know start/end handle but nothing more |
75 | //TODO Rename DiscoveringServices -> DiscoveringDetails or DiscoveringService |
76 | DiscoveringServices,// discoverDetails() called and running |
77 | ServiceDiscovered, // all details have been synchronized |
78 | LocalService, |
79 | }; |
80 | Q_ENUM(ServiceState) |
81 | |
82 | enum WriteMode { |
83 | WriteWithResponse = 0, |
84 | WriteWithoutResponse, |
85 | WriteSigned |
86 | }; |
87 | Q_ENUM(WriteMode) |
88 | |
89 | ~QLowEnergyService(); |
90 | |
91 | QList<QBluetoothUuid> includedServices() const; |
92 | |
93 | QLowEnergyService::ServiceTypes type() const; |
94 | QLowEnergyService::ServiceState state() const; |
95 | |
96 | QLowEnergyCharacteristic characteristic(const QBluetoothUuid &uuid) const; |
97 | QList<QLowEnergyCharacteristic> characteristics() const; |
98 | QBluetoothUuid serviceUuid() const; |
99 | QString serviceName() const; |
100 | |
101 | void discoverDetails(); |
102 | |
103 | ServiceError error() const; |
104 | |
105 | bool contains(const QLowEnergyCharacteristic &characteristic) const; |
106 | void readCharacteristic(const QLowEnergyCharacteristic &characteristic); |
107 | void writeCharacteristic(const QLowEnergyCharacteristic &characteristic, |
108 | const QByteArray &newValue, |
109 | WriteMode mode = WriteWithResponse); |
110 | |
111 | bool contains(const QLowEnergyDescriptor &descriptor) const; |
112 | void readDescriptor(const QLowEnergyDescriptor &descriptor); |
113 | void writeDescriptor(const QLowEnergyDescriptor &descriptor, |
114 | const QByteArray &newValue); |
115 | |
116 | Q_SIGNALS: |
117 | void stateChanged(QLowEnergyService::ServiceState newState); |
118 | void characteristicChanged(const QLowEnergyCharacteristic &info, |
119 | const QByteArray &value); |
120 | void characteristicRead(const QLowEnergyCharacteristic &info, |
121 | const QByteArray &value); |
122 | void characteristicWritten(const QLowEnergyCharacteristic &info, |
123 | const QByteArray &value); |
124 | void descriptorRead(const QLowEnergyDescriptor &info, |
125 | const QByteArray &value); |
126 | void descriptorWritten(const QLowEnergyDescriptor &info, |
127 | const QByteArray &value); |
128 | void error(QLowEnergyService::ServiceError error); |
129 | |
130 | private: |
131 | Q_DECLARE_PRIVATE(QLowEnergyService) |
132 | QSharedPointer<QLowEnergyServicePrivate> d_ptr; |
133 | |
134 | // QLowEnergyController is the factory for this class |
135 | friend class QLowEnergyController; |
136 | friend class QLowEnergyControllerPrivate; |
137 | friend class QLowEnergyControllerPrivateBluez; |
138 | friend class QLowEnergyControllerPrivateAndroid; |
139 | friend class QLowEnergyControllerPrivateDarwin; |
140 | QLowEnergyService(QSharedPointer<QLowEnergyServicePrivate> p, |
141 | QObject *parent = nullptr); |
142 | }; |
143 | |
144 | Q_DECLARE_OPERATORS_FOR_FLAGS(QLowEnergyService::ServiceTypes) |
145 | |
146 | QT_END_NAMESPACE |
147 | |
148 | Q_DECLARE_METATYPE(QLowEnergyService::ServiceError) |
149 | Q_DECLARE_METATYPE(QLowEnergyService::ServiceState) |
150 | Q_DECLARE_METATYPE(QLowEnergyService::ServiceType) |
151 | Q_DECLARE_METATYPE(QLowEnergyService::WriteMode) |
152 | |
153 | #endif // QLOWENERGYSERVICE_H |
154 | |