1 /*
2 * Copyright (c) 2022-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 #include "napi/native_api.h"
16
17 #include "fms_log_wrapper.h"
18 #include "js_runtime_utils.h"
19 #include "napi/native_node_api.h"
20 #include "js_form_provider.h"
21
22 EXTERN_C_START
23 using namespace OHOS::AbilityRuntime;
24
JsProviderInit(napi_env env,napi_value exports)25 static napi_value JsProviderInit(napi_env env, napi_value exports)
26 {
27 HILOG_DEBUG("call");
28
29 std::unique_ptr<JsFormProvider> jsFormProvider = std::make_unique<JsFormProvider>();
30 napi_wrap(env, exports, jsFormProvider.release(), JsFormProvider::Finalizer, nullptr, nullptr);
31
32 const char *moduleName = "JsFormProvider";
33 BindNativeFunction(env, exports, "getFormsInfo", moduleName, JsFormProvider::GetFormsInfo);
34 BindNativeFunction(env, exports, "getPublishedFormInfos", moduleName, JsFormProvider::GetPublishedFormInfos);
35 BindNativeFunction(env, exports, "getPublishedFormInfoById", moduleName, JsFormProvider::GetPublishedFormInfoById);
36 BindNativeFunction(env, exports, "openFormManager", moduleName, JsFormProvider::OpenFormManager);
37 BindNativeFunction(env, exports, "openFormManagerCrossBundle", moduleName,
38 JsFormProvider::OpenFormManagerCrossBundle);
39 BindNativeFunction(env, exports, "setFormNextRefreshTime", moduleName, JsFormProvider::SetFormNextRefreshTime);
40 BindNativeFunction(env, exports, "updateForm", moduleName, JsFormProvider::UpdateForm);
41 BindNativeFunction(env, exports, "requestPublishForm", moduleName, JsFormProvider::RequestPublishForm);
42 BindNativeFunction(env, exports, "isRequestPublishFormSupported", moduleName,
43 JsFormProvider::IsRequestPublishFormSupported);
44 BindNativeFunction(env, exports, "openFormEditAbility", moduleName, JsFormProvider::OpenFormEditAbility);
45 BindNativeFunction(env, exports, "requestOverflow", moduleName, JsFormProvider::RequestOverflow);
46 BindNativeFunction(env, exports, "cancelOverflow", moduleName, JsFormProvider::CancelOverflow);
47 BindNativeFunction(env, exports, "activateSceneAnimation", moduleName, JsFormProvider::ActivateSceneAnimation);
48 BindNativeFunction(env, exports, "deactivateSceneAnimation", moduleName, JsFormProvider::DeactivateSceneAnimation);
49 BindNativeFunction(env, exports, "getFormRect", moduleName, JsFormProvider::GetFormRect);
50 BindNativeFunction(env, exports, "getPublishedRunningFormInfos", moduleName,
51 JsFormProvider::GetPublishedRunningFormInfos);
52 BindNativeFunction(env, exports, "getPublishedRunningFormInfoById", moduleName,
53 JsFormProvider::GetPublishedRunningFormInfoById);
54 return exports;
55 }
56
57 /**
58 * @brief For N-API modules registration
59 *
60 * @param[in] env The environment that the Node-API call is invoked under
61 * @param[in] exports An empty object via the exports parameter as a convenience
62 *
63 * @return The return value from Init is treated as the exports object for the module
64 */
Init(napi_env env,napi_value exports)65 static napi_value Init(napi_env env, napi_value exports)
66 {
67 return JsProviderInit(env, exports);
68 }
69
70 EXTERN_C_END
71
72 // Define a Node-API module.
73 static napi_module _module = {
74 .nm_version = 1,
75 .nm_flags = 0,
76 .nm_filename = nullptr,
77 .nm_register_func = Init,
78 .nm_modname = "app.form.formProvider",
79 .nm_priv = nullptr,
80 .reserved = { nullptr }
81 };
82
83 // Registers a Node-API module.
RegisterModule(void)84 extern "C" __attribute__((constructor)) void RegisterModule(void)
85 {
86 napi_module_register(&_module);
87 }