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 "js_common.h"
17 #include "js_distributedobjectstore.h"
18 #include "logger.h"
19 #include "notifier_impl.h"
20
21 using namespace OHOS::ObjectStore;
22
23 extern const char _binary_distributed_data_object_js_start[];
24 extern const char _binary_distributed_data_object_js_end[];
25
26 extern const char _binary_distributed_data_object_abc_start[];
27 extern const char _binary_distributed_data_object_abc_end[];
28
DistributedDataObjectExport(napi_env env,napi_value exports)29 static napi_value DistributedDataObjectExport(napi_env env, napi_value exports)
30 {
31 napi_status status;
32 static napi_property_descriptor desc[] = {
33 DECLARE_NAPI_FUNCTION("createObjectSync", JSDistributedObjectStore::JSCreateObjectSync),
34 DECLARE_NAPI_FUNCTION("destroyObjectSync", JSDistributedObjectStore::JSDestroyObjectSync),
35 DECLARE_NAPI_FUNCTION("on", JSDistributedObjectStore::JSOn),
36 DECLARE_NAPI_FUNCTION("off", JSDistributedObjectStore::JSOff),
37 DECLARE_NAPI_FUNCTION("recordCallback", JSDistributedObjectStore::JSRecordCallback),
38 DECLARE_NAPI_FUNCTION("deleteCallback", JSDistributedObjectStore::JSDeleteCallback),
39 DECLARE_NAPI_FUNCTION("sequenceNum", JSDistributedObjectStore::JSEquenceNum),
40 };
41
42 status = napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
43 CHECK_EQUAL_WITH_RETURN_NULL(status, napi_ok);
44 return exports;
45 }
46
47 // storage module define
48 static napi_module storageModule = {
49 .nm_version = 1,
50 .nm_flags = 0,
51 .nm_filename = nullptr,
52 .nm_register_func = DistributedDataObjectExport,
53 .nm_modname = "data.distributedDataObject",
54 .nm_priv = ((void *)0),
55 .reserved = { 0 },
56 };
57
58 // distributed_data_object.js
NAPI_data_distributedDataObject_GetJSCode(const char ** buf,int * bufLen)59 extern "C" __attribute__((visibility("default"))) void NAPI_data_distributedDataObject_GetJSCode(
60 const char **buf, int *bufLen)
61 {
62 if (buf != nullptr) {
63 *buf = _binary_distributed_data_object_js_start;
64 }
65
66 if (bufLen != nullptr) {
67 *bufLen = _binary_distributed_data_object_js_end - _binary_distributed_data_object_js_start;
68 }
69 }
70
NAPI_data_distributedDataObject_GetABCCode(const char ** buf,int * bufLen)71 extern "C" __attribute__((visibility("default"))) void NAPI_data_distributedDataObject_GetABCCode(
72 const char **buf, int *bufLen)
73 {
74 if (buf != nullptr) {
75 *buf = _binary_distributed_data_object_abc_start;
76 }
77
78 if (bufLen != nullptr) {
79 *bufLen = _binary_distributed_data_object_abc_end - _binary_distributed_data_object_abc_start;
80 }
81 }
82
83 // distributeddataobject module register
RegisterModule()84 static __attribute__((constructor)) void RegisterModule()
85 {
86 napi_module_register(&storageModule);
87 }