• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2023 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 #include "thermal_action_factory.h"
17 
18 #include "action_airplane.h"
19 #include "action_application_process.h"
20 #include "action_charger.h"
21 #include "action_cpu_big.h"
22 #include "action_cpu_boost.h"
23 #include "action_cpu_isolate.h"
24 #include "action_cpu_lit.h"
25 #include "action_cpu_med.h"
26 #include "action_cpu_nonvip.h"
27 #include "action_display.h"
28 #include "action_gpu.h"
29 #include "action_node.h"
30 #include "action_popup.h"
31 #include "action_shutdown.h"
32 #include "action_socperf.h"
33 #include "action_socperf_resource.h"
34 #include "action_thermal_level.h"
35 #include "action_voltage.h"
36 #include "action_volume.h"
37 #include "constants.h"
38 #include "string_operation.h"
39 #include "thermal_common.h"
40 
41 namespace OHOS {
42 namespace PowerMgr {
43 namespace {
44 std::map<std::string, ActionFunc> g_actionMap;
45 }
InitFactory()46 void ThermalActionFactory::InitFactory()
47 {
48     g_actionMap = {
49         std::make_pair(AIRPLANE_ACTION_NAME,
50             [&](std::string actionName) { return std::make_shared<ActionAirplane>(actionName); }),
51         std::make_pair(CPU_BIG_ACTION_NAME,
52             [&](std::string actionName) { return std::make_shared<ActionCpuBig>(actionName); }),
53         std::make_pair(CPU_MED_ACTION_NAME,
54             [&](std::string actionName) { return std::make_shared<ActionCpuMed>(actionName); }),
55         std::make_pair(CPU_LIT_ACTION_NAME,
56             [&](std::string actionName) { return std::make_shared<ActionCpuLit>(actionName); }),
57         std::make_pair(GPU_ACTION_NAME,
58             [&](std::string actionName) { return std::make_shared<ActionGpu>(actionName); }),
59         std::make_pair(LCD_ACTION_NAME,
60             [&](std::string actionName) { return std::make_shared<ActionDisplay>(actionName); }),
61         std::make_pair(VOLUME_ACTION_NAME,
62             [&](std::string actionName) { return std::make_shared<ActionVolume>(actionName); }),
63         std::make_pair(SHUTDOWN_ACTION_NAME,
64             [&](std::string actionName) { return std::make_shared<ActionShutdown>(actionName); }),
65         std::make_pair(THERMAL_LEVEL_NAME,
66             [&](std::string actionName) { return std::make_shared<ActionThermalLevel>(actionName); }),
67         std::make_pair(POPUP_ACTION_NAME,
68             [&](std::string actionName) { return std::make_shared<ActionPopup>(actionName); }),
69         std::make_pair(CURRENT_ACTION_NAME,
70             [&](std::string actionName) { return std::make_shared<ActionCharger>(actionName); }),
71         std::make_pair(VOLATAGE_ACTION_NAME,
72             [&](std::string actionName) { return std::make_shared<ActionVoltage>(actionName); }),
73         std::make_pair(CPU_BOOST_ACTION_NAME,
74             [&](std::string actionName) { return std::make_shared<ActionCpuBoost>(actionName); }),
75         std::make_pair(CPU_ISOLATE_ACTION_NAME,
76             [&](std::string actionName) { return std::make_shared<ActionCpuIsolate>(actionName); }),
77         std::make_pair(CPU_NONVIP_ACTION_NAME,
78             [&](std::string actionName) { return std::make_shared<ActionCpuNonVip>(actionName); }),
79         std::make_pair(PROCESS_ACTION_NAME,
80             [&](std::string actionName) { return std::make_shared<ActionApplicationProcess>(actionName); }),
81         std::make_pair(SOCPERF_ACTION_NAME,
82             [&](std::string actionName) { return std::make_shared<ActionSocPerf>(actionName); }),
83         std::make_pair(SOCPERF_RESOURCE_ACTION_NAME,
84             [&](std::string actionName) { return std::make_shared<ActionSocPerfResource>(actionName); }),
85         std::make_pair(NODE_ACTION_NAME,
86             [&](std::string actionName) { return std::make_shared<ActionNode>(actionName); }),
87     };
88 }
89 
Create(const std::string & actionClass,const std::string & actionName)90 std::shared_ptr<IThermalAction> ThermalActionFactory::Create(const std::string& actionClass,
91     const std::string& actionName)
92 {
93     for (auto iter = g_actionMap.begin(); iter != g_actionMap.end(); ++iter) {
94         if (StringOperation::Compare(actionClass, iter->first)) {
95             return iter->second(actionName);
96         }
97     }
98 
99     THERMAL_HILOGD(COMP_SVC, "create factory failed");
100     return nullptr;
101 }
102 } // namespace PowerMgr
103 } // namespace OHOS
104