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 30 namespace OHOS { 31 namespace HDI { 32 namespace Thermal { 33 namespace V1_0 { 34 struct XMLThermal { 35 std::string version; 36 std::string product; 37 }; 38 39 struct DfxTraceInfo { 40 std::string title; 41 std::string value; 42 }; 43 44 struct XMLTracingInfo { 45 std::string interval; 46 std::string outpath; 47 }; 48 49 class ThermalHdfConfig { 50 public: 51 using ThermalTypeMap = std::map<std::string, std::shared_ptr<SensorInfoConfig>>; ThermalHdfConfig()52 ThermalHdfConfig() {}; 53 ~ThermalHdfConfig() = default; 54 ThermalHdfConfig(const ThermalHdfConfig&) = delete; 55 ThermalHdfConfig& operator=(const ThermalHdfConfig&) = delete; 56 static ThermalHdfConfig& GetInsance(); 57 58 int32_t ThermalHDIConfigInit(const std::string& path); 59 int32_t ParseThermalHdiXMLConfig(const std::string& path); 60 void ParseBaseNode(xmlNodePtr node); 61 void ParsePollingNode(xmlNodePtr node); 62 void ParsePollingSubNode(xmlNodePtr node, XMLThermalNodeInfo& tn); 63 void ParseTracingNode(xmlNodePtr node); 64 void ParseTracingSubNode(xmlNodePtr node); 65 void ParseConfigInfo(const xmlNode* cur, std::vector<XMLThermalZoneInfo>& tzInfoList, 66 std::vector<XMLThermalNodeInfo>& tnInfoList); 67 ThermalTypeMap GetSensorTypeMap(); SetSensorTypeMap(const ThermalTypeMap & typesMap)68 void SetSensorTypeMap(const ThermalTypeMap& typesMap) 69 { 70 typesMap_ = typesMap; 71 } 72 void GetThermalZoneNodeInfo(XMLThermalZoneInfo& tz, const xmlNode* node); GetBaseConfig()73 std::shared_ptr<BaseInfoConfig> GetBaseConfig() 74 { 75 return baseConfig_; 76 } GetTracingInfo()77 std::vector<DfxTraceInfo> GetTracingInfo() 78 { 79 return traceInfo_; 80 } GetXmlTraceInfo()81 XMLTracingInfo GetXmlTraceInfo() 82 { 83 return trace_; 84 } 85 private: 86 std::shared_ptr<BaseInfoConfig> baseConfig_; 87 ThermalTypeMap typesMap_; 88 XMLThermal thermal_; 89 XMLTracingInfo trace_; 90 std::vector<DfxTraceInfo> traceInfo_; 91 }; 92 } // V1_0 93 } // Thermal 94 } // HDI 95 } // OHOS 96 97 #endif // THERMAL_HDF_CONFIG_H 98