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); 45 std::vector<LevelItem> GetLevelItems(const std::string& name, const std::string& sensor); GetSensorInfoMap()46 std::map<std::string, SensorInfoMap> GetSensorInfoMap() 47 { 48 return sensorInfoMap_; 49 } 50 private: 51 bool LoadThermalSrvConfigXml(const std::string& path); 52 void ParseBaseNode(xmlNodePtr node); 53 void ParseLevelNode(xmlNodePtr node); 54 void ParseStateNode(xmlNodePtr node); 55 void ParseActionNode(xmlNodePtr node); 56 void ParsePolicyNode(xmlNodePtr node); 57 void ParseIdleNode(xmlNodePtr node); 58 void ParseAuxSensorInfo( 59 const std::string& name, const xmlNode* cur, std::shared_ptr<ThermalConfigSensorCluster>& sc); 60 void ParseSensorInfo(const std::string& name, const xmlNode* cur, std::shared_ptr<ThermalConfigSensorCluster>& sc); 61 std::vector<AuxLevelItem> ParseAuxSensorSubnodeInfo(const xmlNode* cur, 62 std::vector<std::string>& auxSensorList, const uint32_t i); 63 bool ParseAuxSensorSubnodeInfoTrigerRange(const xmlNode* subNode, std::vector<std::string>& auxSensorList, 64 std::string& tempRanges, const uint32_t i); 65 void ParseSensorSubnodeInfo(const xmlNode* cur, std::vector<LevelItem>& vItem, std::vector<std::string>& sensors, 66 const uint32_t i, std::shared_ptr<ThermalConfigSensorCluster>& sc); 67 void ParsePolicySubnode(const xmlNode* cur, PolicyConfig& policyConfig); 68 BaseInfoMap baseInfoMap_; 69 std::vector<StateItem> stateItem_; 70 std::vector<ActionItem> actionItem_; 71 ThermalPolicy::PolicyConfigMap policyConfigMap_; 72 std::map<std::string, std::shared_ptr<ThermalConfigSensorCluster>> sensorClusterMap_; 73 std::map<std::string, SensorInfoMap> sensorInfoMap_; 74 std::map<std::string, AuxSensorInfoMap> auxSensorInfoMap_; 75 }; 76 } // namespace PowerMgr 77 } // namespace OHOS 78 #endif // THERMAL_CONFIG_PARSER_H