1 /* 2 * Copyright (c) 2021-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_SENSOR_PROVIDER_H 17 #define THERMAL_SENSOR_PROVIDER_H 18 19 20 #include <functional> 21 #include <map> 22 #include <list> 23 24 #include "thermal_zone_manager.h" 25 #include "thermal_simulation_node.h" 26 #include "v1_1/thermal_types.h" 27 28 namespace OHOS { 29 namespace PowerMgr { 30 using namespace OHOS::HDI::Thermal::V1_1; 31 using SensorsMap = std::map<std::string, int32_t>; 32 enum EventType { 33 EVENT_UEVENT_FD, 34 EVENT_TIMER_FD, 35 }; 36 37 class ThermalSensorProvider : public ThermalZoneManager { 38 public: 39 using Callback = std::function<void(ThermalSensorProvider*, void*)>; 40 using IntervalMap = std::map<std::string, int32_t>; 41 using NotifyTask = std::function<void(SensorsMap)>; 42 ThermalSensorProvider()43 ThermalSensorProvider() {}; ~ThermalSensorProvider()44 ~ThermalSensorProvider() {}; 45 46 bool InitProvider(); 47 void GetThermalSensorInfo(); 48 void RegisterTask(NotifyTask task); 49 void NotifyPolicy(); 50 void GetTypeInterval(); 51 52 int32_t LoopingThreadEntry(void *arg, int32_t epfd); 53 void Run(void *service, int32_t epfd); 54 void StartThread(void *service); 55 int32_t RegisterCallback(const int fd, const EventType et, int32_t epfd); 56 void SetTimerInterval(int interval, int32_t timerfd); 57 void SetIntervalMap(IntervalMap &intervalMap); 58 private: 59 int32_t InitProviderTimer(); 60 void TimerProviderCallback(void *service); 61 int32_t CreateProviderFd(); 62 63 std::vector<ThermalZoneInfo> tzInfoList_; 64 SensorsMap typeTempMap_; 65 IntervalMap intervalMap_; 66 NotifyTask notify_; 67 uint32_t interval_; 68 /* timer related */ 69 int32_t epFd_ {-1}; 70 int32_t timerFd_ {-1}; 71 int32_t timerInterval_ {-1}; 72 std::map<int32_t, Callback> callbackHandler_; 73 }; 74 } // namespace PowerMgr 75 } // namespace OHOS 76 #endif 77