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