• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "reminder/native_module_manager.h"
17 
18 #include "napi/native_api.h"
19 #include "napi/native_node_api.h"
20 #include "reminder/publish.h"
21 #include "manager/napi_slot.h"
22 
23 namespace OHOS {
24 namespace ReminderAgentNapi {
25 EXTERN_C_START
ReminderAgentManagerInit(napi_env env,napi_value exports)26 napi_value ReminderAgentManagerInit(napi_env env, napi_value exports)
27 {
28     ANSR_LOGI("ReminderAgentManagerInit start");
29     napi_property_descriptor desc[] = {
30         DECLARE_NAPI_FUNCTION("cancelReminder", CancelReminderMgr),
31         DECLARE_NAPI_FUNCTION("cancelAllReminders", CancelAllRemindersMgr),
32         DECLARE_NAPI_FUNCTION("getValidReminders", GetValidRemindersMgr),
33         DECLARE_NAPI_FUNCTION("publishReminder", PublishReminderMgr),
34         DECLARE_NAPI_FUNCTION("addNotificationSlot", AddSlotMgr),
35         DECLARE_NAPI_FUNCTION("removeNotificationSlot", NotificationNapi::NapiRemoveSlot),
36     };
37     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
38     return exports;
39 }
40 
ConstantInit(napi_env env,napi_value exports)41 napi_value ConstantInit(napi_env env, napi_value exports)
42 {
43     ANSR_LOGI("ConstantInit start");
44     napi_value objReminderType = nullptr;
45     napi_create_object(env, &objReminderType);
46 
47     napi_value prop = nullptr;
48     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::TIMER), &prop) == napi_ok) {
49         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_TIMER", prop);
50     }
51     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::ALARM), &prop) == napi_ok) {
52         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_ALARM", prop);
53     }
54     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::CALENDAR), &prop) == napi_ok) {
55         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_CALENDAR", prop);
56     }
57 
58     napi_value objButtonType = nullptr;
59     napi_create_object(env, &objButtonType);
60     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::CLOSE), &prop) == napi_ok) {
61         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_CLOSE", prop);
62     }
63     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::SNOOZE), &prop) == napi_ok) {
64         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_SNOOZE", prop);
65     }
66 
67     napi_property_descriptor exportFuncs[] = {
68         DECLARE_NAPI_PROPERTY("ReminderType", objReminderType),
69         DECLARE_NAPI_PROPERTY("ActionButtonType", objButtonType),
70     };
71 
72     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
73     return exports;
74 };
75 EXTERN_C_END
76 
77 /*
78  * Module define
79  */
80 static napi_module _apiModule = {
81     .nm_version = 1,
82     .nm_flags = 0,
83     .nm_filename = nullptr,
84     .nm_register_func = ManagerInit,
85     .nm_modname = "reminderAgentManager",
86     .nm_priv = ((void *)0),
87     .reserved = {0},
88 };
89 
90 /*
91  * function for module exports
92  */
ManagerInit(napi_env env,napi_value exports)93 static napi_value ManagerInit(napi_env env, napi_value exports)
94 {
95     ReminderAgentManagerInit(env, exports);
96     ConstantInit(env, exports);
97     return exports;
98 }
99 
100 /*
101  * Module register function
102  */
RegisterModule(void)103 extern "C" __attribute__((constructor)) void RegisterModule(void)
104 {
105     napi_module_register(&_apiModule);
106 }
107 }  // namespace ReminderAgentNapi
108 }  // namespace OHOS