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 #ifndef BLE_PROPERTIES_H 17 #define BLE_PROPERTIES_H 18 19 #include <mutex> 20 #include <string> 21 #include <vector> 22 23 #include "base_observer_list.h" 24 #include "ble_config.h" 25 #include "ble_defs.h" 26 #include "interface_adapter_ble.h" 27 28 namespace bluetooth { 29 /** 30 * @BleProperties to save and get classic properties. 31 */ 32 class BleProperties { 33 public: 34 /** 35 * @brief Constructor. 36 */ 37 BleProperties(BleProperties &) = delete; 38 39 /** 40 * @brief Constructor. 41 */ 42 BleProperties &operator=(const BleProperties &) = delete; 43 44 /** 45 * @brief Get ble Properties instance. 46 * 47 * @return @c advertiser instance. 48 */ 49 static BleProperties &GetInstance(); 50 51 bool SetLocalAddress(const std::string &addr) const; 52 bool SetLocalName(const std::string &name) const; 53 int SetBondableMode(const int mode) const; 54 bool SetIoCapability(const int ioCapability) const; 55 56 int GetBondableMode() const; 57 int GetIoCapability() const; 58 static int GetAppearance(); 59 std::string GetLocalAddress() const; 60 std::string GetLocalName() const; 61 std::string GetPasskey() const; 62 63 bool LoadBleConfigInfo() const; 64 bool ConfigBleProperties() const; 65 static bool SetBleRoles(uint8_t roles); 66 static int GetBleRoles(); 67 68 static bool SetPasskey(const std::string &passkey); 69 static bool SetBleModel1Level(int level); 70 static bool SetBleModel2Level(int level); 71 static bool SetBleSecurity(bool security); 72 static bool SetBleScanMode(int scanmode); 73 74 bool SaveDefaultValues() const; 75 bool GetAddrFromController() const; 76 77 void RegisterBleAdapterObserver(BaseObserverList<IAdapterBleObserver> &observer) const; 78 void DeregisterBleAdapterObserver(IAdapterBleObserver &observer) const; 79 80 private: 81 BleProperties(); 82 ~BleProperties(); 83 84 void ReadBleHostInfo() const; 85 bool UpdateConfig(int type) const; 86 DECLARE_IMPL(); 87 }; 88 } // namespace bluetooth 89 90 #endif // BLE_PROPERTIES_H 91