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 "napi/native_api.h"
17 #include "hiappevent.h"
18 #define FAIL (-1)
19 #define SUCCESS 0
20 #define PARAM_0 0
21 #define PARAM_1 1
22 
23 const float FLOAT_123_22 = 123.22f;
24 const float FLOAT_234_5 = 234.5f;
25 const float FLOAT_131312_46464 = 131312.46464f;
26 const double DOUBLE_123_22 = 123.22;
27 const double DOUBLE_30949_374 = 30949.374;
28 const double DOUBLE_131312_46464 = 131312.46464;
29 
30 static struct HiAppEvent_Watcher *watcher;
31 
OnReceiver(const char *domain, const struct HiAppEvent_AppEventGroup *appEventGroups, uint32_t groupSize)32 static void OnReceiver(const char *domain, const struct HiAppEvent_AppEventGroup *appEventGroups, uint32_t groupSize)
33 {
34 }
35 
OnTrigger(int row, int size)36 static void OnTrigger(int row, int size)
37 {
38 };
39 
OnTake(const char *const *events, uint32_t eventLen)40 static void OnTake(const char *const *events, uint32_t eventLen)
41 {
42 }
43 
OHHiAppEventWrite(napi_env env, napi_callback_info info)44 static napi_value OHHiAppEventWrite(napi_env env, napi_callback_info info)
45 {
46     ParamList list = OH_HiAppEvent_CreateParamList();
47     int32_t num = PARAM_1;
48     OH_HiAppEvent_AddInt32Param(list, "int32_key", num);
49     int32_t numArray[] = {PARAM_1, INT32_MAX, INT32_MIN};
50     OH_HiAppEvent_AddInt32ArrayParam(list, "int32_arr_key", numArray, sizeof(numArray) / sizeof(numArray[0]));
51     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
52     napi_value result = nullptr;
53     napi_create_int32(env, ret, &result);
54     return result;
55 }
56 
OHHiAppEventConfigure(napi_env env, napi_callback_info info)57 static napi_value OHHiAppEventConfigure(napi_env env, napi_callback_info info)
58 {
59     ParamList list = OH_HiAppEvent_CreateParamList();
60     int32_t num = PARAM_1;
61     OH_HiAppEvent_AddInt32Param(list, "int32_key", num);
62     int ret = -PARAM_1;
63     bool configure = OH_HiAppEvent_Configure(DISABLE, "true");
64     if (configure) {
65         ret = SUCCESS;
66     }
67     OH_HiAppEvent_Configure(DISABLE, "false");
68     napi_value result = nullptr;
69     napi_create_int32(env, ret, &result);
70     return result;
71 }
72 
OHHiAppEventAddBoolParam(napi_env env, napi_callback_info info)73 static napi_value OHHiAppEventAddBoolParam(napi_env env, napi_callback_info info)
74 {
75     ParamList list = OH_HiAppEvent_CreateParamList();
76     OH_HiAppEvent_AddBoolParam(list, "bool_key", true);
77     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
78     napi_value result = nullptr;
79     napi_create_int32(env, ret, &result);
80     return result;
81 }
82 
OHHiAppEventAddBoolArrayParam(napi_env env, napi_callback_info info)83 static napi_value OHHiAppEventAddBoolArrayParam(napi_env env, napi_callback_info info)
84 {
85     ParamList list = OH_HiAppEvent_CreateParamList();
86     bool nums[] = {true};
87     OH_HiAppEvent_AddBoolArrayParam(list, "bool_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
88     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
89     napi_value result = nullptr;
90     napi_create_int32(env, ret, &result);
91     return result;
92 }
93 
OHHiAppEventAddInt8Param(napi_env env, napi_callback_info info)94 static napi_value OHHiAppEventAddInt8Param(napi_env env, napi_callback_info info)
95 {
96     ParamList list = OH_HiAppEvent_CreateParamList();
97     int8_t num = PARAM_1;
98     OH_HiAppEvent_AddInt8Param(list, "int8_key", num);
99     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
100     napi_value result = nullptr;
101     napi_create_int32(env, ret, &result);
102     return result;
103 }
104 
OHHiAppEventAddInt8ArrayParam(napi_env env, napi_callback_info info)105 static napi_value OHHiAppEventAddInt8ArrayParam(napi_env env, napi_callback_info info)
106 {
107     ParamList list = OH_HiAppEvent_CreateParamList();
108     int8_t num[] = {PARAM_1, INT8_MAX, INT8_MIN};
109     OH_HiAppEvent_AddInt8ArrayParam(list, "int8_key", num, sizeof(num) / sizeof(num[0]));
110     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
111     napi_value result = nullptr;
112     napi_create_int32(env, ret, &result);
113     return result;
114 }
115 
OHHiAppEventAddInt16Param(napi_env env, napi_callback_info info)116 static napi_value OHHiAppEventAddInt16Param(napi_env env, napi_callback_info info)
117 {
118     ParamList list = OH_HiAppEvent_CreateParamList();
119     int16_t num = PARAM_1;
120     OH_HiAppEvent_AddInt16Param(list, "int16_key", num);
121     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
122     napi_value result = nullptr;
123     napi_create_int32(env, ret, &result);
124     return result;
125 }
126 
OHHiAppEventAddInt16ArrayParam(napi_env env, napi_callback_info info)127 static napi_value OHHiAppEventAddInt16ArrayParam(napi_env env, napi_callback_info info)
128 {
129     ParamList list = OH_HiAppEvent_CreateParamList();
130     int16_t num[] = {PARAM_1, INT16_MAX, INT16_MIN};
131     OH_HiAppEvent_AddInt16ArrayParam(list, "int16_key", num, sizeof(num) / sizeof(num[0]));
132     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
133     napi_value result = nullptr;
134     napi_create_int32(env, ret, &result);
135     return result;
136 }
137 
OHHiAppEventAddInt32Param(napi_env env, napi_callback_info info)138 static napi_value OHHiAppEventAddInt32Param(napi_env env, napi_callback_info info)
139 {
140     ParamList list = OH_HiAppEvent_CreateParamList();
141     int32_t num = PARAM_1;
142     OH_HiAppEvent_AddInt32Param(list, "int32_key", num);
143     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
144     napi_value result = nullptr;
145     napi_create_int32(env, ret, &result);
146     return result;
147 }
148 
OHHiAppEventAddInt32ArrayParam(napi_env env, napi_callback_info info)149 static napi_value OHHiAppEventAddInt32ArrayParam(napi_env env, napi_callback_info info)
150 {
151     ParamList list = OH_HiAppEvent_CreateParamList();
152     int32_t num[] = {PARAM_1, INT32_MAX, INT32_MIN};
153     OH_HiAppEvent_AddInt32ArrayParam(list, "int32_key", num, sizeof(num) / sizeof(num[0]));
154     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
155     napi_value result = nullptr;
156     napi_create_int32(env, ret, &result);
157     return result;
158 }
159 
OHHiAppEventAddInt64Param(napi_env env, napi_callback_info info)160 static napi_value OHHiAppEventAddInt64Param(napi_env env, napi_callback_info info)
161 {
162     ParamList list = OH_HiAppEvent_CreateParamList();
163     int64_t num = PARAM_1;
164     OH_HiAppEvent_AddInt64Param(list, "int64_key", num);
165     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
166     napi_value result = nullptr;
167     napi_create_int32(env, ret, &result);
168     return result;
169 }
170 
OHHiAppEventAddInt64ArrayParam(napi_env env, napi_callback_info info)171 static napi_value OHHiAppEventAddInt64ArrayParam(napi_env env, napi_callback_info info)
172 {
173     ParamList list = OH_HiAppEvent_CreateParamList();
174     int64_t num[] = {PARAM_1, INT64_MAX, INT64_MIN};
175     OH_HiAppEvent_AddInt64ArrayParam(list, "int64_key", num, sizeof(num) / sizeof(num[0]));
176     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
177     napi_value result = nullptr;
178     napi_create_int32(env, ret, &result);
179     return result;
180 }
181 
OHHiAppEventAddFloatParam(napi_env env, napi_callback_info info)182 static napi_value OHHiAppEventAddFloatParam(napi_env env, napi_callback_info info)
183 {
184     ParamList list = OH_HiAppEvent_CreateParamList();
185     float num = FLOAT_234_5;
186     OH_HiAppEvent_AddFloatParam(list, "float_key", num);
187     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
188     napi_value result = nullptr;
189     napi_create_int32(env, ret, &result);
190     return result;
191 }
192 
OHHiAppEventAddFloatArrayParam(napi_env env, napi_callback_info info)193 static napi_value OHHiAppEventAddFloatArrayParam(napi_env env, napi_callback_info info)
194 {
195     ParamList list = OH_HiAppEvent_CreateParamList();
196     float num[] = {FLOAT_123_22, FLOAT_234_5, FLOAT_131312_46464};
197     OH_HiAppEvent_AddFloatArrayParam(list, "float_key", num, sizeof(num) / sizeof(num[0]));
198     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
199     napi_value result = nullptr;
200     napi_create_int32(env, ret, &result);
201     return result;
202 }
203 
OHHiAppEventAddDoubleParam(napi_env env, napi_callback_info info)204 static napi_value OHHiAppEventAddDoubleParam(napi_env env, napi_callback_info info)
205 {
206     ParamList list = OH_HiAppEvent_CreateParamList();
207     double num = DOUBLE_30949_374;
208     OH_HiAppEvent_AddDoubleParam(list, "double_key", num);
209     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
210     napi_value result = nullptr;
211     napi_create_int32(env, ret, &result);
212     return result;
213 }
214 
OHHiAppEventAddDoubleArrayParam(napi_env env, napi_callback_info info)215 static napi_value OHHiAppEventAddDoubleArrayParam(napi_env env, napi_callback_info info)
216 {
217     ParamList list = OH_HiAppEvent_CreateParamList();
218     double nums[] = {DOUBLE_123_22, DOUBLE_30949_374, DOUBLE_131312_46464};
219     OH_HiAppEvent_AddDoubleArrayParam(list, "double_arr_key", nums, sizeof(nums) / sizeof(nums[0]));
220     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
221     napi_value result = nullptr;
222     napi_create_int32(env, ret, &result);
223     return result;
224 }
225 
OHHiAppEventAddStringParam(napi_env env, napi_callback_info info)226 static napi_value OHHiAppEventAddStringParam(napi_env env, napi_callback_info info)
227 {
228     ParamList list = OH_HiAppEvent_CreateParamList();
229     char str[] = "hello";
230     OH_HiAppEvent_AddStringParam(list, "string_key", str);
231     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
232     napi_value result = nullptr;
233     napi_create_int32(env, ret, &result);
234     return result;
235 }
236 
OHHiAppEventAddStringArrayParam(napi_env env, napi_callback_info info)237 static napi_value OHHiAppEventAddStringArrayParam(napi_env env, napi_callback_info info)
238 {
239     ParamList list = OH_HiAppEvent_CreateParamList();
240     char str[] = "hello";
241     char par[] = "world";
242     char *strs[] = {str, par};
243     OH_HiAppEvent_AddStringArrayParam(list, "string_arr_key", strs, sizeof(strs) / sizeof(strs[0]));
244     int ret = OH_HiAppEvent_Write("domain", "name", BEHAVIOR, list);
245     napi_value result = nullptr;
246     napi_create_int32(env, ret, &result);
247     return result;
248 }
249 
OHHiAppEventCreateParamList(napi_env env, napi_callback_info info)250 static napi_value OHHiAppEventCreateParamList(napi_env env, napi_callback_info info)
251 {
252     ParamList list = OH_HiAppEvent_CreateParamList();
253     int ret = FAIL;
254     if (list != nullptr) {
255         ret = SUCCESS;
256     }
257     napi_value result = nullptr;
258     napi_create_int32(env, ret, &result);
259     return result;
260 }
261 
SetAppEventFilter(napi_env env, napi_callback_info info)262 static napi_value SetAppEventFilter(napi_env env, napi_callback_info info)
263 {
264     napi_value ret;
265     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
266     int32_t code = OH_HiAppEvent_SetAppEventFilter(watcher, "testDomain", 0b1000, {}, 0);
267     OH_HiAppEvent_DestroyWatcher(watcher);
268     napi_create_int32(env, code, &ret);
269     return ret;
270 }
271 
SetAppEventFilterInvName(napi_env env, napi_callback_info info)272 static napi_value SetAppEventFilterInvName(napi_env env, napi_callback_info info)
273 {
274     napi_value ret;
275     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
276     int32_t code = OH_HiAppEvent_SetAppEventFilter(watcher, "nullptr", 0b1000, {}, 1);
277     OH_HiAppEvent_DestroyWatcher(watcher);
278     napi_create_int32(env, code, &ret);
279     return ret;
280 }
281 
SetAppEventFilterInvDomain(napi_env env, napi_callback_info info)282 static napi_value SetAppEventFilterInvDomain(napi_env env, napi_callback_info info)
283 {
284     napi_value ret;
285     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
286     int32_t code = OH_HiAppEvent_SetAppEventFilter(watcher, nullptr, 0b1000, {}, 0);
287     OH_HiAppEvent_DestroyWatcher(watcher);
288     napi_create_int32(env, code, &ret);
289     return ret;
290 }
291 
SetAppEventFilterInvWatcher(napi_env env, napi_callback_info info)292 static napi_value SetAppEventFilterInvWatcher(napi_env env, napi_callback_info info)
293 {
294     napi_value ret;
295     watcher = OH_HiAppEvent_CreateWatcher(nullptr);
296     int32_t code = OH_HiAppEvent_SetAppEventFilter(watcher, "testDomain", 0b1000, {}, 0);
297     OH_HiAppEvent_DestroyWatcher(watcher);
298     napi_create_int32(env, code, &ret);
299     return ret;
300 }
301 
SetTriggerCondition(napi_env env, napi_callback_info info)302 static napi_value SetTriggerCondition(napi_env env, napi_callback_info info)
303 {
304     napi_value ret;
305     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
306     int32_t code = OH_HiAppEvent_SetTriggerCondition(watcher, 1, 0, 0);
307     OH_HiAppEvent_DestroyWatcher(watcher);
308     napi_create_int32(env, code, &ret);
309     return ret;
310 }
311 
SetTriggerConditionInvWatcher(napi_env env, napi_callback_info info)312 static napi_value SetTriggerConditionInvWatcher(napi_env env, napi_callback_info info)
313 {
314     napi_value ret;
315     watcher = OH_HiAppEvent_CreateWatcher(nullptr);
316     int32_t code = OH_HiAppEvent_SetTriggerCondition(watcher, 1, 0, 0);
317     OH_HiAppEvent_DestroyWatcher(watcher);
318     napi_create_int32(env, code, &ret);
319     return ret;
320 }
321 
SetWatcherOnTrigger(napi_env env, napi_callback_info info)322 static napi_value SetWatcherOnTrigger(napi_env env, napi_callback_info info)
323 {
324     napi_value ret;
325     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
326     int32_t code = OH_HiAppEvent_SetWatcherOnTrigger(watcher, OnTrigger);
327     OH_HiAppEvent_DestroyWatcher(watcher);
328     napi_create_int32(env, code, &ret);
329     return ret;
330 }
331 
SetWatcherOnTriggerInvWatcher(napi_env env, napi_callback_info info)332 static napi_value SetWatcherOnTriggerInvWatcher(napi_env env, napi_callback_info info)
333 {
334     napi_value ret;
335     watcher = OH_HiAppEvent_CreateWatcher(nullptr);
336     int32_t code = OH_HiAppEvent_SetWatcherOnTrigger(watcher, OnTrigger);
337     OH_HiAppEvent_DestroyWatcher(watcher);
338     napi_create_int32(env, code, &ret);
339     return ret;
340 }
341 
SetWatcherOnReceive(napi_env env, napi_callback_info info)342 static napi_value SetWatcherOnReceive(napi_env env, napi_callback_info info)
343 {
344     napi_value ret;
345     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
346     int32_t code = OH_HiAppEvent_SetWatcherOnReceive(watcher, OnReceiver);
347     OH_HiAppEvent_DestroyWatcher(watcher);
348     napi_create_int32(env, code, &ret);
349     return ret;
350 }
351 
SetWatcherOnReceiveInvWatcher(napi_env env, napi_callback_info info)352 static napi_value SetWatcherOnReceiveInvWatcher(napi_env env, napi_callback_info info)
353 {
354     napi_value ret;
355     watcher = OH_HiAppEvent_CreateWatcher(nullptr);
356     int32_t code = OH_HiAppEvent_SetWatcherOnReceive(watcher, OnReceiver);
357     OH_HiAppEvent_DestroyWatcher(watcher);
358     napi_create_int32(env, code, &ret);
359     return ret;
360 }
361 
TakeWatcherData(napi_env env, napi_callback_info info)362 static napi_value TakeWatcherData(napi_env env, napi_callback_info info)
363 {
364     napi_value ret;
365     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
366     OH_HiAppEvent_AddWatcher(watcher);
367     int32_t code = OH_HiAppEvent_TakeWatcherData(watcher, 1, OnTake);
368     OH_HiAppEvent_DestroyWatcher(watcher);
369     napi_create_int32(env, code, &ret);
370     return ret;
371 }
372 
TakeWatcherDataInvWatcher(napi_env env, napi_callback_info info)373 static napi_value TakeWatcherDataInvWatcher(napi_env env, napi_callback_info info)
374 {
375     napi_value ret;
376     watcher = OH_HiAppEvent_CreateWatcher(nullptr);
377     OH_HiAppEvent_AddWatcher(watcher);
378     int32_t code = OH_HiAppEvent_TakeWatcherData(watcher, 1, OnTake);
379     OH_HiAppEvent_DestroyWatcher(watcher);
380     napi_create_int32(env, code, &ret);
381     return ret;
382 }
TakeWatcherDataInvOperation(napi_env env, napi_callback_info info)383 static napi_value TakeWatcherDataInvOperation(napi_env env, napi_callback_info info)
384 {
385     napi_value ret;
386     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
387     int32_t code = OH_HiAppEvent_TakeWatcherData(watcher, 1, OnTake);
388     OH_HiAppEvent_DestroyWatcher(watcher);
389     napi_create_int32(env, code, &ret);
390     return ret;
391 }
392 
AddWatcher(napi_env env, napi_callback_info info)393 static napi_value AddWatcher(napi_env env, napi_callback_info info)
394 {
395     napi_value ret;
396     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
397     int32_t code = OH_HiAppEvent_AddWatcher(watcher);
398     OH_HiAppEvent_DestroyWatcher(watcher);
399     napi_create_int32(env, code, &ret);
400     return ret;
401 }
402 
AddWatcherInvWatcher(napi_env env, napi_callback_info info)403 static napi_value AddWatcherInvWatcher(napi_env env, napi_callback_info info)
404 {
405     napi_value ret;
406     watcher = OH_HiAppEvent_CreateWatcher(nullptr);
407     int32_t code = OH_HiAppEvent_AddWatcher(watcher);
408     OH_HiAppEvent_DestroyWatcher(watcher);
409     napi_create_int32(env, code, &ret);
410     return ret;
411 }
412 
RemoveWatcher(napi_env env, napi_callback_info info)413 static napi_value RemoveWatcher(napi_env env, napi_callback_info info)
414 {
415     napi_value ret;
416     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
417     OH_HiAppEvent_AddWatcher(watcher);
418     int32_t code = OH_HiAppEvent_RemoveWatcher(watcher);
419     OH_HiAppEvent_DestroyWatcher(watcher);
420     napi_create_int32(env, code, &ret);
421     return ret;
422 }
423 
RemoveWatcherInvWatcher(napi_env env, napi_callback_info info)424 static napi_value RemoveWatcherInvWatcher(napi_env env, napi_callback_info info)
425 {
426     napi_value ret;
427     watcher = OH_HiAppEvent_CreateWatcher(nullptr);
428     OH_HiAppEvent_AddWatcher(watcher);
429     int32_t code = OH_HiAppEvent_RemoveWatcher(watcher);
430     OH_HiAppEvent_DestroyWatcher(watcher);
431     napi_create_int32(env, code, &ret);
432     return ret;
433 }
434 
RemoveWatcherInvOperation(napi_env env, napi_callback_info info)435 static napi_value RemoveWatcherInvOperation(napi_env env, napi_callback_info info)
436 {
437     napi_value ret;
438     watcher = OH_HiAppEvent_CreateWatcher("testWatcher");
439     int32_t code = OH_HiAppEvent_RemoveWatcher(watcher);
440     OH_HiAppEvent_DestroyWatcher(watcher);
441     OH_HiAppEvent_ClearData();
442     napi_create_int32(env, code, &ret);
443     return ret;
444 }
445 
446 EXTERN_C_START
Init(napi_env env, napi_value exports)447 static napi_value Init(napi_env env, napi_value exports)
448 {
449     napi_property_descriptor desc[] = {
450         {"oHHiAppEventWrite", nullptr, OHHiAppEventWrite, nullptr, nullptr, nullptr, napi_default, nullptr},
451         {"oHHiAppEventConfigure", nullptr, OHHiAppEventConfigure, nullptr, nullptr, nullptr, napi_default, nullptr},
452         {"oHHiAppEventAddBoolParam", nullptr, OHHiAppEventAddBoolParam, nullptr, nullptr, nullptr,
453          napi_default, nullptr},
454         {"oHHiAppEventAddBoolArrayParam", nullptr, OHHiAppEventAddBoolArrayParam, nullptr, nullptr, nullptr,
455          napi_default, nullptr},
456         {"oHHiAppEventAddInt8Param", nullptr, OHHiAppEventAddInt8Param, nullptr, nullptr, nullptr,
457          napi_default, nullptr},
458         {"oHHiAppEventAddInt8ArrayParam", nullptr, OHHiAppEventAddInt8ArrayParam, nullptr, nullptr, nullptr,
459          napi_default, nullptr},
460         {"oHHiAppEventAddInt16Param", nullptr, OHHiAppEventAddInt16Param, nullptr, nullptr, nullptr,
461          napi_default, nullptr},
462         {"oHHiAppEventAddInt16ArrayParam", nullptr, OHHiAppEventAddInt16ArrayParam, nullptr, nullptr, nullptr,
463          napi_default, nullptr},
464         {"oHHiAppEventAddInt32Param", nullptr, OHHiAppEventAddInt32Param, nullptr, nullptr, nullptr,
465          napi_default, nullptr},
466         {"oHHiAppEventAddInt32ArrayParam", nullptr, OHHiAppEventAddInt32ArrayParam, nullptr, nullptr, nullptr,
467          napi_default, nullptr},
468         {"oHHiAppEventAddInt64Param", nullptr, OHHiAppEventAddInt64Param, nullptr, nullptr, nullptr,
469          napi_default, nullptr},
470         {"oHHiAppEventAddInt64ArrayParam", nullptr, OHHiAppEventAddInt64ArrayParam, nullptr, nullptr, nullptr,
471          napi_default, nullptr},
472         {"oHHiAppEventAddFloatParam", nullptr, OHHiAppEventAddFloatParam, nullptr, nullptr, nullptr,
473          napi_default, nullptr},
474         {"oHHiAppEventAddFloatArrayParam", nullptr, OHHiAppEventAddFloatArrayParam, nullptr, nullptr, nullptr,
475          napi_default, nullptr},
476         {"oHHiAppEventAddDoubleParam", nullptr, OHHiAppEventAddDoubleParam, nullptr, nullptr, nullptr,
477          napi_default, nullptr},
478         {"oHHiAppEventAddDoubleArrayParam", nullptr, OHHiAppEventAddDoubleArrayParam, nullptr, nullptr, nullptr,
479          napi_default, nullptr},
480         {"oHHiAppEventAddStringParam", nullptr, OHHiAppEventAddStringParam, nullptr, nullptr, nullptr,
481          napi_default, nullptr},
482         {"oHHiAppEventAddStringArrayParam", nullptr, OHHiAppEventAddStringArrayParam, nullptr, nullptr, nullptr,
483          napi_default, nullptr},
484         {"oHHiAppEventCreateParamList", nullptr, OHHiAppEventCreateParamList, nullptr, nullptr, nullptr,
485          napi_default, nullptr},
486         { "setAppEventFilter", nullptr, SetAppEventFilter, nullptr, nullptr, nullptr,
487          napi_default, nullptr },
488         { "setAppEventFilterInvName", nullptr, SetAppEventFilterInvName, nullptr, nullptr, nullptr,
489          napi_default, nullptr },
490         { "setAppEventFilterInvDomain", nullptr, SetAppEventFilterInvDomain, nullptr, nullptr, nullptr,
491          napi_default, nullptr },
492         { "setAppEventFilterInvWatcher", nullptr, SetAppEventFilterInvWatcher, nullptr, nullptr, nullptr,
493          napi_default, nullptr },
494         { "setTriggerCondition", nullptr, SetTriggerCondition, nullptr, nullptr, nullptr,
495          napi_default, nullptr },
496         { "setTriggerConditionInvWatcher", nullptr, SetTriggerConditionInvWatcher, nullptr, nullptr, nullptr,
497          napi_default, nullptr },
498         { "setWatcherOnTrigger", nullptr, SetWatcherOnTrigger, nullptr, nullptr, nullptr,
499          napi_default, nullptr },
500         { "setWatcherOnTriggerInvWatcher", nullptr, SetWatcherOnTriggerInvWatcher, nullptr, nullptr, nullptr,
501          napi_default, nullptr },
502         { "setWatcherOnReceive", nullptr, SetWatcherOnReceive, nullptr, nullptr, nullptr,
503          napi_default, nullptr },
504         { "setWatcherOnReceiveInvWatcher", nullptr, SetWatcherOnReceiveInvWatcher, nullptr, nullptr, nullptr,
505          napi_default, nullptr },
506         { "takeWatcherData", nullptr, TakeWatcherData, nullptr, nullptr, nullptr,
507          napi_default, nullptr },
508         { "takeWatcherDataInvWatcher", nullptr, TakeWatcherDataInvWatcher, nullptr, nullptr, nullptr,
509          napi_default, nullptr },
510         { "takeWatcherDataInvOperation", nullptr, TakeWatcherDataInvOperation, nullptr, nullptr, nullptr,
511          napi_default, nullptr },
512         { "addWatcher", nullptr, AddWatcher, nullptr, nullptr, nullptr,
513          napi_default, nullptr },
514         { "addWatcherInvWatcher", nullptr, AddWatcherInvWatcher, nullptr, nullptr, nullptr,
515          napi_default, nullptr },
516         { "removeWatcher", nullptr, RemoveWatcher, nullptr, nullptr, nullptr,
517          napi_default, nullptr },
518         { "removeWatcherInvWatcher", nullptr, RemoveWatcherInvWatcher, nullptr, nullptr, nullptr,
519          napi_default, nullptr },
520         { "removeWatcherInvOperation", nullptr, RemoveWatcherInvOperation, nullptr, nullptr, nullptr,
521          napi_default, nullptr }};
522     napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
523     return exports;
524 }
525 
526 EXTERN_C_END
527 
528 static napi_module demoModule = {
529     .nm_version = 1,
530     .nm_flags = 0,
531     .nm_filename = nullptr,
532     .nm_register_func = Init,
533     .nm_modname = "hiappevent",
534     .nm_priv = ((void *)0),
535     .reserved = {0},
536 };
537 
RegisterModule(void)538 extern "C" __attribute__((constructor)) void RegisterModule(void) { napi_module_register(&demoModule); }
539