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 "cloud_sync_manager_napi.h"
17 #include "cloud_sync_manager_n_exporter.h"
18 
19 namespace OHOS::FileManagement::CloudSync {
20 using namespace FileManagement::LibN;
21 /***********************************************
22  * Module export and register
23  ***********************************************/
24 
Init(napi_env env,napi_value exports)25 static napi_value Init(napi_env env, napi_value exports)
26 {
27     CloudSyncManagerExport(env, exports);
28     InitENumACtions(env, exports);
29 
30     return exports;
31 }
32 
CloudSyncManagerExport(napi_env env,napi_value exports)33 void CloudSyncManagerExport(napi_env env, napi_value exports)
34 {
35     static napi_property_descriptor desc[] = {
36         DECLARE_NAPI_FUNCTION("changeAppCloudSwitch", ChangeAppCloudSwitch),
37         DECLARE_NAPI_FUNCTION("clean", Clean),
38         DECLARE_NAPI_FUNCTION("notifyDataChange", NotifyDataChange),
39         DECLARE_NAPI_FUNCTION("enableCloud", EnableCloud),
40         DECLARE_NAPI_FUNCTION("disableCloud", DisableCloud),
41     };
42     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
43 }
44 
InitENumACtions(napi_env env,napi_value exports)45 void InitENumACtions(napi_env env, napi_value exports)
46 {
47     char propertyName[] = "Action";
48     napi_value actionObj = nullptr;
49     napi_create_object(env, &actionObj);
50     napi_property_descriptor desc[] = {
51         DECLARE_NAPI_STATIC_PROPERTY("RETAIN_DATA", NVal::CreateInt32(env, (int32_t)Action::RETAIN_DATA).val_),
52         DECLARE_NAPI_STATIC_PROPERTY("CLEAR_DATA", NVal::CreateInt32(env, (int32_t)Action::CLEAR_DATA).val_),
53     };
54     napi_define_properties(env, actionObj, sizeof(desc) / sizeof(desc[0]), desc);
55     napi_set_named_property(env, exports, propertyName, actionObj);
56 }
57 
58 static napi_module _module = {
59     .nm_version = 1,
60     .nm_flags = 0,
61     .nm_filename = nullptr,
62     .nm_register_func = Init,
63     .nm_modname = "file.cloudSyncManager",
64     .nm_priv = ((void *)0),
65     .reserved = {0}
66 };
67 
RegisterModule(void)68 extern "C" __attribute__((constructor)) void RegisterModule(void)
69 {
70     napi_module_register(&_module);
71 }
72 } // namespace OHOS::FileManagement::CloudSync
73