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 manager, including observer and common functions. 21 * 22 * @since 6 23 */ 24 25 /** 26 * @file interface_adapter_manager.h 27 * 28 * @brief Adapter manager interface. 29 * 30 * @since 6 31 */ 32 33 #ifndef INTERFACE_ADAPTER_MANAGER 34 #define INTERFACE_ADAPTER_MANAGER 35 36 #include "interface_adapter.h" 37 #include <memory> 38 39 namespace bluetooth { 40 /** 41 * @brief Represents adapter state change observer during enable/disable. 42 * 43 * @since 6 44 */ 45 class IAdapterStateObserver { 46 public: 47 /** 48 * @brief A destructor used to delete the <b>IAdapterStateObserver</b> instance. 49 * 50 * @since 6 51 */ 52 virtual ~IAdapterStateObserver() = default; 53 54 /** 55 * @brief IAdapterStateObserver state change function. 56 * 57 * @param transport Transport type when state change. 58 * @param state Change to the new state. 59 * @since 6 60 */ 61 virtual void OnStateChange(const BTTransport transport, const BTStateID state) = 0; 62 }; 63 64 /** 65 * @brief System state define, using to OnSystemChange()... 66 */ 67 enum class BTSystemState : int { 68 ON, 69 OFF, 70 }; 71 72 /** 73 * @brief Represents system state change observer during start/stop/factoryReset/reset. 74 * 75 * @since 6 76 */ 77 class ISystemStateObserver { 78 public: 79 /** 80 * @brief A destructor used to delete the <b>ISystemStateObserver</b> instance. 81 * 82 * @since 6 83 */ 84 virtual ~ISystemStateObserver() = default; 85 86 /** 87 * @brief OnSystemStateChange state change function. 88 * 89 * @param transport Transport type when state change. 90 * @param state Change to 91 * @since 6 92 */ 93 virtual void OnSystemStateChange(const BTSystemState state) = 0; 94 }; 95 96 /** 97 * @brief Represents interface adapter manager. 98 * 99 * @since 6 100 */ 101 class BLUETOOTH_API IAdapterManager { 102 public: 103 /** 104 * @brief A destructor used to delete the <b>IAdapterManager</b> instance. 105 * 106 * @since 6 107 */ 108 virtual ~IAdapterManager() = default; 109 110 /** 111 * @brief Get adapter manager singleton instance pointer. 112 * 113 * @return Returns the singleton instance pointer. 114 * @since 6 115 */ 116 static IAdapterManager *GetInstance(); 117 118 /** 119 * @brief Reset bluetooth service. 120 * 121 * @return Returns <b>true</b> if the operation is successful; 122 * returns <b>false</b> if the operation fails. 123 * @since 6 124 */ 125 virtual void Reset() const = 0; 126 127 /** 128 * @brief Start bluetooth service. 129 * 130 * @return Returns <b>true</b> if the operation is successful; 131 * returns <b>false</b> if the operation fails. 132 * @since 6 133 */ 134 virtual bool Start() = 0; 135 136 /** 137 * @brief Stop bluetooth service. 138 * 139 * @since 6 140 */ 141 virtual void Stop() const = 0; 142 143 /** 144 * @brief Factory reset bluetooth service. 145 * 146 * @return Returns <b>true</b> if the operation is successful; 147 * returns <b>false</b> if the operation fails. 148 * @since 6 149 */ 150 virtual bool FactoryReset() const = 0; 151 152 /** 153 * @brief Enable bluetooth service. 154 * 155 * @param transport Enable classic or ble. 156 * @return Returns <b>true</b> if the operation is accepted; 157 * returns <b>false</b> if the operation is rejected. 158 * @since 6 159 */ 160 virtual bool Enable(const BTTransport transport) const = 0; 161 162 /** 163 * @brief Disable bluetooth service. 164 * 165 * @param transport Disable classic or ble. 166 * @return Returns <b>true</b> if the operation is accepted; 167 * returns <b>false</b> if the operation is rejected. 168 * @since 6 169 */ 170 virtual bool Disable(const BTTransport transport) const = 0; 171 172 /** 173 * @brief Get adapter enable/disable state. 174 * 175 * @param transport Disable classic or ble. 176 * @return Returns adapter enable/disable state. 177 * @since 6 178 */ 179 virtual BTStateID GetState(const BTTransport transport) const = 0; 180 181 /** 182 * @brief Get adapter connects state. 183 * 184 * @return Returns adapter connects state. 185 * @since 6 186 */ 187 virtual BTConnectState GetAdapterConnectState() const = 0; 188 189 /** 190 * @brief Register adapter state observer. 191 * 192 * @param observer Class IAdapterStateObserver pointer to register observer. 193 * @return Returns <b>true</b> if the operation is successful; 194 * returns <b>false</b> if the operation fails. 195 * @since 6 196 */ 197 virtual bool RegisterStateObserver(IAdapterStateObserver &observer) const = 0; 198 199 /** 200 * @brief Deregister adapter state observer. 201 * 202 * @param observer Class IAdapterStateObserver pointer to deregister observer. 203 * @return Returns <b>true</b> if the operation is successful; 204 * returns <b>false</b> if the operation fails. 205 * @since 6 206 */ 207 virtual bool DeregisterStateObserver(IAdapterStateObserver &observer) const = 0; 208 209 /** 210 * @brief Register system state observer. 211 * 212 * @param observer Class ISystemStateObserver pointer to register observer. 213 * @return Returns <b>true</b> if the operation is successful; 214 * returns <b>false</b> if the operation fails. 215 * @since 6 216 */ 217 virtual bool RegisterSystemStateObserver(ISystemStateObserver &observer) const = 0; 218 219 /** 220 * @brief Deregister system state observer. 221 * 222 * @param observer Class ISystemStateObserver pointer to deregister observer. 223 * @return Returns <b>true</b> if the operation is successful; 224 * returns <b>false</b> if the operation fails. 225 * @since 6 226 */ 227 virtual bool DeregisterSystemStateObserver(ISystemStateObserver &observer) const = 0; 228 229 /** 230 * @brief Get max audio connected devices number. 231 * 232 * @return Returns max device number that audio can connect. 233 * @since 6 234 */ 235 virtual int GetMaxNumConnectedAudioDevices() const = 0; 236 237 /** 238 * @brief Set phonebook permission for device. 239 * 240 * @param address Device address which is setted permission. 241 * @param permission Permission grade. 242 * @return Returns <b>true</b> if the operation is successful; 243 * returns <b>false</b> if the operation fails. 244 * @since 6 245 */ 246 virtual bool SetPhonebookPermission(const std::string &address, BTPermissionType permission) const = 0; 247 248 /** 249 * @brief Get phonebook permission for device. 250 * 251 * @param address Device address which is setted permission. 252 * @return Returns Permission grade. 253 * @since 6 254 */ 255 virtual BTPermissionType GetPhonebookPermission(const std::string &address) const = 0; 256 257 /** 258 * @brief Set message permission for device. 259 * 260 * @param address Device address which is setted permission. 261 * @param permission Permission grade. 262 * @return Returns <b>true</b> if the operation is successful; 263 * returns <b>false</b> if the operation fails. 264 * @since 6 265 */ 266 virtual bool SetMessagePermission(const std::string &address, BTPermissionType permission) const = 0; 267 268 /** 269 * @brief Get message permission for device. 270 * 271 * @param address Device address which is setted permission. 272 * @return Returns Permission grade. 273 * @since 6 274 */ 275 virtual BTPermissionType GetMessagePermission(const std::string &address) const = 0; 276 277 /** 278 * @brief Get classic adapter or ble adapter. 279 * 280 * @param transport classic or adapter. 281 * @return Returns Basic adapter pointer. 282 * @since 6 283 */ 284 virtual IAdapter *GetAdapter(const BTTransport transport) const = 0; 285 286 /** 287 * @brief Get power mode. 288 * 289 * @param address Device address. 290 * @return Returns power mode grade. 291 * BTPowerMode::MODE_INVALID = 0x00, 292 * BTPowerMode::MODE_ACTIVE = 0x100, 293 * BTPowerMode::MODE_SNIFF_LEVEL_LOW = 0x201, 294 * BTPowerMode::MODE_SNIFF_LEVEL_MID = 0x202, 295 * BTPowerMode::MODE_SNIFF_LEVEL_HIG = 0x203, 296 * @since 6 297 */ 298 virtual int GetPowerMode(const std::string &address) const = 0; 299 }; 300 } // namespace bluetooth 301 302 #endif // INTERFACE_ADAPTER_MANAGER