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