• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 "js_form_agent.h"
20 #include "napi/native_node_api.h"
21 
22 EXTERN_C_START
23 using namespace OHOS::AbilityRuntime;
24 
JsFormAgentInit(napi_env env,napi_value exports)25 static napi_value JsFormAgentInit(napi_env env, napi_value exports)
26 {
27     HILOG_INFO("call");
28 
29     std::unique_ptr<JsFormAgent> jsFormAgent = std::make_unique<JsFormAgent>();
30     napi_wrap(env, exports, jsFormAgent.release(), JsFormAgent::Finalizer, nullptr, nullptr);
31 
32     const char *moduleName = "JsFormAgent";
33     BindNativeFunction(env, exports, "requestPublishForm", moduleName, JsFormAgent::RequestPublishForm);
34     return exports;
35 }
36 
37 /**
38  * @brief  For N-API modules registration
39  *
40  * @param[in] env The environment that the Node-API call is invoked under
41  * @param[in] exports  An empty object via the exports parameter as a convenience
42  *
43  * @return The return value from Init is treated as the exports object for the module
44  */
Init(napi_env env,napi_value exports)45 static napi_value Init(napi_env env, napi_value exports)
46 {
47     return JsFormAgentInit(env, exports);
48 }
49 
50 EXTERN_C_END
51 
52 // Define a Node-API module.
53 static napi_module _module = {
54     .nm_version = 1,
55     .nm_flags = 0,
56     .nm_filename = nullptr,
57     .nm_register_func = Init,
58     .nm_modname = "app.form.formAgent",
59     .nm_priv = nullptr,
60     .reserved = { nullptr }
61 };
62 
63 // Registers a Node-API module.
RegisterModule(void)64 extern "C" __attribute__((constructor)) void RegisterModule(void)
65 {
66     napi_module_register(&_module);
67 }