• 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_LOGD("called");
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("getAllValidReminders", GetAllValidRemindersMgr),
34         DECLARE_NAPI_FUNCTION("publishReminder", PublishReminderMgr),
35         DECLARE_NAPI_FUNCTION("addNotificationSlot", AddSlotMgr),
36         DECLARE_NAPI_FUNCTION("removeNotificationSlot", NotificationNapi::NapiRemoveSlot),
37         DECLARE_NAPI_FUNCTION("addExcludeDate", AddExcludeDate),
38         DECLARE_NAPI_FUNCTION("deleteExcludeDates", DelExcludeDates),
39         DECLARE_NAPI_FUNCTION("getExcludeDates", GetExcludeDates),
40         DECLARE_NAPI_FUNCTION("updateReminder", UpdateReminder),
41     };
42     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
43     return exports;
44 }
45 
ConstantInit(napi_env env,napi_value exports)46 napi_value ConstantInit(napi_env env, napi_value exports)
47 {
48     ANSR_LOGD("called");
49     napi_value objReminderType = nullptr;
50     napi_create_object(env, &objReminderType);
51 
52     napi_value prop = nullptr;
53     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::TIMER), &prop) == napi_ok) {
54         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_TIMER", prop);
55     }
56     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::ALARM), &prop) == napi_ok) {
57         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_ALARM", prop);
58     }
59     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::CALENDAR), &prop) == napi_ok) {
60         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_CALENDAR", prop);
61     }
62 
63     napi_value objButtonType = nullptr;
64     napi_create_object(env, &objButtonType);
65     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::CLOSE), &prop) == napi_ok) {
66         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_CLOSE", prop);
67     }
68     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::SNOOZE), &prop) == napi_ok) {
69         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_SNOOZE", prop);
70     }
71     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::CUSTOM), &prop) == napi_ok) {
72         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_CUSTOM", prop);
73     }
74 
75     napi_value objRingChannel = nullptr;
76     napi_create_object(env, &objRingChannel);
77     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::RingChannel::MEDIA), &prop) == napi_ok) {
78         napi_set_named_property(env, objRingChannel, "RING_CHANNEL_MEDIA", prop);
79     }
80     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::RingChannel::ALARM), &prop) == napi_ok) {
81         napi_set_named_property(env, objRingChannel, "RING_CHANNEL_ALARM", prop);
82     }
83 
84     napi_property_descriptor exportFuncs[] = {
85         DECLARE_NAPI_PROPERTY("ReminderType", objReminderType),
86         DECLARE_NAPI_PROPERTY("ActionButtonType", objButtonType),
87         DECLARE_NAPI_PROPERTY("RingChannel", objRingChannel),
88     };
89 
90     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
91     return exports;
92 };
93 EXTERN_C_END
94 
95 /*
96  * Module define
97  */
98 static napi_module _apiModule = {
99     .nm_version = 1,
100     .nm_flags = 0,
101     .nm_filename = nullptr,
102     .nm_register_func = ManagerInit,
103     .nm_modname = "reminderAgentManager",
104     .nm_priv = ((void *)0),
105     .reserved = {0},
106 };
107 
108 /*
109  * function for module exports
110  */
ManagerInit(napi_env env,napi_value exports)111 static napi_value ManagerInit(napi_env env, napi_value exports)
112 {
113     ReminderAgentManagerInit(env, exports);
114     ConstantInit(env, exports);
115     return exports;
116 }
117 
118 /*
119  * Module register function
120  */
RegisterModule(void)121 extern "C" __attribute__((constructor)) void RegisterModule(void)
122 {
123     napi_module_register(&_apiModule);
124 }
125 }  // namespace ReminderAgentNapi
126 }  // namespace OHOS