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 "native_engine/native_engine.h"
17
18 extern const char _binary_ability_stage_js_start[];
19 extern const char _binary_ability_stage_js_end[];
20 extern const char _binary_ability_stage_abc_start[];
21 extern const char _binary_ability_stage_abc_end[];
22
23 static napi_module _module = {
24 #ifdef ENABLE_ERRCODE
25 .nm_version = 0,
26 .nm_filename = "app/ability/libabilitystage.so/ability_stage.js",
27 .nm_modname = "app.ability.AbilityStage",
28 #else
29 .nm_version = 0,
30 .nm_filename = "application/libabilitystage_napi.so/ability_stage.js",
31 .nm_modname = "application.AbilityStage",
32 #endif
33 };
34 extern "C" __attribute__((constructor))
35 #ifdef ENABLE_ERRCODE
NAPI_app_ability_AbilityStage_AutoRegister()36 void NAPI_app_ability_AbilityStage_AutoRegister()
37 #else
38 void NAPI_application_AbilityStage_AutoRegister()
39 #endif
40 {
41 napi_module_register(&_module);
42 }
43
44 extern "C" __attribute__((visibility("default")))
45 #ifdef ENABLE_ERRCODE
NAPI_app_ability_AbilityStage_GetJSCode(const char ** buf,int * bufLen)46 void NAPI_app_ability_AbilityStage_GetJSCode(const char **buf, int *bufLen)
47 #else
48 void NAPI_application_AbilityStage_GetJSCode(const char **buf, int *bufLen)
49 #endif
50 {
51 if (buf != nullptr) {
52 *buf = _binary_ability_stage_js_start;
53 }
54
55 if (bufLen != nullptr) {
56 *bufLen = _binary_ability_stage_js_end - _binary_ability_stage_js_start;
57 }
58 }
59
60 // ability_stage JS register
61 extern "C" __attribute__((visibility("default")))
62 #ifdef ENABLE_ERRCODE
NAPI_app_ability_AbilityStage_GetABCCode(const char ** buf,int * buflen)63 void NAPI_app_ability_AbilityStage_GetABCCode(const char **buf, int *buflen)
64 #else
65 void NAPI_application_AbilityStage_GetABCCode(const char **buf, int *buflen)
66 #endif
67 {
68 if (buf != nullptr) {
69 *buf = _binary_ability_stage_abc_start;
70 }
71 if (buflen != nullptr) {
72 *buflen = _binary_ability_stage_abc_end - _binary_ability_stage_abc_start;
73 }
74 }
75