• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #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 "napi_form_provider.h"
21 
22 EXTERN_C_START
23 using namespace OHOS::AbilityRuntime;
24 
JsProviderInit(napi_env env,napi_value value)25 static napi_value JsProviderInit(napi_env env, napi_value value)
26 {
27     HILOG_INFO("call");
28 
29     std::unique_ptr<JsFormProvider> jsFormPorivder = std::make_unique<JsFormProvider>();
30     napi_wrap(env, value, jsFormPorivder.release(), JsFormProvider::Finalizer, nullptr, nullptr);
31 
32     const char *moduleName = "JsFormProvider";
33     BindNativeFunction(env, value, "getFormsInfo", moduleName, JsFormProvider::GetFormsInfo);
34     BindNativeFunction(env, value, "setFormNextRefreshTime", moduleName, JsFormProvider::SetFormNextRefreshTime);
35     BindNativeFunction(env, value, "updateForm", moduleName, JsFormProvider::UpdateForm);
36     BindNativeFunction(env, value, "isRequestPublishFormSupported", moduleName,
37         JsFormProvider::IsRequestPublishFormSupported);
38     return value;
39 }
40 
41 /**
42  * @brief  For N-API modules registration
43  *
44  * @param[in] env The environment that the Node-API call is invoked under
45  * @param[in] exports  An empty object via the exports parameter as a convenience
46  *
47  * @return The return value from Init is treated as the exports object for the module
48  */
Init(napi_env env,napi_value exports)49 static napi_value Init(napi_env env, napi_value exports)
50 {
51     HILOG_INFO("Init start");
52     napi_property_descriptor properties[] = {
53         DECLARE_NAPI_FUNCTION("requestPublishForm", NAPI_RequestPublishForm),
54     };
55     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(properties) / sizeof(properties[0]), properties));
56     HILOG_INFO("Init end");
57     return JsProviderInit(env, exports);
58 }
59 
60 EXTERN_C_END
61 
62 // Define a Node-API module.
63 static napi_module _module = {
64     .nm_version = 1,
65     .nm_flags = 0,
66     .nm_filename = nullptr,
67     .nm_register_func = Init,
68     .nm_modname = "application.formProvider",
69     .nm_priv = nullptr,
70     .reserved = {nullptr}
71 };
72 
73 // Registers a Node-API module.
RegisterModule(void)74 extern "C" __attribute__((constructor)) void RegisterModule(void)
75 {
76     napi_module_register(&_module);
77 }