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_ZONE_MANAGER_H 17 #define THERMAL_ZONE_MANAGER_H 18 19 #include <list> 20 #include <map> 21 #include <string> 22 #include <mutex> 23 #include "thermal_hdf_config.h" 24 #include "v1_1/thermal_types.h" 25 #include "v1_1/ithermal_callback.h" 26 #include "v1_1/ifan_callback.h" 27 28 namespace OHOS { 29 namespace HDI { 30 namespace Thermal { 31 namespace V1_1 { 32 struct ThermalZoneSysfsPathInfo { 33 char* name; 34 char temperturePath[PATH_MAX]; 35 char typePath[PATH_MAX]; 36 int32_t fd; 37 }; 38 39 struct ThermalSysfsPathInfo { 40 char* name; 41 char thermalZonePath[PATH_MAX]; 42 char coolingDevicePath[PATH_MAX]; 43 int32_t fd; 44 }; 45 46 class ThermalZoneManager { 47 public: 48 ThermalZoneManager() = default; 49 ~ThermalZoneManager() = default; 50 GetTzPathInfo()51 ThermalZoneSysfsPathInfo GetTzPathInfo() 52 { 53 return tzSysPathInfo_; 54 }; 55 SetTzPathInfo(ThermalZoneSysfsPathInfo tzSysPathInfo)56 void SetTzPathInfo(ThermalZoneSysfsPathInfo tzSysPathInfo) 57 { 58 tzSysPathInfo_ = tzSysPathInfo; 59 } 60 GetLTZPathInfo()61 std::list<ThermalZoneSysfsPathInfo> GetLTZPathInfo() 62 { 63 return lTzSysPathInfo_; 64 } 65 GetlTzInfo()66 std::vector<ThermalZoneInfo> GetlTzInfo() 67 { 68 return tzInfoList_; 69 } 70 ConvertInt(const std::string & value)71 int32_t ConvertInt(const std::string &value) 72 { 73 return std::stoi(value.c_str()); 74 } 75 SetThermalEventCb(const sptr<IThermalCallback> & thermalCb)76 void SetThermalEventCb(const sptr<IThermalCallback> &thermalCb) 77 { 78 thermalCb_ = thermalCb; 79 } 80 DelThermalEventCb()81 void DelThermalEventCb() 82 { 83 thermalCb_ = nullptr; 84 } 85 SetFanEventCb(const sptr<IFanCallback> & fanCb)86 void SetFanEventCb(const sptr<IFanCallback> &fanCb) 87 { 88 fanCb_ = fanCb; 89 } 90 DelFanEventCb()91 void DelFanEventCb() 92 { 93 fanCb_ = nullptr; 94 } 95 GetMaxReportTime()96 int32_t GetMaxReportTime() 97 { 98 return maxReportTime_; 99 } 100 GetMaxCd()101 int32_t GetMaxCd() 102 { 103 return maxCd_; 104 } 105 106 void Init(); 107 int32_t ParseThermalZoneInfo(); 108 void CalculateMaxCd(); 109 void ReportThermalZoneData(int32_t reportTime); 110 HdfThermalCallbackInfo GetCallbackInfo(); 111 void DumpPollingInfo(); 112 113 private: 114 int32_t InitThermalZoneSysfs(); 115 void CallbackOnEvent(std::string name, HdfThermalCallbackInfo &info); 116 void CollectCallbackInfo( 117 HdfThermalCallbackInfo &callbackInfo, const std::shared_ptr<SensorInfoConfig> &sensorInfo, int32_t reportTime); 118 int32_t UpdateThermalZoneData(std::map<std::string, std::string> &tzPathMap); 119 void UpdateDataType(XMLThermalZoneInfo& tzIter, ReportedThermalData& data); 120 int32_t GetMaxCommonDivisor(int32_t a, int32_t b); 121 int32_t GetIntervalCommonDivisor(std::vector<int32_t> intervalList); 122 void FormatThermalSysfsPaths(struct ThermalSysfsPathInfo *pTSysPathInfo); 123 void FormatThermalPaths(char *path, size_t size, const char *format, const char* name); 124 struct ThermalZoneSysfsPathInfo tzSysPathInfo_; 125 std::list<ThermalZoneSysfsPathInfo> lTzSysPathInfo_; 126 std::vector<ThermalZoneInfo> tzInfoList_; 127 ThermalHdfConfig::PollingMap pollingMap_; 128 sptr<IThermalCallback> thermalCb_; 129 sptr<IFanCallback> fanCb_; 130 int32_t maxCd_; 131 int32_t maxReportTime_; 132 std::mutex mutex_; 133 }; 134 } // V1_1 135 } // Thermal 136 } // HDI 137 } // OHOS 138 #endif // THERMAL_ZONE_MANAGER_H 139