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_PROTECTOR_TIMER_H 17 #define THERMAL_PROTECTOR_TIMER_H 18 19 #include <map> 20 #include <vector> 21 #include "thermal_sensor_provision.h" 22 23 namespace OHOS { 24 namespace PowerMgr { 25 enum EventType { 26 EVENT_UEVENT_FD, 27 EVENT_TIMER_FD, 28 }; 29 class ThermalProtectorTimer { 30 public: 31 using Callback = std::function<void(ThermalProtectorTimer*, void*)>; 32 using NotifyTask = std::function<void(SensorsMap)>; 33 34 ThermalProtectorTimer(const std::shared_ptr<ThermalSensorProvision>& provision); ~ThermalProtectorTimer()35 ~ThermalProtectorTimer() {} 36 void RegisterTask(NotifyTask task); 37 int32_t Init(); 38 void ReportThermalData(); 39 int32_t LoopingThreadEntry(void *arg, int32_t epfd); 40 void Run(void *service, int32_t epfd); 41 void StartThread(void *service); 42 int32_t RegisterCallback(const int32_t fd, const EventType et, int32_t epfd); 43 void SetTimerInterval(int32_t interval, int32_t timerfd); 44 void ResetCount(); 45 private: 46 void NotifyPolicy(); 47 int32_t InitProvisionTimer(); 48 void TimerProvisionCallback(void *service); 49 int32_t CreateProvisionFd(); 50 int32_t timeCount_ {0}; 51 int32_t epFd_ {-1}; 52 int32_t timerFd_ {-1}; 53 int32_t timerInterval_ {-1}; 54 std::map<int32_t, Callback> callbackHandler_; 55 std::vector<int32_t> multipleList_; 56 int32_t reportTime_ {0}; 57 NotifyTask notify_; 58 SensorsMap sensorMap_; 59 std::shared_ptr<ThermalSensorProvision> provision_; 60 }; 61 } // PowerMgr 62 } // OHOS 63 #endif // THERMAL_HDF_TIMER_H