1 /*
2  * Copyright (C) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Bluetooth
18  * @{
19  *
20  * @brief Defines a bluetooth system that provides basic bluetooth connection and profile functions,
21  *        including A2DP, AVRCP, BLE, GATT, HFP, MAP, PBAP, and SPP, etc.
22  *
23  * @since 6
24  *
25  */
26 
27 /**
28  * @file interface_profile_gatt_client.h
29  *
30  * @brief Declares GATT client role interface profile functions.
31  *
32  * @since 6
33  *
34  */
35 #ifndef INTERFACE_PROFILE_GATT_CLIENT_H
36 #define INTERFACE_PROFILE_GATT_CLIENT_H
37 
38 #include "interface_profile.h"
39 #include "gatt_data.h"
40 #include <vector>
41 
42 namespace OHOS {
43 namespace bluetooth {
44 /**
45  * @brief Class for IGattClientCallback functions.
46  *
47  * @since 6
48  *
49  */
50 class IGattClientCallback {
51 public:
52     /**
53      * @brief The callback function to notify services changed.
54      *
55      * @param services Service list.
56      * @since 6
57      *
58      */
59     virtual void OnServicesChanged(const std::vector<Service> &services) = 0;
60     /**
61      * @brief The callback function to notify characteristic read.
62      *
63      * @param ret Result of the callback.
64      * @param characteristic Characteristic object.
65      * @since 6
66      *
67      */
68     virtual void OnCharacteristicRead(int ret, const Characteristic &characteristic) = 0;
69     /**
70      * @brief The callback function to notify characteristic write.
71      *
72      * @param ret Result of the callback.
73      * @param characteristic Characteristic object.
74      * @since 6
75      *
76      */
77     virtual void OnCharacteristicWrite(int ret, const Characteristic &characteristic) = 0;
78     /**
79      * @brief The callback function to notify characteristic changed.
80      *
81      * @param characteristic Characteristic object.
82      * @param needConfirm Status of confirm need.
83      * @since 6
84      *
85      */
86     virtual void OnCharacteristicChanged(const Characteristic &characteristic) = 0;
87     /**
88      * @brief The callback function to notify descriptor read.
89      *
90      * @param ret Result of the callback.
91      * @param descriptor Descriptor object.
92      * @since 6
93      *
94      */
95     virtual void OnDescriptorRead(int ret, const Descriptor &descriptor) = 0;
96     /**
97      * @brief The callback function to notify descriptor write.
98      *
99      * @param ret Result of the callback.
100      * @param descriptor Descriptor object.
101      * @since 6
102      *
103      */
104     virtual void OnDescriptorWrite(int ret, const Descriptor &descriptor) = 0;
105     /**
106      * @brief The callback function to notify connection state changed.
107      *
108      * @param state Current state.
109      * @param newState New state.
110      * @since 6
111      *
112      */
113     virtual void OnConnectionStateChanged(int state, int newState) = 0;
114     /**
115      * @brief The callback function to notify mtu changed.
116      *
117      * @param state Current state.
118      * @param mtu Current mtu.
119      * @since 6
120      *
121      */
122     virtual void OnMtuChanged(int state, int mtu) = 0;
123 
124     virtual void OnServicesDiscovered(int status) = 0;
125     /**
126      * @brief Destroy the IGattClientCallback.
127      *
128      * @since 6
129      *
130      */
~IGattClientCallback()131     virtual ~IGattClientCallback()
132     {}
133 
134     virtual void OnConnectionParameterChanged(int interval, int latency, int timeout, int status) = 0;
135     virtual void OnReadRemoteRssiValue(const RawAddress &addr, int rssi, int status) = 0;
136 };
137 
138 /**
139  * @brief Class for IProfileGattClient functions.
140  *
141  * @since 6
142  *
143  */
144 class IProfileGattClient : public IProfile {
145 public:
146     /**
147      * @brief The function to register application.
148      *
149      * @param callback Callback object.
150      * @param addr Address object.
151      * @param transport Transport type.
152      * @return int api accept status.
153      * @since 6
154      *
155      */
156     virtual int RegisterApplication(IGattClientCallback &callback, const RawAddress &addr, uint8_t transport) = 0;
157 
158     virtual int RegisterSharedApplication(IGattClientCallback &callback, const RawAddress &addr, uint8_t transport) = 0;
159     /**
160      * @brief The function to deregister application.
161      *
162      * @param appId Application id.
163      * @return int api accept status.
164      * @since 6
165      *
166      */
167     virtual int DeregisterApplication(int appId) = 0;
168     /**
169      * @brief The function to connect.
170      *
171      * @param appId Application id.
172      * @return int api accept status.
173      * @since 6
174      *
175      */
176     virtual int Connect(int appId, bool autoConnect) = 0;
177     /**
178      * @brief The function to disconnect.
179      *
180      * @param appId Application id.
181      * @return int api accept status.
182      * @since 6
183      *
184      */
185     virtual int Disconnect(int appId) = 0;
186     /**
187      * @brief The function to discovery services.
188      *
189      * @param appId Application id.
190      * @return int api accept status.
191      * @since 6
192      *
193      */
194     virtual int DiscoveryServices(int appId) = 0;
195     /**
196      * @brief The function to read characteristic.
197      *
198      * @param appId Application id.
199      * @param characteristic Characteristic object.
200      * @return int api accept status.
201      * @since 6
202      *
203      */
204     virtual int ReadCharacteristic(int appId, const Characteristic &characteristic) = 0;
205 
206     virtual int ReadCharacteristicByUuid(int appId, const Uuid &uuid) = 0;
207     /**
208      * @brief The function to write characteristic.
209      *
210      * @param appId Application id.
211      * @param characteristic Characteristic object.
212      * @param withoutRespond Respond status.
213      * @return int api accept status.
214      * @since 6
215      *
216      */
217     virtual int WriteCharacteristic(int appId, Characteristic &characteristic, bool withoutRespond = false) = 0;
218     /**
219      * @brief The function to signed write characteristic.
220      *
221      * @param appId Application id.
222      * @param characteristic Characteristic object.
223      * @param withoutRespond Respond status.
224      * @return int api accept status.
225      * @since 6
226      *
227      */
228     virtual int SignedWriteCharacteristic(int appId, Characteristic &characteristic) = 0;
229 
230     /**
231      * @brief The function to read descriptor.
232      *
233      * @param appId Application id.
234      * @param descriptor Descriptor object.
235      * @return int api accept status.
236      * @since 6
237      *
238      */
239     virtual int ReadDescriptor(int appId, const Descriptor &descriptor) = 0;
240     /**
241      * @brief The function to write descriptor.
242      *
243      * @param appId Application id.
244      * @param descriptor Descriptor object.
245      * @return int api accept status.
246      * @since 6
247      *
248      */
249     virtual int WriteDescriptor(int appId, Descriptor &descriptor) = 0;
250     /**
251      * @brief The function to request exchange mtu.
252      *
253      * @param appId Application id.
254      * @param mtu Expected mtu.
255      * @return int api accept status.
256      * @since 6
257      *
258      */
259     virtual int RequestExchangeMtu(int appId, int mtu) = 0;
260     /**
261      * @brief The function to get all devices.
262      *
263      * @return std::vector<GattDevice> devices list.
264      * @since 6
265      *
266      */
267     virtual std::vector<GattDevice> GetAllDevice() = 0;
268 
269     virtual int RequestConnectionPriority(int appId, int connPriority) = 0;
270 
271     virtual std::vector<Service> GetServices(int appId) = 0;
272 
273 private:
274     using IProfile::Connect;
275     using IProfile::Disconnect;
276 };
277 }  // namespace bluetooth
278 }  // namespace OHOS
279 
280 #endif  // INTERFACE_PROFILE_GATT_CLIENT_H