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 ADAPTER_DEVICE_INFO_H 17 #define ADAPTER_DEVICE_INFO_H 18 19 #include <mutex> 20 #include <string> 21 #include <vector> 22 23 #include "base/base_def.h" 24 25 /* 26 * @brief The Bluetooth subsystem. 27 */ 28 namespace OHOS { 29 namespace bluetooth { 30 const std::string SECTION_BLE = "BLE"; 31 const std::string PROPERTY_SYSYTEM_ID = "SystemId"; 32 const std::string PROPERTY_PNP_ID = "PnpId"; 33 const std::string PROPERTY_IEEE_INFO = "IEEEInfo"; 34 const std::string PROPERTY_MANUFACTURER_NAME = "ManufactureName"; 35 const std::string PROPERTY_MODEL_NUMBER = "ModelNumber"; 36 const std::string PROPERTY_SERIAL_NUMBER = "SerialNumber"; 37 const std::string PROPERTY_HARDWARE_REVISION = "HardwareRevision"; 38 const std::string PROPERTY_FIRMWARE_REVISION = "FirmwareRevision"; 39 const std::string PROPERTY_SOFTWARE_REVISION = "SoftwareRevision"; 40 41 const std::string DEVICE_INFO_PATH = "./bt_device_info.xml"; 42 const std::string SECTION_BREDR = "BR/EDR"; 43 const std::string PROPERTY_SPECIFICATION_ID = "SpecificationID"; 44 const std::string PROPERTY_VENDOR_ID = "VendorID"; 45 const std::string PROPERTY_PRODUCT_ID = "ProductID"; 46 const std::string PROPERTY_VERSION = "Version"; 47 const std::string PROPERTY_PRIMARY_RECORD = "PrimaryRecord"; 48 const std::string PROPERTY_VENDOR_ID_SOURCE = "VendorIDSource"; 49 50 /** 51 * @brief Device info config. 52 */ 53 class IAdapterDeviceInfo { 54 public: 55 virtual ~IAdapterDeviceInfo() = default; 56 /** 57 * @brief Load XML Document from specified path. 58 * @return true Success Load XML Document. 59 * @return false Failed Load XML Document. 60 */ 61 virtual bool Load() = 0; 62 63 /** 64 * @brief Reload XML Document from specified path. 65 * @return true Success reload XML Document. 66 * @return false Failed reload XML Document. 67 */ 68 virtual bool Reload() = 0; 69 70 /** 71 * @brief Get specified property value. 72 * @param[in] section 73 * @param[in] property 74 * @param[out] value String type value. 75 * @return true Success get specified property's value. 76 * @return false Failed get specified property's value. 77 */ 78 virtual bool GetValue(const std::string §ion, const std::string &property, std::string &value) = 0; 79 80 /** 81 * @brief Get specified property value. 82 * @param[in] section 83 * @param[in] property 84 * @param[out] value Int type value. 85 * @return true Success get specified property's value. 86 * @return false Failed get specified property's value. 87 */ 88 virtual bool GetValue(const std::string §ion, const std::string &property, int &value) = 0; 89 90 /** 91 * @brief Get specified property value. 92 * @param[in] section 93 * @param[in] property 94 * @param[out] value Bool type value. 95 * @return true Success get specified property's value. 96 * @return false Failed get specified property's value. 97 */ 98 virtual bool GetValue(const std::string §ion, const std::string &property, bool &value) = 0; 99 }; 100 101 class AdapterDeviceInfo : public IAdapterDeviceInfo { 102 public: 103 /** 104 * @brief Get the Instance object 105 * @return IAdapterConfig* 106 */ 107 static IAdapterDeviceInfo *GetInstance(); 108 109 /** 110 * @brief Load XML Document from specified path. 111 * @return true Success Load XML Document. 112 * @return false Failed Load XML Document. 113 */ 114 virtual bool Load() override; 115 116 /** 117 * @brief Reload XML Document from specified path. 118 * @return true Success reload XML Document. 119 * @return false Failed reload XML Document. 120 */ 121 virtual bool Reload() override; 122 123 /** 124 * @brief Get specified property value. 125 * @param[in] section 126 * @param[in] property 127 * @param[out] value String type value. 128 * @return true Success get specified property's value. 129 * @return false Failed get specified property's value. 130 */ 131 virtual bool GetValue(const std::string §ion, const std::string &property, std::string &value) override; 132 133 /** 134 * @brief Get specified property value. 135 * @param[in] section 136 * @param[in] property 137 * @param[out] value Int type value. 138 * @return true Success get specified property's value. 139 * @return false Failed get specified property's value. 140 */ 141 virtual bool GetValue(const std::string §ion, const std::string &property, int &value) override; 142 143 /** 144 * @brief Get specified property value. 145 * @param[in] section 146 * @param[in] property 147 * @param[out] value Bool type value. 148 * @return true Success get specified property's value. 149 * @return false Failed get specified property's value. 150 */ 151 virtual bool GetValue(const std::string §ion, const std::string &property, bool &value) override; 152 153 private: 154 /** 155 * @brief Construct a new Adapter Config object 156 */ 157 AdapterDeviceInfo(); 158 159 /** 160 * @brief Destroy the Adapter Config object 161 */ 162 ~AdapterDeviceInfo(); 163 164 std::mutex mutex_ {}; 165 static AdapterDeviceInfo *g_instance; 166 DECLARE_IMPL(); 167 }; 168 } // namespace bluetooth 169 } // namespace OHOS 170 171 #endif // ADAPTER_DEVICE_INFO_H