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 #define LOG_TAG "EntryPoint"
16 #include "js_const_properties.h"
17 #include "js_field_node.h"
18 #include "js_kv_manager.h"
19 #include "js_query.h"
20 #include "js_schema.h"
21 #include "js_util.h"
22 #include "log_print.h"
23
24 using namespace OHOS::DistributedData;
25
Init(napi_env env,napi_value exports)26 static napi_value Init(napi_env env, napi_value exports)
27 {
28 const napi_property_descriptor desc[] = {
29 DECLARE_NAPI_FUNCTION("createKVManager", JsKVManager::CreateKVManager)
30 };
31 napi_status status = napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
32 ZLOGI("init createKVManager %{public}d", status);
33
34 status = napi_set_named_property(env, exports, "FieldNode", JsFieldNode::Constructor(env));
35 ZLOGI("init FieldNode %{public}d", status);
36
37 status = napi_set_named_property(env, exports, "Schema", JsSchema::Constructor(env));
38 ZLOGI("init Schema %{public}d", status);
39
40 status = napi_set_named_property(env, exports, "Query", JsQuery::Constructor(env));
41 ZLOGI("init Query %{public}d", status);
42
43 status = InitConstProperties(env, exports);
44 ZLOGI("init Enumerate Constants %{public}d", status);
45 return exports;
46 }
47
RegisterModule()48 static __attribute__((constructor)) void RegisterModule()
49 {
50 static napi_module module = { .nm_version = 1,
51 .nm_flags = 0,
52 .nm_filename = nullptr,
53 .nm_register_func = Init,
54 .nm_modname = "data.distributedData",
55 .nm_priv = ((void*)0),
56 .reserved = { 0 } };
57 napi_module_register(&module);
58 ZLOGI("module register data.distributedData");
59 }
60