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