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 <libxml/tree.h>
22 #include "fan_fault_detect.h"
23 #include "thermal_action_manager.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     ~ThermalSrvConfigParser() = default;
33     ThermalSrvConfigParser(const ThermalSrvConfigParser&) = delete;
34     ThermalSrvConfigParser& operator=(const ThermalSrvConfigParser&) = delete;
35     bool ThermalSrvConfigInit(const std::string& path);
36     bool ParseXmlFile(const std::string& path);
37 
38 private:
39     bool ParseRootNode(const xmlNodePtr& node);
40     bool ParseBaseNode(const xmlNodePtr& node);
41     bool ParseLevelNode(const xmlNodePtr& node);
42     bool ParseStateNode(const xmlNodePtr& node);
43     bool ParseActionNode(const xmlNodePtr& node);
44     bool ParsePolicyNode(const xmlNodePtr& node);
45     bool ParseIdleNode(const xmlNodePtr& node);
46     bool ParseLevelState(const xmlNodePtr& cur, SensorClusterPtr& sc);
47     bool ParseAuxSensorInfo(const xmlNodePtr& cur, SensorClusterPtr& sc);
48     bool ParseSensorInfo(const xmlNodePtr& cur, SensorClusterPtr& sc);
49     bool ParseAuxSensorLevInfo(const xmlNodePtr& cur, std::vector<std::string>& auxsensors,
50         const uint32_t sensorIdx, std::vector<AuxLevelItem>& auxLevelItem);
51     bool ParseAuxSensorTriggerRange(const xmlNodePtr& subNode, std::vector<std::string>& auxsensors,
52         std::string& tempRangeStr, const uint32_t sensorIdx);
53     bool ParseSensorLevelInfo(const xmlNodePtr& cur, std::vector<LevelItem>& levelItems,
54         std::vector<std::string>& sensors, const uint32_t sensorIdx, SensorClusterPtr& sc);
55     bool ParseLevelThreshold(const xmlNodePtr& subNode, LevelItem& levelItem,
56         std::vector<std::string>& sensors, const uint32_t sensorIdx);
57     bool ParseActionInfo(const xmlNodePtr& cur, ActionItem& ai);
58     bool ParsePolicyActionInfo(const xmlNodePtr& cur, PolicyConfig& policyConfig);
59     bool ParseFanNode(const xmlNodePtr& cur);
60     bool ParseFanFaultInfo(const xmlNodePtr& cur,
61         std::vector<std::string> &sensors, FanFaultInfoMap &fanFaultInfoMap);
62     bool DecryptConfig(const std::string& path, std::string& result);
63 };
64 } // namespace PowerMgr
65 } // namespace OHOS
66 #endif //  THERMAL_SRV_CONFIG_PARSER_H
67