1 /* 2 * Copyright (C) 2021-2022 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_CONFIG_H 17 #define ADAPTER_CONFIG_H 18 19 #include <memory> 20 #include <string> 21 #include "base/base_def.h" 22 23 namespace OHOS { 24 namespace bluetooth { 25 // define section name 26 const std::string SECTION_CLASSIC_ADAPTER = "ClassicAdapter"; 27 const std::string SECTION_BLE_ADAPTER = "BleAdapter"; 28 const std::string SECTION_A2DP_SRC_SERVICE = "A2dpSrcService"; 29 const std::string SECTION_A2DP_SNK_SERVICE = "A2dpSnkService"; 30 const std::string SECTION_HFP_HF_SERVICE = "HfpHfService"; 31 const std::string SECTION_HFP_AG_SERVICE = "HfpAgService"; 32 const std::string SECTION_GATT_CLIENT_SERVICE = "GattClientService"; 33 const std::string SECTION_GATT_SERVICE = "GattService"; 34 const std::string SECTION_AVRCP_CT_SERVICE = "AvrcpCtService"; 35 const std::string SECTION_AVRCP_TG_SERVICE = "AvrcpTgService"; 36 const std::string SECTION_SOCKET_SERVICE = "SocketService"; 37 const std::string SECTION_MAP_MCE_SERVICE = "MapMceService"; 38 const std::string SECTION_MAP_MSE_SERVICE = "MapMseService"; 39 const std::string SECTION_PAN_SERVICE = "PanService"; 40 const std::string SECTION_PBAP_PCE_SERVICE = "PbapPceService"; 41 const std::string SECTION_PBAP_PSE_SERVICE = "PbapPseService"; 42 const std::string SECTION_HID_HOST_SERVICE = "HidHostService"; 43 const std::string SECTION_OPP_SERVICE = "OppService"; 44 const std::string SECTION_DI_SERVICE = "DIService"; 45 const std::string SECTION_OUTPUT_SETTING = "OutputSetting"; 46 47 // Output setting name 48 const std::string PROPERTY_BTSNOOP_OUTPUT = "BtsnoopOutput"; 49 const std::string PROPERTY_BTSNOOP_OUTPUT_PATH = "BtsnoopOutputPath"; 50 const std::string PROPERTY_HCILOG_OUTPUT = "HciLogOutput"; 51 const std::string PROPERTY_DESENSITIZATION = "Desensitization"; 52 const std::string PROPERTY_OUTPUTMAXSIZE = "BtOutputMaxSize"; 53 54 // define property name 55 const std::string PROPERTY_IS_VALID = "IsValid"; 56 const std::string PROPERTY_A2DP_OFFLOAD_ENABLE = "A2dpOffloadEnable"; 57 const std::string PROPERTY_CONNECT_POLICY = "ConnectPolicy"; 58 const std::string PROPERTY_CLASSIC_ADAPTER_ENABLE = "ClassicAdapterEnable"; 59 const std::string PROPERTY_BLE_ADAPTER_ENABLE = "BleAdapterEnable"; 60 const std::string PROPERTY_SERVICE_ENABLE = "ServiceEnable"; 61 const std::string PROPERTY_MAX_CONNECTED_DEVICES = "MaxConnectedDevices"; 62 const std::string PROPERTY_MAP_VERSION = "Version"; 63 64 const std::string PROPERTY_GATT_CLIENT_SERVICE = "GattClientService"; 65 const std::string PROPERTY_GATT_SERVER_SERVICE = "GattServerService"; 66 const std::string PROPERTY_A2DP_SNK_SERVICE = "A2dpSnkService"; 67 const std::string PROPERTY_A2DP_SRC_SERVICE = "A2dpSrcService"; 68 const std::string PROPERTY_AVRCP_CT_SERVICE = "AvrcpCtService"; 69 const std::string PROPERTY_AVRCP_TG_SERVICE = "AvrcpTgService"; 70 const std::string PROPERTY_HFP_HF_SERVICE = "HfpHfService"; 71 const std::string PROPERTY_HFP_AG_SERVICE = "HfpAgService"; 72 const std::string PROPERTY_MAP_MCE_SERVICE = "MapMceService"; 73 const std::string PROPERTY_MAP_MSE_SERVICE = "MapMseService"; 74 const std::string PROPERTY_PBAP_PCE_SERVICE = "PbapPceService"; 75 const std::string PROPERTY_PBAP_PSE_SERVICE = "PbapPseService"; 76 const std::string PROPERTY_SOCKET_SERVICE = "SocketService"; 77 const std::string PROPERTY_DI_SERVICE = "DIService"; 78 79 // GATT property 80 const std::string PROPERTY_GATT_PROFILE_MAX_MTU = "GattProfileMaxMtu"; 81 const std::string PROPERTY_BLE_MAX_CONNECTED_DEVICES = "BleMaxConnectedDevices"; 82 const std::string PROPERTY_BLE_MIN_CONNECTION_INTERVAL = "BleMinConnectionInterval"; 83 const std::string PROPERTY_BLE_MAX_CONNECTION_INTERVAL = "BleMaxConnectionInterval"; 84 const std::string PROPERTY_BLE_CONNECTION_LATENCY = "BleConnectionLatency"; 85 const std::string PROPERTY_BLE_CONNECTION_SUPERVISION_TIMEOUT = "BleConnectionSupervisionTimeout"; 86 const std::string PROPERTY_BLE_GATTSERVER_EXCHANGE_MTU = "BleGattServerExchangeMtu"; 87 const std::string PROPERTY_CLASSIC_MAX_CONNECTED_DEVICES = "ClassicMaxConnectedDevices"; 88 const std::string PROPERTY_CLASSIC_CONNECTION_MTU = "ClassicConnectionMtu"; 89 const std::string PROPERTY_CLASSIC_CONNECTION_MODE = "ClassicConnectionMode"; 90 const std::string PROPERTY_CLASSIC_CONNECTION_FLUSH_TIMEOUT = "ClassicConnectionFlushTimeout"; 91 const std::string PROPERTY_CLASSIC_CONNECTION_SECURITY_MODE = "ClassicConnectionSecurityMode"; 92 const std::string PROPERTY_HIGH_PRIORITY_MIN_INTERVAL = "HighPriorityMinInterval"; 93 const std::string PROPERTY_BALANCED_PRIORITY_MIN_INTERVAL = "BalancedPriorityMinInterval"; 94 const std::string PROPERTY_LOW_POWER_MIN_INTERVAL = "LowPowerMinInterval"; 95 const std::string PROPERTY_HIGH_PRIORITY_MAX_INTERVAL = "HighPriorityMaxInterval"; 96 const std::string PROPERTY_BALANCED_PRIORITY_MAX_INTERVAL = "BalancedPriorityMaxInterval"; 97 const std::string PROPERTY_LOW_POWER_MAX_INTERVAL = "LowPowerMaxInterval"; 98 const std::string PROPERTY_HIGH_PRIORITY_LATENCY = "HighPriorityLatency"; 99 const std::string PROPERTY_BALANCED_PRIORITY_LATENCY = "BalancedPriorityLatency"; 100 const std::string PROPERTY_LOW_POWER_LATENCY = "LowPowerLatency"; 101 const std::string PROPERTY_HIGH_PRIORITY_TIMEOUT = "HighPriorityTimeout"; 102 const std::string PROPERTY_BALANCED_PRIORITY_TIMEOUT = "BalancedPriorityTimeout"; 103 const std::string PROPERTY_LOW_POWER_TIMEOUT = "LowPowerTimeout"; 104 105 const std::string PROPERTY_CONTROL_MTU = "ControlMtu"; 106 const std::string PROPERTY_BROWSE_MTU = "BrowseMtu"; 107 108 // MAP/PBAP property 109 const std::string PROPERTY_SRM_ENABLE = "SrmEnable"; 110 const std::string PROPERTY_L2CAP_MTU = "L2capMtu"; 111 const std::string PROPERTY_RFCOMM_MTU = "RfcommMtu"; 112 113 // MCE property 114 const std::string PROPERTY_MAP_MAX_OF_GET_UREAD = "MaxOfGetUreadMessage"; 115 116 // A2dpSnk property 117 const std::string PROPERTY_CODEC_SBC = "CodecSbc"; 118 const std::string PROPERTY_CODEC_AAC = "CodecAac"; 119 120 const std::string PROPERTY_CODEC_SBC_SUPPORT = "CodecSbcSupport"; 121 const std::string PROPERTY_CODEC_AAC_SUPPORT = "CodecAacSupport"; 122 123 class IAdapterConfig { 124 public: 125 virtual ~IAdapterConfig() = default; 126 /** 127 * @brief Load XML Document from specified path. 128 * @return true Success Load XML Document. 129 * @return false Failed Load XML Document. 130 */ 131 virtual bool Load() = 0; 132 133 /** 134 * @brief Reload XML Document from specified path. 135 * @return true Success reload XML Document. 136 * @return false Failed reload XML Document. 137 */ 138 virtual bool Reload() = 0; 139 140 /** 141 * @brief Get specified property value. 142 * @param[in] section 143 * @param[in] property 144 * @param[out] value Int type value. 145 * @return true Success get specified property's value. 146 * @return false Failed get specified property's value. 147 */ 148 virtual bool GetValue(const std::string §ion, const std::string &property, int &value) = 0; 149 150 /** 151 * @brief Get specified property value. 152 * @param[in] section 153 * @param[in] property 154 * @param[out] value String type value. 155 * @return true Success get specified property's value. 156 * @return false Failed get specified property's value. 157 */ 158 virtual bool GetValue(const std::string §ion, const std::string &property, std::string &value) = 0; 159 160 /** 161 * @brief Get specified property value. 162 * @param[in] section 163 * @param[in] property 164 * @param[out] value Bool type value. 165 * @return true Success get specified property's value. 166 * @return false Failed get specified property's value. 167 */ 168 virtual bool GetValue(const std::string §ion, const std::string &property, bool &value) = 0; 169 170 /** 171 * @brief Whether XML document has specified section. 172 * @param[in] section 173 * @return true XML document has specified section. 174 * @return false XML document doesnot have specified section. 175 */ 176 virtual bool HasSection(const std::string §ion) = 0; 177 }; 178 179 class AdapterConfig : public IAdapterConfig { 180 public: 181 /** 182 * @brief Get the Instance object 183 * @return IAdapterConfig* 184 */ 185 static IAdapterConfig *GetInstance(); 186 187 /** 188 * @brief Load XML Document from specified path. 189 * @return true Success Load XML Document. 190 * @return false Failed Load XML Document. 191 */ 192 virtual bool Load() override; 193 194 /** 195 * @brief Reload XML Document from specified path. 196 * @return true Success reload XML Document. 197 * @return false Failed reload XML Document. 198 */ 199 virtual bool Reload() override; 200 201 /** 202 * @brief Get specified property value. 203 * @param[in] section 204 * @param[in] property 205 * @param[out] value Int type value. 206 * @return true Success get specified property's value. 207 * @return false Failed get specified property's value. 208 */ 209 virtual bool GetValue(const std::string §ion, const std::string &property, int &value) override; 210 211 /** 212 * @brief Get specified property value. 213 * @param[in] section 214 * @param[in] property 215 * @param[out] value String type value. 216 * @return true Success get specified property's value. 217 * @return false Failed get specified property's value. 218 */ 219 virtual bool GetValue(const std::string §ion, const std::string &property, std::string &value) override; 220 221 /** 222 * @brief Get specified property value. 223 * @param[in] section 224 * @param[in] property 225 * @param[out] value Bool type value. 226 * @return true Success get specified property's value. 227 * @return false Failed get specified property's value. 228 */ 229 virtual bool GetValue(const std::string §ion, const std::string &property, bool &value) override; 230 231 /** 232 * @brief Whether XML document has specified section. 233 * @param[in] section 234 * @return true XML document has specified section. 235 * @return false XML document doesnot have specified section. 236 */ 237 virtual bool HasSection(const std::string §ion) override; 238 239 private: 240 /** 241 * @brief Construct a new Adapter Config object 242 */ 243 AdapterConfig(); 244 245 /** 246 * @brief Destroy the Adapter Config object 247 */ 248 ~AdapterConfig(); 249 250 DECLARE_IMPL(); 251 }; 252 } // namespace bluetooth 253 } // namespace OHOS 254 255 #endif // ADAPTER_CONFIG_H