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