1 /* 2 * Copyright (c) 2023 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 HGM_XML_PARSER_H 17 #define HGM_XML_PARSER_H 18 19 #include <string> 20 #include <unordered_map> 21 22 #include <libxml/parser.h> 23 #include <libxml/tree.h> 24 25 #include "hgm_command.h" 26 #include "hgm_log.h" 27 28 namespace OHOS::Rosen { 29 class XMLParser { 30 public: 31 int32_t LoadConfiguration(const char* fileDir); 32 int32_t Parse(); 33 void Destroy(); 34 XMLParser()35 explicit XMLParser() : xmlDocument_(nullptr) {} 36 ~XMLParser()37 ~XMLParser() 38 { 39 Destroy(); 40 } 41 GetParsedData()42 std::unique_ptr<PolicyConfigData> GetParsedData() 43 { 44 return std::move(mParsedData_); 45 } 46 47 static bool IsNumber(const std::string& str); 48 49 private: 50 static HgmXmlNode GetHgmXmlNodeAsInt(xmlNode& node); 51 bool ParseInternal(xmlNode& node); 52 int32_t ParseParam(xmlNode& node); 53 int32_t ParseParams(xmlNode& node); 54 int32_t ParseStrategyConfig(xmlNode& node); 55 int32_t ParseScreenConfig(xmlNode& node); 56 int32_t ParseSubScreenConfig(xmlNode& node, PolicyConfigData::ScreenSetting& screenSetting); 57 int32_t ParseSimplex(xmlNode& node, std::unordered_map<std::string, std::string>& config, 58 const std::string& valueName = "value", const std::string& keyName = "name", 59 const bool canBeEmpty = false); 60 int32_t ParsePowerStrategy(xmlNode& node, std::unordered_map<std::string, int32_t>& powerConfig); 61 int32_t ParseDynamicSetting(xmlNode& node, PolicyConfigData::DynamicSettingMap& dynamicSettingMap); 62 int32_t ParseSmallSizeDynamicSetting(xmlNode& node, PolicyConfigData::ScreenSetting& screenSetting); 63 int32_t ParseSceneList(xmlNode& node, PolicyConfigData::SceneConfigMap& sceneList); 64 int32_t ParseSupportedModeConfig(xmlNode& node, PolicyConfigData::SupportedModeConfig& supportedModeConfig); 65 int32_t ParseMultiAppStrategy(xmlNode& node, PolicyConfigData::ScreenSetting& screenSetting); 66 int32_t ParseAppTypes(xmlNode& node, std::unordered_map<int32_t, std::string>& appTypes); 67 int32_t ReplenishMissingScreenConfig(const PolicyConfigData::ScreenConfig& ScreenConfigDefalut, 68 PolicyConfigData::ScreenConfig& screenConfig); 69 void ReplenishMissingScreenAppGameConfig(PolicyConfigData::ScreenSetting& screenSetting, 70 const PolicyConfigData::ScreenSetting& screenSettingDefalut); 71 int32_t ParsePerformanceConfig(xmlNode& node, std::unordered_map<std::string, std::string>& performanceConfig); 72 int32_t ParseRefreshRate4Settings(xmlNode& node); 73 int32_t ParseVideoFrameVoteConfig(xmlNode& node); 74 std::string ExtractPropertyValue(const std::string& propName, xmlNode& node); 75 static std::vector<uint32_t> StringToVector(const std::string& str, const std::string& pattern = " "); 76 void ParseBufferStrategyList(xmlNode& node, PolicyConfigData::StrategyConfig& strategy); 77 int32_t ParseSubSequentParams(xmlNode& node, std::string& paraName); 78 void ParseAppBufferList(xmlNode& node); 79 int32_t ParsePageUrlStrategy(xmlNode& node, 80 std::unordered_map<std::string, PolicyConfigData::PageUrlConfig>& pageUrlConfigMap); 81 bool BuildStrategyConfig(xmlNode& currNode, PolicyConfigData::StrategyConfig& strategy); 82 xmlDoc* xmlDocument_ = nullptr; 83 std::unique_ptr<PolicyConfigData> mParsedData_ = nullptr; 84 }; 85 } // namespace OHOS::Rosen 86 #endif // HGM_XML_PARSER_H