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
16 #include "napi/native_api.h"
17 #include "napi/native_node_api.h"
18
19 extern const char _binary_picker_js_start[];
20 extern const char _binary_picker_js_end[];
21 extern const char _binary_picker_abc_start[];
22 extern const char _binary_picker_abc_end[];
23
24 namespace OHOS {
25 namespace FileAccessFwk {
26 /*
27 * Function registering all props and functions of ohos.medialibrary module
28 */
Export(napi_env env,napi_value exports)29 static napi_value Export(napi_env env, napi_value exports)
30 {
31 return exports;
32 }
33
NAPI_file_picker_GetJSCode(const char ** buf,int * bufLen)34 extern "C" __attribute__((visibility("default"))) void NAPI_file_picker_GetJSCode(const char** buf,
35 int* bufLen)
36 {
37 if (buf != nullptr) {
38 *buf = _binary_picker_js_start;
39 }
40
41 if (bufLen != nullptr) {
42 *bufLen = _binary_picker_js_end - _binary_picker_js_start;
43 }
44 }
45
NAPI_file_picker_GetABCCode(const char ** buf,int * bufLen)46 extern "C" __attribute__((visibility("default"))) void NAPI_file_picker_GetABCCode(const char** buf,
47 int* bufLen)
48 {
49 if (buf != nullptr) {
50 *buf = _binary_picker_abc_start;
51 }
52
53 if (bufLen != nullptr) {
54 *bufLen = _binary_picker_abc_end - _binary_picker_abc_start;
55 }
56 }
57
58 /*
59 * module define
60 */
61 static napi_module g_module = {
62 .nm_version = 1,
63 .nm_flags = 0,
64 .nm_filename = nullptr,
65 .nm_register_func = Export,
66 .nm_modname = "file.picker",
67 .nm_priv = reinterpret_cast<void *>(0),
68 .reserved = {0}
69 };
70
71 /*
72 * module register
73 */
RegisterModule(void)74 extern "C" __attribute__((constructor)) void RegisterModule(void)
75 {
76 napi_module_register(&g_module);
77 }
78 } // namespace Media
79 } // namespace OHOS
80