• 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("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     };
41     NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
42     return exports;
43 }
44 
ConstantInit(napi_env env,napi_value exports)45 napi_value ConstantInit(napi_env env, napi_value exports)
46 {
47     ANSR_LOGI("ConstantInit start");
48     napi_value objReminderType = nullptr;
49     napi_create_object(env, &objReminderType);
50 
51     napi_value prop = nullptr;
52     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::TIMER), &prop) == napi_ok) {
53         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_TIMER", prop);
54     }
55     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::ALARM), &prop) == napi_ok) {
56         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_ALARM", prop);
57     }
58     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ReminderType::CALENDAR), &prop) == napi_ok) {
59         napi_set_named_property(env, objReminderType, "REMINDER_TYPE_CALENDAR", prop);
60     }
61 
62     napi_value objButtonType = nullptr;
63     napi_create_object(env, &objButtonType);
64     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::CLOSE), &prop) == napi_ok) {
65         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_CLOSE", prop);
66     }
67     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::SNOOZE), &prop) == napi_ok) {
68         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_SNOOZE", prop);
69     }
70     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::CUSTOM), &prop) == napi_ok) {
71         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_CUSTOM", prop);
72     }
73 
74     napi_property_descriptor exportFuncs[] = {
75         DECLARE_NAPI_PROPERTY("ReminderType", objReminderType),
76         DECLARE_NAPI_PROPERTY("ActionButtonType", objButtonType),
77     };
78 
79     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
80     return exports;
81 };
82 EXTERN_C_END
83 
84 /*
85  * Module define
86  */
87 static napi_module _apiModule = {
88     .nm_version = 1,
89     .nm_flags = 0,
90     .nm_filename = nullptr,
91     .nm_register_func = ManagerInit,
92     .nm_modname = "reminderAgentManager",
93     .nm_priv = ((void *)0),
94     .reserved = {0},
95 };
96 
97 /*
98  * function for module exports
99  */
ManagerInit(napi_env env,napi_value exports)100 static napi_value ManagerInit(napi_env env, napi_value exports)
101 {
102     ReminderAgentManagerInit(env, exports);
103     ConstantInit(env, exports);
104     return exports;
105 }
106 
107 /*
108  * Module register function
109  */
RegisterModule(void)110 extern "C" __attribute__((constructor)) void RegisterModule(void)
111 {
112     napi_module_register(&_apiModule);
113 }
114 }  // namespace ReminderAgentNapi
115 }  // namespace OHOS