• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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_med.h"
22 #include "action_cpu_lit.h"
23 #include "action_gpu.h"
24 #include "action_display.h"
25 #include "action_volume.h"
26 #include "action_shutdown.h"
27 #include "action_thermal_level.h"
28 #include "action_popup.h"
29 #include "action_voltage.h"
30 #include "string_operation.h"
31 #include "constants.h"
32 #include "thermal_common.h"
33 
34 namespace OHOS {
35 namespace PowerMgr {
36 namespace {
37 std::map<std::string, std::shared_ptr<IThermalAction>> g_actionMap;
38 }
InitFactory()39 void ThermalActionFactory::InitFactory()
40 {
41     g_actionMap.clear();
42     g_actionMap.insert(std::make_pair(CPU_BIG_ACTION_NAME, std::make_shared<ActionCpuBig>(CPU_BIG_ACTION_NAME)));
43     g_actionMap.insert(std::make_pair(CPU_MED_ACTION_NAME, std::make_shared<ActionCpuMed>(CPU_MED_ACTION_NAME)));
44     g_actionMap.insert(std::make_pair(CPU_LIT_ACTION_NAME, std::make_shared<ActionCpuLit>(CPU_LIT_ACTION_NAME)));
45     g_actionMap.insert(std::make_pair(GPU_ACTION_NAME, std::make_shared<ActionGpu>(GPU_ACTION_NAME)));
46     g_actionMap.insert(std::make_pair(LCD_ACTION_NAME, std::make_shared<ActionDisplay>(LCD_ACTION_NAME)));
47     g_actionMap.insert(std::make_pair(VOLUME_ACTION_NAME, std::make_shared<ActionVolume>(VOLUME_ACTION_NAME)));
48     g_actionMap.insert(std::make_pair(SHUTDOWN_ACTION_NAME, std::make_shared<ActionShutdown>(SHUTDOWN_ACTION_NAME)));
49     g_actionMap.insert(
50         std::make_pair(PROCESS_ACTION_NAME, std::make_shared<ActionApplicationProcess>(PROCESS_ACTION_NAME)));
51     g_actionMap.insert(std::make_pair(THERMAL_LEVEL_NAME, std::make_shared<ActionThermalLevel>(THERMAL_LEVEL_NAME)));
52     g_actionMap.insert(std::make_pair(POPUP_ACTION_NAME, std::make_shared<ActionPopup>(POPUP_ACTION_NAME)));
53     g_actionMap.insert(std::make_pair(CURRENT_SC_ACTION_NAME, std::make_shared<ActionCharger>(CURRENT_SC_ACTION_NAME)));
54     g_actionMap.insert(
55         std::make_pair(CURRENT_BUCK_ACTION_NAME, std::make_shared<ActionCharger>(CURRENT_BUCK_ACTION_NAME)));
56     g_actionMap.insert(
57         std::make_pair(VOLATAGE_SC_ACTION_NAME, std::make_shared<ActionVoltage>(VOLATAGE_SC_ACTION_NAME)));
58     g_actionMap.insert(
59         std::make_pair(VOLATAGE_BUCK_ACTION_NAME, std::make_shared<ActionVoltage>(VOLATAGE_BUCK_ACTION_NAME)));
60 }
61 
Create(const std::string & actionName)62 std::shared_ptr<IThermalAction> ThermalActionFactory::Create(const std::string& actionName)
63 {
64     THERMAL_HILOGD(COMP_SVC, "Enter");
65     for (auto iter = g_actionMap.begin(); iter != g_actionMap.end(); ++iter) {
66         if (StringOperation::Compare(actionName, iter->first)) {
67             return iter->second;
68         }
69     }
70 
71     THERMAL_HILOGD(COMP_SVC, "create factory failed");
72     return nullptr;
73 }
74 } // namespace PowerMgr
75 } // namespace OHOS
76