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 GetThermalEventCb()81 const sptr<IThermalCallback>& GetThermalEventCb() 82 { 83 return thermalCb_; 84 } 85 DelThermalEventCb()86 void DelThermalEventCb() 87 { 88 thermalCb_ = nullptr; 89 } 90 SetFanEventCb(const sptr<IFanCallback> & fanCb)91 void SetFanEventCb(const sptr<IFanCallback> &fanCb) 92 { 93 fanCb_ = fanCb; 94 } 95 GetFanEventCb()96 const sptr<IFanCallback>& GetFanEventCb() 97 { 98 return fanCb_; 99 } 100 DelFanEventCb()101 void DelFanEventCb() 102 { 103 fanCb_ = nullptr; 104 } 105 GetMaxReportTime()106 int32_t GetMaxReportTime() 107 { 108 return maxReportTime_; 109 } 110 GetMaxCd()111 int32_t GetMaxCd() 112 { 113 return maxCd_; 114 } 115 116 void Init(); 117 int32_t UpdateThermalZoneData(); 118 void CalculateMaxCd(); 119 void ReportThermalZoneData(int32_t reportTime); 120 HdfThermalCallbackInfo GetCallbackInfo(); 121 void DumpPollingInfo(); 122 123 private: 124 void InitThermalZoneSysfs(); 125 void CallbackOnEvent(std::string name, HdfThermalCallbackInfo &info); 126 void CollectCallbackInfo( 127 HdfThermalCallbackInfo &callbackInfo, const std::shared_ptr<SensorInfoConfig> &sensorInfo, int32_t reportTime); 128 void UpdateDataType(XMLThermalZoneInfo& tzIter, ReportedThermalData& data, int32_t tzn); 129 void UpdateThermalZoneInfo(std::shared_ptr<SensorInfoConfig> &infoConfig); 130 int32_t GetIntervalCommonDivisor(std::vector<int32_t> intervalList); 131 struct ThermalZoneSysfsPathInfo tzSysPathInfo_; 132 std::list<ThermalZoneSysfsPathInfo> lTzSysPathInfo_; 133 std::vector<ThermalZoneInfo> tzInfoList_; 134 ThermalHdfConfig::PollingMap pollingMap_; 135 sptr<IThermalCallback> thermalCb_; 136 sptr<IFanCallback> fanCb_; 137 int32_t maxCd_; 138 int32_t maxReportTime_; 139 std::map<std::string, int32_t> tznMap_; 140 std::mutex mutex_; 141 }; 142 } // V1_1 143 } // Thermal 144 } // HDI 145 } // OHOS 146 #endif // THERMAL_ZONE_MANAGER_H 147