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