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 "thermal_types.h" 25 26 namespace OHOS { 27 namespace HDI { 28 namespace Thermal { 29 namespace V1_0 { 30 struct ThermalZoneSysfsPathInfo { 31 char* name; 32 char temperturePath[PATH_MAX]; 33 char typePath[PATH_MAX]; 34 int32_t fd; 35 }; 36 37 struct ThermalSysfsPathInfo { 38 char* name; 39 char thermalZonePath[PATH_MAX]; 40 char coolingDevicePath[PATH_MAX]; 41 int32_t fd; 42 }; 43 44 class ThermalZoneManager { 45 public: 46 ThermalZoneManager() = default; 47 ~ThermalZoneManager() = default; 48 GetTzPathInfo()49 ThermalZoneSysfsPathInfo GetTzPathInfo() 50 { 51 return tzSysPathInfo_; 52 }; 53 SetTzPathInfo(ThermalZoneSysfsPathInfo tzSysPathInfo)54 void SetTzPathInfo(ThermalZoneSysfsPathInfo tzSysPathInfo) 55 { 56 tzSysPathInfo_ = tzSysPathInfo; 57 } 58 GetLTZPathInfo()59 std::list<ThermalZoneSysfsPathInfo> GetLTZPathInfo() 60 { 61 return lTzSysPathInfo_; 62 } 63 GetlTzInfo()64 std::vector<ThermalZoneInfo> GetlTzInfo() 65 { 66 return tzInfoList_; 67 } 68 ConvertInt(const std::string & value)69 int32_t ConvertInt(const std::string &value) 70 { 71 return std::stoi(value.c_str()); 72 } 73 74 int32_t InitThermalZoneSysfs(); 75 int32_t ParseThermalZoneInfo(); 76 void Trim(char* str) const; 77 int32_t ReadThermalSysfsToBuff(const char* path, char* buf, size_t size) const; 78 int32_t ReadSysfsFile(const char* path, char* buf, size_t size) const; 79 void FormatThermalSysfsPaths(struct ThermalSysfsPathInfo *pTSysPathInfo); 80 void FormatThermalPaths(char *path, size_t size, const char *format, const char* name); 81 void ClearThermalZoneInfo(); 82 int32_t GetMaxCommonDivisor(int32_t a, int32_t b); 83 int32_t GetIntervalCommonDivisor(std::vector<int32_t> intervalList); 84 void SetMultiples(); 85 void CalculateMaxCd(); 86 int32_t ReadFile(const char *path, char *buf, size_t size); 87 void ReportThermalZoneData(int32_t reportTime, std::vector<int32_t> &multipleList); 88 HdfThermalCallbackInfo tzInfoAcaualEvent_; 89 int32_t maxCd_; 90 private: 91 int32_t UpdateThermalZoneData(std::map<std::string, std::string> &tzPathMap); 92 ThermalHdfConfig::ThermalTypeMap sensorTypeMap_; 93 struct ThermalZoneSysfsPathInfo tzSysPathInfo_; 94 std::list<ThermalZoneSysfsPathInfo> lTzSysPathInfo_; 95 std::vector<ThermalZoneInfo> tzInfoList_; 96 std::mutex mutex_; 97 bool flag_ {false}; 98 }; 99 } // V1_0 100 } // Thermal 101 } // HDI 102 } // OHOS 103 #endif // THERMAL_ZONE_MANAGER_H