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_module_ohos_image.h"
17 
18 #include "image_log.h"
19 
20 #undef LOG_DOMAIN
21 #define LOG_DOMAIN LOG_TAG_DOMAIN_ID_IMAGE
22 
23 #undef LOG_TAG
24 #define LOG_TAG "NAPITEST"
25 
26 namespace OHOS {
27 namespace Media {
28 /*
29  * Function registering all props and functions of ohos.medialibrary module
30  */
Export(napi_env env,napi_value exports)31 static napi_value Export(napi_env env, napi_value exports)
32 {
33     IMAGE_LOGD("ImagePackerNapi CALL");
34     ImagePackerNapi::Init(env, exports);
35     IMAGE_LOGD("PixelMapNapi CALL");
36     PixelMapNapi::Init(env, exports);
37     IMAGE_LOGD("ImageSourceNapi CALL");
38     ImageSourceNapi::Init(env, exports);
39 #if !defined(IOS_PLATFORM) && !defined(ANDROID_PLATFORM)
40     IMAGE_LOGD("PictureNapi CALL");
41     PictureNapi::Init(env, exports);
42     IMAGE_LOGD("AuxiliaryPictureNapi CALL");
43     AuxiliaryPictureNapi::Init(env, exports);
44     IMAGE_LOGD("MetadataNapi CALL");
45     MetadataNapi::Init(env, exports);
46     IMAGE_LOGD("ImageReceiverNapi CALL");
47     ImageReceiverNapi::Init(env, exports);
48     IMAGE_LOGD("ImageCreatorNapi CALL");
49     ImageCreatorNapi::Init(env, exports);
50     IMAGE_LOGD("ImageNapi CALL");
51     ImageNapi::Init(env, exports);
52 #endif
53     return exports;
54 }
55 
56 /*
57  * module define
58  */
59 static napi_module g_module = {
60     .nm_version = 1,
61     .nm_flags = 0,
62     .nm_filename = nullptr,
63     .nm_register_func = Export,
64     .nm_modname = "multimedia.image",
65     .nm_priv = (reinterpret_cast<void *>(0)),
66     .reserved = {0}
67 };
68 
69 /*
70  * module register
71  */
ImageRegisterModule(void)72 extern "C" __attribute__((constructor)) void ImageRegisterModule(void)
73 {
74     napi_module_register(&g_module);
75 }
76 } // namespace Media
77 } // namespace OHOS
78