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 "thermal_srv_sensor_info.h" 24 #include "thermal_config_sensor_cluster.h" 25 26 namespace OHOS { 27 namespace PowerMgr { 28 struct PolicyAction { 29 std::string actionName; 30 std::string actionValue; 31 std::map<std::string, std::string> actionPropMap; 32 bool isProp; 33 }; 34 35 struct PolicyConfig { 36 uint32_t level; 37 std::vector<PolicyAction> policyActionList; 38 }; 39 40 class ThermalPolicy { 41 public: 42 using PolicyConfigMap = std::map<std::string, std::vector<PolicyConfig>>; 43 ThermalPolicy() = default; 44 ~ThermalPolicy() = default; 45 46 bool Init(); 47 void OnSensorInfoReported(const TypeTempMap& info); 48 void ExecutePolicy(); 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