1 /* 2 * Copyright (c) 2021 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_POLICY_H 17 #define THERMAL_POLICY_H 18 19 #include <map> 20 #include <string> 21 #include <vector> 22 23 #include "delayed_sp_singleton.h" 24 #include "thermal_srv_sensor_info.h" 25 #include "thermal_config_sensor_cluster.h" 26 27 namespace OHOS { 28 namespace PowerMgr { 29 struct PolicyAction { 30 std::string actionName; 31 std::string actionValue; 32 std::map<std::string, std::string> actionPropMap; 33 bool isProp; 34 }; 35 36 struct PolicyConfig { 37 uint32_t level; 38 std::vector<PolicyAction> policyActionList; 39 }; 40 41 class ThermalPolicy { 42 public: 43 using PolicyConfigMap = std::map<std::string, std::vector<PolicyConfig>>; 44 ThermalPolicy() = default; 45 ~ThermalPolicy() = default; 46 47 bool Init(); 48 void OnSensorInfoReported(const TypeTempMap& info); 49 void SetPolicyMap(PolicyConfigMap& pcm); 50 void SetSensorClusterMap(SensorClusterMap& scm); 51 void FindSubscribeActionValue(); 52 /* Test */ 53 std::map<std::string, uint32_t> GetClusterLevelMap(); 54 void DumpLevel(std::string& result); 55 void DumpPolicy(std::string& result); 56 57 private: 58 void SortLevel(); 59 void RegisterObserver(); 60 void WriteLevel(); 61 void LevelDecision(); 62 void PolicyDecision(); 63 void ActionDecision(const std::vector<PolicyAction>& actionList); 64 bool StateMachineDecision(const std::map<std::string, std::string>& stateMap); 65 bool ActionExecution(); 66 void PrintPolicyState(); 67 void PrintPolicyAction(std::vector<PolicyAction> policyActionList, std::string& result); 68 LevelCompare(const PolicyConfig & r,const PolicyConfig & l)69 static bool LevelCompare(const PolicyConfig& r, const PolicyConfig& l) 70 { 71 return r.level < l.level; 72 } 73 74 TypeTempMap typeTempMap_; 75 SensorClusterMap sensorClusterMap_; 76 std::map<std::string, uint32_t> clusterLevelMap_; 77 PolicyConfigMap clusterPolicyMap_; 78 }; 79 } // namespace PowerMgr 80 } // namespace OHOS 81 #endif // THERMAL_POLICY_H 82