• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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();
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<ParsedConfigData> GetParsedData()
43     {
44         return std::move(mParsedData_);
45     }
46 
47 private:
48     int32_t GetHgmXmlNodeAsInt(xmlNode &node) const;
49     bool ParseInternal(xmlNode &node);
50     int32_t ParseParam(xmlNode &node);
51     int32_t ParseParams(xmlNode &node);
52     int32_t ParseSetting(xmlNode &node, std::unordered_map<std::string, std::string> &config);
53     int32_t ParserAnimationDynamicSetting(xmlNode &node);
54     int32_t ParseStrat(xmlNode &node);
55     std::string ExtractPropertyValue(const std::string &propName, xmlNode &node);
56     static bool IsNumber(const std::string &str);
57 
58     xmlDoc *xmlDocument_;
59     static constexpr char CONFIG_FILE[] = "/system/etc/graphic/hgm_policy_config.xml";
60     std::unordered_map<std::string, int> hgmXmlLabel_;
61     std::unique_ptr<ParsedConfigData> mParsedData_ = nullptr;
62 };
63 } // namespace OHOS::Rosen
64 #endif // HGM_XML_PARSER_H