• 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 basic adapter for classic adapter and ble adapter.
21  *
22  * @since 6
23  */
24 
25 /**
26  * @file interface_adapter.h
27  *
28  * @brief basic adapter interface.
29  *
30  * @since 6
31  */
32 
33 #ifndef INTERFACE_ADAPTER_H
34 #define INTERFACE_ADAPTER_H
35 
36 #include <string>
37 #include <vector>
38 
39 #include "bt_def.h"
40 #include "bt_uuid.h"
41 #include "raw_address.h"
42 
43 /**
44  * @brief bluetooth adapter name Define
45  */
46 const std::string ADAPTER_NAME_CLASSIC = "ClassicAdapter";
47 const std::string ADAPTER_NAME_BLE = "BleAdapter";
48 
49 /**
50  * @brief forward declaration for class Context in namespace utility
51  */
52 namespace utility {
53 class Context;
54 }
55 
56 namespace bluetooth {
57 /**
58  * @brief Represents basic adapter for classic and ble, including the common functions.
59  *
60  * @since 6
61  */
62 class IAdapter {
63 public:
64     /**
65      * @brief A destructor used to delete the <b>IAdapter</b> instance.
66      *
67      * @since 6
68      */
69     virtual ~IAdapter() = default;
70 
71     /// gap
72     /**
73      * @brief Get local device address.
74      *
75      * @return Returns local device address.
76      * @since 6
77      */
78     virtual std::string GetLocalAddress() const = 0;
79 
80     /**
81      * @brief Get local device name.
82      *
83      * @return Returns local device name.
84      * @since 6
85      */
86     virtual std::string GetLocalName() const = 0;
87 
88     /**
89      * @brief Set local device name.
90      *
91      * @return Returns <b>true</b> if the operation is successful;
92      *         returns <b>false</b> if the operation fails.
93      * @since 6
94      */
95     virtual bool SetLocalName(const std::string &name) const = 0;
96 
97     /**
98      * @brief Set local device bondable mode.
99      *
100      * @return Returns <b>true</b> if the operation is successful;
101      *         returns <b>false</b> if the operation fails.
102      * @since 6
103      */
104     virtual bool SetBondableMode(int mode) const = 0;
105 
106     /**
107      * @brief Get local device bondable mode.
108      *
109      * @return Returns local device bondable mode.
110      * @since 6
111      */
112     virtual int GetBondableMode() const = 0;
113 
114     /// remote device information
115     /**
116      * @brief Get remote device type.
117      *
118      * @param device Remote device address.
119      * @return Returns remote device type.
120      * @since 6
121      */
122     virtual int GetDeviceType(const RawAddress &device) const = 0;
123 
124     /**
125      * @brief Get remote device name.
126      *
127      * @param device Remote device address.
128      * @return Returns remote device name.
129      * @since 6
130      */
131     virtual std::string GetDeviceName(const RawAddress &device) const = 0;
132 
133     /**
134      * @brief Get remote device uuids.
135      *
136      * @param device Remote device address.
137      * @return Returns remote device uuids vector.
138      * @since 6
139      */
140     virtual std::vector<Uuid> GetDeviceUuids(const RawAddress &device) const = 0;
141 
142     /// pair
143     /**
144      * @brief Get paired devices.
145      *
146      * @return Returns paired devices vector.
147      * @since 6
148      */
149     virtual std::vector<RawAddress> GetPairedDevices() const = 0;
150 
151     /**
152      * @brief Get remote device uuids.
153      *
154      * @param device Remote device address.
155      * @return Returns <b>true</b> if the operation is successful;
156      *         returns <b>false</b> if the operation fails.
157      * @since 6
158      */
159     virtual bool StartPair(const RawAddress &device) = 0;
160 
161     /**
162      * @brief Check if device was bonded from local.
163      *
164      * @param device Remote device address.
165      * @return Returns <b>true</b> if device was bonded from local;
166      *         returns <b>false</b> if device was not bonded from local.
167      * @since 6
168      */
169     virtual bool IsBondedFromLocal(const RawAddress &device) const = 0;
170 
171     /**
172      * @brief Cancel pair operation.
173      *
174      * @param device Remote device address.
175      * @return Returns <b>true</b> if the operation is successful;
176      *         returns <b>false</b> if the operation fails.
177      * @since 6
178      */
179     virtual bool CancelPairing(const RawAddress &device) = 0;
180 
181     /**
182      * @brief Remove pair.
183      *
184      * @param device Remote device address.
185      * @return Returns <b>true</b> if the operation is successful;
186      *         returns <b>false</b> if the operation fails.
187      * @since 6
188      */
189     virtual bool RemovePair(const RawAddress &device) = 0;
190 
191     /**
192      * @brief Remove all pairs.
193      *
194      * @return Returns <b>true</b> if the operation is successful;
195      *         returns <b>false</b> if the operation fails.
196      * @since 6
197      */
198     virtual bool RemoveAllPairs() = 0;
199 
200     /**
201      * @brief Get device pair state.
202      *
203      * @param device Remote device address.
204      * @return Returns device pair state.
205      * @since 6
206      */
207     virtual int GetPairState(const RawAddress &device) const = 0;
208 
209     /**
210      * @brief Set device pairing confirmation.
211      *
212      * @param device Remote device address.
213      * @param accept Set gap accept flag.
214      * @return Returns <b>true</b> if the operation is successful;
215      *         returns <b>false</b> if the operation fails.
216      * @since 6
217      */
218     virtual bool SetDevicePairingConfirmation(const RawAddress &device, bool accept) const = 0;
219 
220     /**
221      * @brief Set device pair passkey.
222      *
223      * @param device Remote device address.
224      * @param passkey Device passkey.
225      * @param accept Set gap accept flag.
226      * @return Returns <b>true</b> if the operation is successful;
227      *         returns <b>false</b> if the operation fails.
228      * @since 6
229      */
230     virtual bool SetDevicePasskey(const RawAddress &device, int passkey, bool accept) const = 0;
231 
232     /**
233      * @brief Check device pair request reply.
234      *
235      * @param device Remote device address.
236      * @param accept Set gap accept flag.
237      * @return Returns <b>true</b> if the operation is successful;
238      *         returns <b>false</b> if the operation fails.
239      * @since 6
240      */
241     virtual bool PairRequestReply(const RawAddress &device, bool accept) const = 0;
242 
243     /// other
244     /**
245      * @brief Check if device acl connected.
246      *
247      * @param device Remote device address.
248      * @return Returns <b>true</b> if device acl connected;
249      *         returns <b>false</b> if device does not acl connect.
250      * @since 6
251      */
252     virtual bool IsAclConnected(const RawAddress &device) const = 0;
253 
254     /**
255      * @brief Check if device acl Encrypted.
256      *
257      * @param device Remote device address.
258      * @return Returns <b>true</b> if device acl Encrypted;
259      *         returns <b>false</b> if device does not acl Encrypt.
260      * @since 6
261      */
262     virtual bool IsAclEncrypted(const RawAddress &device) const = 0;
263 
264     /**
265      * @brief Get utility::Context pointer for adapter.
266      *
267      * @return Returns the pointer for adapter.
268      * @since 6
269      */
270     virtual utility::Context *GetContext() = 0;
271 };
272 }  // namespace bluetooth
273 
274 #endif  // INTERFACE_ADAPTER_H