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