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_TIMER_H 17 #define THERMAL_HDF_TIMER_H 18 19 #include <atomic> 20 #include <map> 21 #include <thread> 22 #include "thermal_dfx.h" 23 #include "thermal_hdf_config.h" 24 #include "thermal_simulation_node.h" 25 #include "thermal_zone_manager.h" 26 #include "v1_0/ithermal_callback.h" 27 28 namespace OHOS { 29 namespace HDI { 30 namespace Thermal { 31 namespace V1_0 { 32 enum EventType { 33 EVENT_UEVENT_FD, 34 EVENT_TIMER_FD, 35 }; 36 class ThermalHdfTimer { 37 public: 38 using Callback = std::function<void(ThermalHdfTimer*, void*)>; 39 40 ThermalHdfTimer(const std::shared_ptr<ThermalSimulationNode> &node, 41 const std::shared_ptr<ThermalZoneManager> &thermalZoneMgr); 42 ~ThermalHdfTimer(); 43 44 int32_t Init(); 45 void ReportThermalData(); 46 void LoopingThreadEntry(); 47 void Run(); 48 void StartThread(); 49 void ResetCount(); 50 void SetSimluationFlag(); 51 int32_t GetSimluationFlag(); 52 void SetSimFlag(int32_t flag); 53 void SetThermalEventCb(const sptr<IThermalCallback> &thermalCb); 54 void DumpSensorConfigInfo(); 55 private: 56 void TimerProviderCallback(); 57 int32_t CreateProviderFd(); 58 59 std::map<int32_t, Callback> callbackHandler_; 60 std::shared_ptr<ThermalSimulationNode> node_; 61 std::shared_ptr<ThermalZoneManager> thermalZoneMgr_; 62 HdfThermalCallbackInfo tzInfoEventV1_; 63 HdfThermalCallbackInfo tzInfoEventV2_; 64 HdfThermalCallbackInfo tzInfoEvent_; 65 sptr<IThermalCallback> thermalCb_; 66 std::unique_ptr<ThermalDfx> thermalDfx_ = nullptr; 67 std::vector<int32_t> multipleList_; 68 int32_t reportTime_; 69 int32_t isSim_; 70 std::atomic_bool isRunning_ {true}; 71 std::unique_ptr<std::thread> callbackThread_ {nullptr}; 72 }; 73 } // V1_0 74 } // Thermal 75 } // HDI 76 } // OHOS 77 #endif // THERMAL_HDF_TIMER_H