1 /* 2 * Copyright (c) 2022 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_CONFIG_PARSER_H 17 #define THERMAL_CONFIG_PARSER_H 18 19 #include <string> 20 #include <vector> 21 #include <libxml/tree.h> 22 23 #include "state_machine.h" 24 #include "thermal_action_manager.h" 25 #include "thermal_config_base_info.h" 26 #include "thermal_config_sensor_cluster.h" 27 #include "thermal_log.h" 28 #include "thermal_policy.h" 29 30 namespace OHOS { 31 namespace PowerMgr { 32 class ThermalConfigFileParser { 33 public: ThermalConfigFileParser()34 ThermalConfigFileParser() 35 { 36 THERMAL_HILOGI(LABEL_TEST, "Thermal config xml file parser instance is created"); 37 } 38 ~ThermalConfigFileParser() = default; 39 bool Init(); 40 bool GetActionEnableEvent(const std::string& actionName); 41 bool GetActionStrict(const std::string& actionName); 42 bool GetActionPolicy(const std::string& name, uint32_t level, std::vector<PolicyAction>& policy); 43 std::vector<StateItem> GetStateItem(); 44 bool ParseXmlFile(const std::string& path); GetSensorInfoMap()45 std::map<std::string, SensorInfoMap> GetSensorInfoMap() 46 { 47 return sensorInfoMap_; 48 } 49 private: 50 bool LoadThermalSrvConfigXml(const std::string& path); 51 void ParseBaseNode(xmlNodePtr node); 52 void ParseLevelNode(xmlNodePtr node); 53 void ParseStateNode(xmlNodePtr node); 54 void ParseActionNode(xmlNodePtr node); 55 void ParsePolicyNode(xmlNodePtr node); 56 void ParseIdleNode(xmlNodePtr node); 57 void ParseAuxSensorInfo(const xmlNode* cur, std::shared_ptr<ThermalConfigSensorCluster>& sc); 58 void ParseSensorInfo(const std::string& name, const xmlNode* cur, std::shared_ptr<ThermalConfigSensorCluster>& sc); 59 std::vector<AuxLevelItem> ParseAuxSensorSubnodeInfo(const xmlNode* cur, 60 std::vector<std::string>& auxSensorList, const uint32_t i); 61 bool ParseAuxSensorSubnodeInfoTrigerRange(const xmlNode* subNode, std::vector<std::string>& auxSensorList, 62 std::string& tempRanges, const uint32_t i); 63 void ParseSensorSubnodeInfo(const xmlNode* cur, std::vector<LevelItem>& vItem, std::vector<std::string>& sensors, 64 const uint32_t i, std::shared_ptr<ThermalConfigSensorCluster>& sc); 65 void ParsePolicySubnode(const xmlNode* cur, PolicyConfig& policyConfig); 66 BaseInfoMap baseInfoMap_; 67 std::vector<StateItem> stateItem_; 68 std::vector<ActionItem> actionItem_; 69 ThermalPolicy::PolicyConfigMap policyConfigMap_; 70 std::map<std::string, std::shared_ptr<ThermalConfigSensorCluster>> sensorClusterMap_; 71 std::map<std::string, SensorInfoMap> sensorInfoMap_; 72 }; 73 } // namespace PowerMgr 74 } // namespace OHOS 75 #endif // THERMAL_CONFIG_PARSER_H