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 ParseTempDiffInfo(const xmlNodePtr& cur, SensorClusterPtr& sc); 50 bool ParseTempDiffLevInfo(const xmlNodePtr& cur, 51 const std::string& sensor1, const std::string& sensor2, TempDiffInfoList& infoList); 52 bool ParseTempDiffValue(const xmlNodePtr& cur, 53 const std::string& sensor1, const std::string& sensor2, TempDiffItem& item); 54 bool ParseAuxSensorLevInfo(const xmlNodePtr& cur, std::vector<std::string>& auxsensors, 55 const uint32_t sensorIdx, std::vector<AuxLevelItem>& auxLevelItem); 56 bool ParseAuxSensorTriggerRange(const xmlNodePtr& subNode, std::vector<std::string>& auxsensors, 57 std::string& tempRangeStr, const uint32_t sensorIdx); 58 bool ParseSensorLevelInfo(const xmlNodePtr& cur, std::vector<LevelItem>& levelItems, 59 std::vector<std::string>& sensors, const uint32_t sensorIdx, SensorClusterPtr& sc); 60 bool ParseLevelThreshold(const xmlNodePtr& subNode, LevelItem& levelItem, 61 std::vector<std::string>& sensors, const uint32_t sensorIdx); 62 bool ParseActionInfo(const xmlNodePtr& cur, ActionItem& ai); 63 bool ParsePolicyActionInfo(const xmlNodePtr& cur, PolicyConfig& policyConfig); 64 bool ParseFanNode(const xmlNodePtr& cur); 65 bool ParseFanFaultInfo(const xmlNodePtr& cur, 66 std::vector<std::string> &sensors, FanFaultInfoMap &fanFaultInfoMap); 67 bool DecryptConfig(const std::string& path, std::string& result); 68 }; 69 } // namespace PowerMgr 70 } // namespace OHOS 71 #endif // THERMAL_SRV_CONFIG_PARSER_H 72