• 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     if (napi_create_int32(env, static_cast<int32_t>(ReminderRequest::ActionButtonType::CUSTOM), &prop) == napi_ok) {
67         napi_set_named_property(env, objButtonType, "ACTION_BUTTON_TYPE_CUSTOM", prop);
68     }
69 
70     napi_property_descriptor exportFuncs[] = {
71         DECLARE_NAPI_PROPERTY("ReminderType", objReminderType),
72         DECLARE_NAPI_PROPERTY("ActionButtonType", objButtonType),
73     };
74 
75     napi_define_properties(env, exports, sizeof(exportFuncs) / sizeof(*exportFuncs), exportFuncs);
76     return exports;
77 };
78 EXTERN_C_END
79 
80 /*
81  * Module define
82  */
83 static napi_module _apiModule = {
84     .nm_version = 1,
85     .nm_flags = 0,
86     .nm_filename = nullptr,
87     .nm_register_func = ManagerInit,
88     .nm_modname = "reminderAgentManager",
89     .nm_priv = ((void *)0),
90     .reserved = {0},
91 };
92 
93 /*
94  * function for module exports
95  */
ManagerInit(napi_env env,napi_value exports)96 static napi_value ManagerInit(napi_env env, napi_value exports)
97 {
98     ReminderAgentManagerInit(env, exports);
99     ConstantInit(env, exports);
100     return exports;
101 }
102 
103 /*
104  * Module register function
105  */
RegisterModule(void)106 extern "C" __attribute__((constructor)) void RegisterModule(void)
107 {
108     napi_module_register(&_apiModule);
109 }
110 }  // namespace ReminderAgentNapi
111 }  // namespace OHOS