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