1 /*
2 * Copyright (C) 2021-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_module_ohos_medialibrary.h"
17 extern const char _binary_medialibraryinf_js_start[];
18 extern const char _binary_medialibraryinf_js_end[];
19 extern const char _binary_medialibraryinf_abc_start[];
20 extern const char _binary_medialibraryinf_abc_end[];
21
22 namespace OHOS {
23 namespace Media {
24 /*
25 * Function registering all props and functions of ohos.medialibrary module
26 */
Export(napi_env env,napi_value exports)27 static napi_value Export(napi_env env, napi_value exports)
28 {
29 FileAssetNapi::Init(env, exports);
30 FetchFileResultNapi::Init(env, exports);
31 AlbumNapi::Init(env, exports);
32 SmartAlbumNapi::Init(env, exports);
33 MediaLibraryNapi::Init(env, exports);
34 MediaScannerNapi::Init(env, exports);
35 return exports;
36 }
37
NAPI_multimedia_mediaLibrary_GetJSCode(const char ** buf,int * bufLen)38 extern "C" __attribute__((visibility("default"))) void NAPI_multimedia_mediaLibrary_GetJSCode(const char** buf,
39 int* bufLen)
40 {
41 if (buf != nullptr) {
42 *buf = _binary_medialibraryinf_js_start;
43 }
44
45 if (bufLen != nullptr) {
46 *bufLen = _binary_medialibraryinf_js_end - _binary_medialibraryinf_js_start;
47 }
48 }
49
NAPI_multimedia_mediaLibrary_GetABCCode(const char ** buf,int * bufLen)50 extern "C" __attribute__((visibility("default"))) void NAPI_multimedia_mediaLibrary_GetABCCode(const char** buf,
51 int* bufLen)
52 {
53 if (buf != nullptr) {
54 *buf = _binary_medialibraryinf_abc_start;
55 }
56
57 if (bufLen != nullptr) {
58 *bufLen = _binary_medialibraryinf_abc_end - _binary_medialibraryinf_abc_start;
59 }
60 }
61
62 /*
63 * module define
64 */
65 static napi_module g_module = {
66 .nm_version = 1,
67 .nm_flags = 0,
68 .nm_filename = nullptr,
69 .nm_register_func = Export,
70 .nm_modname = "multimedia.mediaLibrary",
71 .nm_priv = reinterpret_cast<void *>(0),
72 .reserved = {0}
73 };
74
75 /*
76 * module register
77 */
RegisterModule(void)78 extern "C" __attribute__((constructor)) void RegisterModule(void)
79 {
80 napi_module_register(&g_module);
81 }
82 } // namespace Media
83 } // namespace OHOS
84