• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 THERMAL_SRV_CONFIG_PARSER_H
17 #define THERMAL_SRV_CONFIG_PARSER_H
18 
19 #include <string>
20 #include <vector>
21 #include <mutex>
22 #include <memory>
23 #include <libxml/tree.h>
24 #include "thermal_config_sensor_cluster.h"
25 #include "thermal_policy.h"
26 
27 namespace OHOS {
28 namespace PowerMgr {
29 class ThermalSrvConfigParser {
30 public:
31     ThermalSrvConfigParser();
32     static ThermalSrvConfigParser &GetInstance();
33     ~ThermalSrvConfigParser() = default;
34     ThermalSrvConfigParser(const ThermalSrvConfigParser&) = delete;
35     ThermalSrvConfigParser& operator=(const ThermalSrvConfigParser&) = delete;
36     bool ThermalSrvConfigInit(std::string &path);
37     bool ParseXMLFile(std::string &path);
38 private:
39     void ParseBaseNode(xmlNodePtr node);
40     void ParseLevelNode(xmlNodePtr node);
41     void ParseStateNode(xmlNodePtr node);
42     void ParseActionNode(xmlNodePtr node);
43     void ParsePolicyNode(xmlNodePtr node);
44     void ParseIdleNode(xmlNodePtr node);
45     void ParseAuxSensorInfo(const xmlNode *cur, std::shared_ptr<ThermalConfigSensorCluster> &sc);
46     void ParseSensorInfo(const xmlNode *cur, std::shared_ptr<ThermalConfigSensorCluster> &sc);
47     std::vector<AuxLevelItem> ParseAuxSensorSubnodeInfo(const xmlNode *cur,
48         std::vector<std::string>& auxsensors, const uint32_t i);
49     bool ParseAuxSensorSubnodeInfoTrigerRange(const xmlNode *subNode, std::vector<std::string>& auxsensors,
50         std::string& tempRanges, const uint32_t i);
51     void ParseSensorSubnodeInfo(const xmlNode *cur, std::vector<LevelItem>& vItem, std::vector<std::string>& sensors,
52         const uint32_t i, std::shared_ptr<ThermalConfigSensorCluster> &sc);
53     void ParsePolicySubnode(const xmlNode *cur, PolicyConfig& policyConfig);
54     std::mutex mutex_;
55 };
56 } // namespace PowerMgr
57 } // namespace OHOS
58 #endif //  THERMAL_SRV_CONFIG_PARSER_H
59