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 PROFILE_CONFIG_H 17 #define PROFILE_CONFIG_H 18 19 #include <string> 20 #include <vector> 21 22 #include "base/base_def.h" 23 24 namespace OHOS { 25 namespace bluetooth { 26 const std::string SECTION_CONNECTION_POLICIES = "ConnectionPolicies"; 27 const std::string SECTION_PERMISSION = "Permission"; 28 const std::string SECTION_CODE_CS_SUPPORT = "CodecsSupport"; 29 30 const std::string PROPERTY_A2DP_CONNECTION_POLICY = "A2dpConnectionPolicy"; 31 const std::string PROPERTY_A2DP_SINK_CONNECTION_POLICY = "A2dpSinkConnectionPolicy"; 32 const std::string PROPERTY_HFP_CONNECTION_POLICY = "HfpConnectionPolicy"; 33 const std::string PROPERTY_HFP_CLIENT_CONNECTION_POLICY = "HfpClientConnectionPolicy"; 34 const std::string PROPERTY_PBAP_CONNECTION_POLICY = "PbapConnectionPolicy"; 35 const std::string PROPERTY_PBAP_CLIENT_CONNECTION_POLICY = "PbapClientConnectionPolicy"; 36 const std::string PROPERTY_MAP_CONNECTION_POLICY = "MapConnectionPolicy"; 37 38 const std::string PROPERTY_MAP_CLIENT_CONNECTION_POLICY = "MapClientConnectionPolicy"; 39 const std::string PROPERTY_GATT_CLIENT_CONNECTION_POLICY = "GattClientConnectionPolicy"; 40 const std::string PROPERTY_GATT_SERVER_CONNECTION_POLICY = "GattServerConnectionPolicy"; 41 const std::string PROPERTY_PHONEBOOK_PERMISSION = "PhonebookPermission"; 42 const std::string PROPERTY_MESSAGE_PERMISSION = "MessagePermission"; 43 const std::string PROPERTY_A2DP_SUPPORTS_OPTIONAL_CODECS = "A2dpSupportsOptionalCodecs"; 44 const std::string PROPERTY_A2DP_OPTIONAL_CODECS_ENABLED = "A2dpOptionalCodecsEnabled"; 45 46 class IProfileConfig { 47 public: 48 virtual ~IProfileConfig() = default; 49 /** 50 * @brief Load XML document form file. 51 * 52 * @return true Success load xml document. 53 * @return false Failed load xml document. 54 * @since 6 55 */ 56 virtual bool Load() = 0; 57 58 /** 59 * @brief Reload XML Document from specified path. 60 * @return true Success reload XML Document. 61 * @return false Failed reload XML Document. 62 */ 63 virtual bool Reload() = 0; 64 65 /** 66 * @brief Get specified property value. 67 * Value type is int. 68 * 69 * @param addr Bluetooth device addr. 70 * @param section 71 * @param property 72 * @param value Value type is int. 73 * @return true Success get specified property's value. 74 * @return false Failed get specified property's value. 75 * @since 6 76 */ 77 virtual bool GetValue( 78 const std::string &addr, const std::string §ion, const std::string &property, int &value) = 0; 79 80 /** 81 * @brief Get specified property value. 82 * Value type is int. 83 * 84 * @param addr 85 * @param section 86 * @param property 87 * @param value Value type is bool. 88 * @return true Success get specified property's value. 89 * @return false Failed get specified property's value. 90 * @since 6 91 */ 92 virtual bool GetValue( 93 const std::string &addr, const std::string §ion, const std::string &property, bool &value) = 0; 94 95 /** 96 * @brief Set specified property value. 97 * Value type is int. 98 * 99 * @param section 100 * @param subSection 101 * @param property 102 * @param value Value type is const int. 103 * @return true Success set specified property's value. 104 * @return false Failed set specified property's value. 105 * @since 6 106 */ 107 virtual bool SetValue( 108 const std::string &addr, const std::string §ion, const std::string &property, int &value) = 0; 109 110 /** 111 * @brief Set specified property value. 112 * Value type is int. 113 * 114 * @param section 115 * @param subSection 116 * @param property 117 * @param value Value type is const bool. 118 * @return true Success set specified property's value. 119 * @return false Failed set specified property's value. 120 * @since 6 121 */ 122 virtual bool SetValue( 123 const std::string &addr, const std::string §ion, const std::string &property, bool &value) = 0; 124 125 /** 126 * @brief Remove specified addr, as well as it's all sections and properties. 127 * 128 * @param Addr 129 * @return true Success remove specified addr's value. 130 * @return false Failed remove specified addr's value. 131 * @since 6 132 */ 133 virtual bool RemoveAddr(const std::string &addr) = 0; 134 135 /** 136 * @brief Remove specified property value. 137 * Value type is int. 138 * @param addr 139 * @param section 140 * @param property 141 * @param value Value type is const int. 142 * @return true Success remove specified property's value. 143 * @return false Failed remove specified property's value. 144 * @since 6 145 */ 146 virtual bool RemoveProperty(const std::string &addr, const std::string §ion, const std::string &property) = 0; 147 148 /** 149 * @brief Whether XML document has specified section. 150 * 151 * @param addr 152 * @param section 153 * @return true XML document has specified section. 154 * @return false XML document doesnot have specified section. 155 * @since 6 156 */ 157 virtual bool HasSection(const std::string &addr, const std::string §ion) = 0; 158 }; 159 160 class ProfileConfig : public IProfileConfig { 161 public: 162 /** 163 * @brief Get the Instance object 164 * 165 * @return IProfileConfig* 166 * @since 6 167 */ 168 static IProfileConfig *GetInstance(); 169 170 /** 171 * @brief Load XML document form file. 172 * 173 * @return true Success load xml document. 174 * @return false Failed load xml document. 175 * @since 6 176 */ 177 virtual bool Load() override; 178 179 /** 180 * @brief Reload XML Document from specified path. 181 * @return true Success reload XML Document. 182 * @return false Failed reload XML Document. 183 */ 184 virtual bool Reload() override; 185 186 /** 187 * @brief Get specified property value. 188 * Value type is int. 189 * 190 * @param addr Bluetooth device addr. 191 * @param section 192 * @param property 193 * @param value Value type is int. 194 * @return true Success get specified property's value. 195 * @return false Failed get specified property's value. 196 * @since 6 197 */ 198 virtual bool GetValue( 199 const std::string &addr, const std::string §ion, const std::string &property, int &value) override; 200 201 /** 202 * @brief Get specified property value. 203 * Value type is int. 204 * 205 * @param addr 206 * @param section 207 * @param property 208 * @param value Value type is bool. 209 * @return true Success get specified property's value. 210 * @return false Failed get specified property's value. 211 * @since 6 212 */ 213 virtual bool GetValue( 214 const std::string &addr, const std::string §ion, const std::string &property, bool &value) override; 215 216 /** 217 * @brief Set specified property value. 218 * Value type is int. 219 * 220 * @param section 221 * @param subSection 222 * @param property 223 * @param value Value type is const int. 224 * @return true Success set specified property's value. 225 * @return false Failed set specified property's value. 226 * @since 6 227 */ 228 virtual bool SetValue( 229 const std::string &addr, const std::string §ion, const std::string &property, int &value) override; 230 231 /** 232 * @brief Set specified property value. 233 * Value type is int. 234 * 235 * @param section 236 * @param subSection 237 * @param property 238 * @param value Value type is const bool. 239 * @return true Success set specified property's value. 240 * @return false Failed set specified property's value. 241 * @since 6 242 */ 243 virtual bool SetValue( 244 const std::string &addr, const std::string §ion, const std::string &property, bool &value) override; 245 246 /** 247 * @brief Remove specified addr, as well as it's all sections and properties. 248 * 249 * @param Addr 250 * @return true Success remove specified addr's value. 251 * @return false Failed remove specified addr's value. 252 * @since 6 253 */ 254 virtual bool RemoveAddr(const std::string &addr) override; 255 256 /** 257 * @brief Remove specified property value. 258 * Value type is int. 259 * @param addr 260 * @param section 261 * @param property 262 * @param value Value type is const int. 263 * @return true Success remove specified property's value. 264 * @return false Failed remove specified property's value. 265 * @since 6 266 */ 267 virtual bool RemoveProperty( 268 const std::string &addr, const std::string §ion, const std::string &property) override; 269 270 /** 271 * @brief Whether XML document has specified section. 272 * 273 * @param addr 274 * @param section 275 * @return true XML document has specified section. 276 * @return false XML document doesnot have specified section. 277 * @since 6 278 */ 279 virtual bool HasSection(const std::string &addr, const std::string §ion) override; 280 281 private: 282 /** 283 * @brief Construct a new Profile Config object 284 */ 285 ProfileConfig(); 286 287 /** 288 * @brief Destroy the Profile Config object 289 */ 290 ~ProfileConfig(); 291 292 DECLARE_IMPL(); 293 }; 294 } // namespace bluetooth 295 } // namespace OHOS 296 297 #endif // PROFILE_CONFIG_H