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_HDF_CONFIG_H 17 #define THERMAL_HDF_CONFIG_H 18 19 #include <string> 20 #include <vector> 21 #include <memory> 22 #include <map> 23 #include <libxml/xpath.h> 24 #include <libxml/tree.h> 25 #include <libxml/parser.h> 26 27 #include "base_info_config.h" 28 #include "sensor_info_config.h" 29 #include "isolate_info_config.h" 30 31 namespace OHOS { 32 namespace HDI { 33 namespace Thermal { 34 namespace V1_1 { 35 struct XMLThermal { 36 std::string version; 37 std::string product; 38 }; 39 40 struct DfxTraceInfo { 41 std::string title; 42 std::string valuePath; 43 }; 44 45 struct XmlTraceConfig { 46 std::string outPath; 47 }; 48 49 class ThermalHdfConfig { 50 public: 51 using GroupMap = std::map<std::string, std::shared_ptr<SensorInfoConfig>>; 52 using PollingMap = std::map<std::string, GroupMap>; ThermalHdfConfig()53 ThermalHdfConfig() {}; 54 ~ThermalHdfConfig() = default; 55 ThermalHdfConfig(const ThermalHdfConfig&) = delete; 56 ThermalHdfConfig& operator=(const ThermalHdfConfig&) = delete; 57 static ThermalHdfConfig& GetInstance(); 58 59 int32_t ThermalHDIConfigInit(const std::string& path); 60 int32_t ParseThermalHdiXMLConfig(const std::string& path); 61 void ParseBaseNode(xmlNodePtr node); 62 void ParsePollingNode(xmlNodePtr node); 63 void ParsePollingSubNode(xmlNodePtr node, XMLThermalNodeInfo& tn); 64 void ParseTracingNode(xmlNodePtr node); 65 void ParseTracingSubNode(xmlNodePtr node); 66 void ParseConfigInfo(const xmlNode* cur, std::vector<XMLThermalZoneInfo>& tzInfoList, 67 std::vector<XMLThermalNodeInfo>& tnInfoList); 68 std::string GetXmlNodeName(xmlNodePtr node, std::string &defaultName); 69 void GetThermalZoneNodeInfo(XMLThermalZoneInfo& tz, const xmlNode* node); GetBaseConfig()70 std::shared_ptr<BaseInfoConfig> GetBaseConfig() 71 { 72 return baseConfig_; 73 } GetTracingInfo()74 std::vector<DfxTraceInfo>& GetTracingInfo() 75 { 76 return traceInfo_; 77 } GetXmlTraceConfig()78 XmlTraceConfig& GetXmlTraceConfig() 79 { 80 return traceConfig_; 81 } GetPollingConfig()82 PollingMap& GetPollingConfig() 83 { 84 return pollingMap_; 85 } 86 87 using IsolateInfoMap = std::map<std::string, std::shared_ptr<IsolateInfoConfig>>; 88 void ParseIsolateNode(xmlNodePtr node); 89 void ParseIsolateSubNode(xmlNodePtr node, IsolateNodeInfo& tn); 90 int32_t GetIsolateCpuNodePath(bool isSim, const std::string &type, std::string &path); 91 private: 92 std::shared_ptr<BaseInfoConfig> baseConfig_; 93 PollingMap pollingMap_; 94 XMLThermal thermal_; 95 XmlTraceConfig traceConfig_; 96 std::vector<DfxTraceInfo> traceInfo_; 97 IsolateInfoMap isolateInfoMap_; 98 }; 99 } // V1_1 100 } // Thermal 101 } // HDI 102 } // OHOS 103 104 #endif // THERMAL_HDF_CONFIG_H 105