• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 adapter classic, including observer and common functions.
21  *
22  * @since 6
23  */
24 
25 /**
26  * @file interface_adapter_classic.h
27  *
28  * @brief Adapter classic interface.
29  *
30  * @since 6
31  */
32 
33 #ifndef INTERFACE_ADAPTER_CLASSIC_H
34 #define INTERFACE_ADAPTER_CLASSIC_H
35 
36 #include "interface_adapter.h"
37 
38 namespace OHOS {
39 namespace bluetooth {
40 /**
41  * @brief Represents adapter classic observer.
42  *
43  * @since 6
44  */
45 class IAdapterClassicObserver {
46 public:
47     /**
48      * @brief A destructor used to delete the <b>IAdapterClassicObserver</b> instance.
49      *
50      * @since 6
51      */
52     virtual ~IAdapterClassicObserver() = default;
53 
54     /**
55      * @brief Discovery state changed observer.
56      *
57      * @param status Device discovery status.
58      * @since 6
59      */
60     virtual void OnDiscoveryStateChanged(int status) = 0;
61 
62     /**
63      * @brief Discovery result observer.
64      *
65      * @param device Remote device.
66      * @since 6
67      */
68     virtual void OnDiscoveryResult(const RawAddress &device) = 0;
69 
70     /**
71      * @brief Pair requester observer.
72      *
73      * @param device Remote device.
74      * @since 6
75      */
76     virtual void OnPairRequested(const BTTransport transport, const RawAddress &device) = 0;
77 
78     /**
79      * @brief Pair confirmed observer.
80      *
81      * @param device Remote device.
82      * @param reqType Pair type.
83      * @param number Paired passkey.
84      * @since 6
85      */
86     virtual void OnPairConfirmed(const BTTransport transport, const RawAddress &device, int reqType, int number) = 0;
87 
88     /**
89      * @brief Scan mode changed observer.
90      *
91      * @param mode Device scan mode.
92      * @since 6
93      */
94     virtual void OnScanModeChanged(int mode) = 0;
95 
96     /**
97      * @brief Device name changed observer.
98      *
99      * @param deviceName Device name.
100      * @since 6
101      */
102     virtual void OnDeviceNameChanged(const std::string &deviceName) = 0;
103 
104     /**
105      * @brief Device address changed observer.
106      *
107      * @param address Device address.
108      * @since 6
109      */
110     virtual void OnDeviceAddrChanged(const std::string &address) = 0;
111 };
112 
113 /**
114  * @brief Represents remote device observer.
115  *
116  * @since 6
117  */
118 class IClassicRemoteDeviceObserver {
119 public:
120     /**
121      * @brief A destructor used to delete the <b>IClassicRemoteDeviceObserver</b> instance.
122      *
123      * @since 6
124      */
125     virtual ~IClassicRemoteDeviceObserver() = default;
126 
127     /**
128      * @brief Pair status changed observer.
129      *
130      * @param device Remote device.
131      * @param status Remote device pair status.
132      * @since 6
133      */
134     virtual void OnPairStatusChanged(const BTTransport transport, const RawAddress &device, int status) = 0;
135 
136     /**
137      * @brief Remote uuid changed observer.
138      *
139      * @param device Remote device.
140      * @param uuids Remote device uuids.
141      * @since 6
142      */
143     virtual void OnRemoteUuidChanged(const RawAddress &device, const std::vector<Uuid> &uuids) = 0;
144 
145     /**
146      * @brief Remote name changed observer.
147      *
148      * @param device Remote device.
149      * @param deviceName Remote device name.
150      * @since 6
151      */
152     virtual void OnRemoteNameChanged(const RawAddress &device, const std::string &deviceName) = 0;
153 
154     /**
155      * @brief Remote alias changed observer.
156      *
157      * @param device Remote device.
158      * @param alias Remote device alias.
159      * @since 6
160      */
161     virtual void OnRemoteAliasChanged(const RawAddress &device, const std::string &alias) = 0;
162 
163     /**
164      * @brief Remote cod changed observer.
165      *
166      * @param device Remote device.
167      * @param cod Remote device cod.
168      * @since 6
169      */
170     virtual void OnRemoteCodChanged(const RawAddress &device, int cod) = 0;
171 
172     /**
173      * @brief Remote battery level changed observer.
174      *
175      * @param device Remote device.
176      * @param batteryLevel Remote device battery Level.
177      * @since 6
178      */
179     virtual void OnRemoteBatteryLevelChanged(const RawAddress &device, int batteryLevel) = 0;
180 };
181 
182 /**
183  * @brief Represents classic adapter interface.
184  *
185  * @since 6
186  */
187 class IAdapterClassic : public IAdapter {
188 public:
189     /**
190      * @brief A destructor used to delete the <b>IAdapterClassic</b> instance.
191      *
192      * @since 6
193      */
194     virtual ~IAdapterClassic() = default;
195 
196     /**
197      * @brief Get remote device class.
198      *
199      * @param device Remote device.
200      * @return Returns remote device class.
201      * @since 6
202      */
203     virtual int GetDeviceClass(const RawAddress &device) const = 0;
204 
205     /**
206      * @brief Get remote device alias name.
207      *
208      * @param device Remote device
209      * @return Returns remote device alias name.
210      * @since 6
211      */
212     virtual std::string GetAliasName(const RawAddress &device) const = 0;
213 
214     /**
215      * @brief Set remote device alias name.
216      *
217      * @param device Remote device which set alias name.
218      * @param name Alias name.
219      * @return Returns <b>true</b> if the operation is successful;
220      *         returns <b>false</b> if the operation fails.
221      * @since 6
222      */
223     virtual bool SetAliasName(const RawAddress &device, const std::string &name) const = 0;
224 
225     /**
226      * @brief Get remote device battery level.
227      *
228      * @param device Remote device
229      * @return Returns remote device battery level.
230      * @since 6
231      */
232     virtual int GetDeviceBatteryLevel(const RawAddress &device) const = 0;
233 
234     /**
235      * @brief Set remote device battery level.
236      *
237      * @param device Remote device
238      * @param batteryLevel battery level
239      * @since 6
240      */
241     virtual void SetDeviceBatteryLevel(const RawAddress &device, int batteryLevel) const = 0;
242 
243     /**
244      * @brief Register remote device observer.
245      *
246      * @param observer Class IClassicRemoteDeviceObserver pointer to register observer.
247      * @return Returns <b>true</b> if the operation is successful;
248      *         returns <b>false</b> if the operation fails.
249      * @since 6
250      */
251     virtual bool RegisterRemoteDeviceObserver(IClassicRemoteDeviceObserver &observer) const = 0;
252 
253     /**
254      * @brief Deregister remote device observer.
255      *
256      * @return Returns <b>true</b> if the operation is successful;
257      *         returns <b>false</b> if the operation fails.
258      * @since 6
259      */
260     virtual bool DeregisterRemoteDeviceObserver(IClassicRemoteDeviceObserver &observer) const = 0;
261 
262     /**
263      * @brief Set device scan mode.
264      *
265      * @param mode Scan mode.
266      * @param duration Scan time.
267      * @return Returns <b>true</b> if the operation is successful;
268      *         returns <b>false</b> if the operation fails.
269      * @since 6
270      */
271     virtual bool SetBtScanMode(int mode, int duration) = 0;
272 
273     /**
274      * @brief Get device scan mode.
275      *
276      * @return Returns bluetooth scan mode.
277      * @since 6
278      */
279     virtual int GetBtScanMode() const = 0;
280 
281     /**
282      * @brief Get local device class.
283      *
284      * @return Returns local device class.
285      * @since 6
286      */
287     virtual int GetLocalDeviceClass() const = 0;
288 
289     /**
290      * @brief Set local device class.
291      *
292      * @param deviceClass Device class.
293      * @return Returns <b>true</b> if the operation is successful;
294      *         returns <b>false</b> if the operation fails.
295      * @since 6
296      */
297     virtual bool SetLocalDeviceClass(int deviceClass) const = 0;
298 
299     /**
300      * @brief Get device address.
301      *
302      * @return Returns <b>true</b> if the operation is successful;
303      *         returns <b>false</b> if the operation fails.
304      * @since 6
305      */
306     virtual bool StartBtDiscovery() = 0;
307 
308     /**
309      * @brief Cancel device discovery.
310      *
311      * @return Returns <b>true</b> if the operation is successful;
312      *         returns <b>false</b> if the operation fails.
313      * @since 6
314      */
315     virtual bool CancelBtDiscovery() = 0;
316 
317     /**
318      * @brief Check if device is discovering.
319      *
320      * @return Returns <b>true</b> if device is discovering;
321      *         returns <b>false</b> if device is not discovering.
322      * @since 6
323      */
324     virtual bool IsBtDiscovering() const = 0;
325 
326     /**
327      * @brief Get device discovery end time.
328      *
329      * @return Returns device discovery end time.
330      * @since 6
331      */
332     virtual long GetBtDiscoveryEndMillis() const = 0;
333 
334     /**
335      * @brief Set device pair pin.
336      *
337      * @param device Remote device address.
338      * @param pinCode Pin code.
339      * @return Returns <b>true</b> if the operation is successful;
340      *         returns <b>false</b> if the operation fails.
341      * @since 6
342      */
343     virtual bool SetDevicePin(const RawAddress &device, const std::string &pinCode) const = 0;
344 
345     /**
346      * @brief Register classic adapter observer.
347      *
348      * @param observer Class IAdapterClassicObserver pointer to register observer.
349      * @return Returns <b>true</b> if the operation is successful;
350      *         returns <b>false</b> if the operation fails.
351      * @since 6
352      */
353     virtual bool RegisterClassicAdapterObserver(IAdapterClassicObserver &observer) const = 0;
354 
355     /**
356      * @brief Deregister classic adapter observer.
357      *
358      * @return Returns <b>true</b> if the operation is successful;
359      *         returns <b>false</b> if the operation fails.
360      * @since 6
361      */
362     virtual bool DeregisterClassicAdapterObserver(IAdapterClassicObserver &observer) const = 0;
363 };
364 }  // namespace bluetooth
365 }  // namespace OHOS
366 
367 #endif  // INTERFACE_ADAPTER_CLASSIC_H