/* * Copyright (c) 2021 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef THERMAL_KERNEL_POLICY_H #define THERMAL_KERNEL_POLICY_H #include #include "thermal_kernel_config_file.h" #include "protector_thermal_zone_info.h" #include "ithermal_action.h" namespace OHOS { namespace PowerMgr { struct ActionItem { std::string name; uint32_t value; }; struct LevelAction { std::string name; uint32_t level; std::vector vAction; }; class ThermalKernelPolicy { public: using ThermalZoneMap = std::map>; using LevelMap = std::map; using TypeLevelsMap = std::map>; ThermalKernelPolicy() {}; ~ThermalKernelPolicy() {}; bool Init(); void SetThermalZoneMap(ThermalZoneMap &tzInfoMap); ThermalZoneMap GetThermalZoneMap(); void SetLevelAction(std::vector &levelAction); std::vector GetLevelAction(); int32_t GetMaxCd(); private: void LevelDecision(); void PolicyDecision(); void ActionDecision(std::vector &vAction); void ActionExecution(); void ActionFallbackDecision(); void SetCallback(); void OnReceivedSensorsInfo(SensorsMap typeTempMap); void Dump(); /* Gets the maximum common divisor of the time interval */ int32_t GetMaxCommonDivisor(int32_t a, int32_t b); int32_t GetIntervalCommonDivisor(std::vector intervalList); void SetMultiples(); void CalculateMaxCd(); TypeLevelsMap typeLevelsMap_; SensorsMap typeTempMap_; ThermalZoneMap tzInfoMap_; LevelMap levelMap_; std::vector levelAction_; std::vector executeActionList_; int32_t maxCd_ {0}; }; } // namespace PowerMgr } // namespace OHOS #endif