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 #include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_module_manager.h"
17
18 #include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_app_module.h"
19 #include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_curves_module.h"
20 #include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_matrix4_module.h"
21 #include "frameworks/bridge/declarative_frontend/engine/jsi/modules/jsi_router_module.h"
22
23 namespace OHOS::Ace::Framework {
24
GetInstance()25 ModuleManager* ModuleManager::GetInstance()
26 {
27 static ModuleManager instance;
28 return &instance;
29 }
30
InitModule(const shared_ptr<JsRuntime> & runtime,shared_ptr<JsValue> & thisObj,const std::string & moduleName)31 bool ModuleManager::InitModule(
32 const shared_ptr<JsRuntime>& runtime, shared_ptr<JsValue>& thisObj, const std::string& moduleName)
33 {
34 static const std::unordered_map<std::string,
35 void (*)(const shared_ptr<JsRuntime>& runtime, shared_ptr<JsValue>& thisObj)>
36 MODULE_LIST = {
37 { "system.router", [](const shared_ptr<JsRuntime>& runtime,
38 shared_ptr<JsValue>& thisObj) { InitRouterModule(runtime, thisObj); } },
39 { "ohos.router", [](const shared_ptr<JsRuntime>& runtime,
40 shared_ptr<JsValue>& thisObj) { InitRouterModule(runtime, thisObj); } },
41 { "system.app", [](const shared_ptr<JsRuntime>& runtime,
42 shared_ptr<JsValue>& thisObj) { InitAppModule(runtime, thisObj); } },
43 { "ohos.app", [](const shared_ptr<JsRuntime>& runtime,
44 shared_ptr<JsValue>& thisObj) { InitAppModule(runtime, thisObj); } },
45 { "system.curves", [](const shared_ptr<JsRuntime>& runtime,
46 shared_ptr<JsValue>& thisObj) { InitCurvesModule(runtime, thisObj); } },
47 { "ohos.curves", [](const shared_ptr<JsRuntime>& runtime,
48 shared_ptr<JsValue>& thisObj) { InitCurvesModule(runtime, thisObj); } },
49 { "system.matrix4", [](const shared_ptr<JsRuntime>& runtime,
50 shared_ptr<JsValue>& thisObj) { InitMatrix4Module(runtime, thisObj); } },
51 { "ohos.matrix4", [](const shared_ptr<JsRuntime>& runtime,
52 shared_ptr<JsValue>& thisObj) { InitMatrix4Module(runtime, thisObj); } },
53 };
54 auto iter = MODULE_LIST.find(moduleName);
55 if (iter != MODULE_LIST.end()) {
56 iter->second(runtime, thisObj);
57 return true;
58 } else {
59 return false;
60 }
61 }
62
63 } // namespace OHOS::Ace::Framework