• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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_js_start[];
19 extern const char _binary_ability_js_end[];
20 extern const char _binary_ability_abc_start[];
21 extern const char _binary_ability_abc_end[];
22 
23 #ifdef ENABLE_ERRCODE
24 extern "C" __attribute__((constructor))
NAPI_app_ability_UIAbility_AutoRegister()25 void NAPI_app_ability_UIAbility_AutoRegister()
26 {
27     auto moduleManager = NativeModuleManager::GetInstance();
28     NativeModule newModuleInfo = {
29         .name = "app.ability.UIAbility",
30         .fileName = "app/ability/libability.so/ability.js",
31     };
32 
33     moduleManager->Register(&newModuleInfo);
34 }
35 
36 extern "C" __attribute__((visibility("default")))
NAPI_app_ability_UIAbility_GetJSCode(const char ** buf,int * bufLen)37 void NAPI_app_ability_UIAbility_GetJSCode(const char **buf, int *bufLen)
38 {
39     if (buf != nullptr) {
40         *buf = _binary_ability_js_start;
41     }
42 
43     if (bufLen != nullptr) {
44         *bufLen = _binary_ability_js_end - _binary_ability_js_start;
45     }
46 }
47 
48 // ability JS register
49 extern "C" __attribute__((visibility("default")))
NAPI_app_ability_UIAbility_GetABCCode(const char ** buf,int * buflen)50 void NAPI_app_ability_UIAbility_GetABCCode(const char **buf, int *buflen)
51 {
52     if (buf != nullptr) {
53         *buf = _binary_ability_abc_start;
54     }
55     if (buflen != nullptr) {
56         *buflen = _binary_ability_abc_end - _binary_ability_abc_start;
57     }
58 }
59 #else
60 extern "C" __attribute__((constructor))
NAPI_application_Ability_AutoRegister()61 void NAPI_application_Ability_AutoRegister()
62 {
63     auto moduleManager = NativeModuleManager::GetInstance();
64     NativeModule newModuleInfo = {
65         .name = "application.Ability",
66         .fileName = "application/libability_napi.so/ability.js",
67     };
68 
69     moduleManager->Register(&newModuleInfo);
70 }
71 
72 extern "C" __attribute__((visibility("default")))
NAPI_application_Ability_GetJSCode(const char ** buf,int * bufLen)73 void NAPI_application_Ability_GetJSCode(const char **buf, int *bufLen)
74 {
75     if (buf != nullptr) {
76         *buf = _binary_ability_js_start;
77     }
78 
79     if (bufLen != nullptr) {
80         *bufLen = _binary_ability_js_end - _binary_ability_js_start;
81     }
82 }
83 
84 // ability JS register
85 extern "C" __attribute__((visibility("default")))
NAPI_application_Ability_GetABCCode(const char ** buf,int * buflen)86 void NAPI_application_Ability_GetABCCode(const char **buf, int *buflen)
87 {
88     if (buf != nullptr) {
89         *buf = _binary_ability_abc_start;
90     }
91     if (buflen != nullptr) {
92         *buflen = _binary_ability_abc_end - _binary_ability_abc_start;
93     }
94 }
95 #endif
96