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