fixed get next duetime bug
[framework/appfw/alarm-manager.git] / alarm-lib.c
1 /*
2  *  alarm-manager
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: Venkatesha Sarpangala <sarpangala.v@samsung.com>, Jayoun Lee <airjany@samsung.com>,
7  * Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  */
22
23
24
25
26 #include<stdio.h>
27 #include<stdlib.h>
28 #include<errno.h>
29 #include <unistd.h>
30 #include <sys/stat.h>
31 #include<sys/types.h>
32 #include<string.h>
33 #include<dbus/dbus.h>
34 #include<dbus/dbus-glib.h>
35 #include<glib.h>
36 #include <fcntl.h>
37 #include <dbus/dbus-glib-lowlevel.h>
38
39 #include "alarm.h"
40 #include "alarm-internal.h"
41 #include "alarm-stub.h"
42 #include <bundle.h>
43 #include <appsvc.h>
44 #include <aul.h>
45
46 #define MAX_KEY_SIZE 256
47
48 static alarm_context_t alarm_context = { NULL, NULL, NULL, NULL, -1 };
49
50 static bool b_initialized = false;
51 static bool sub_initialized = false;
52
53 #define MAX_OBJECT_PATH_LEN 256
54 #define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
55
56 static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection,
57                                                DBusMessage *message,
58                                                void *user_data);
59 static int __alarm_validate_date(alarm_date_t *date, int *error_code);
60 static bool __alarm_validate_time(alarm_date_t *date, int *error_code);
61 static int __sub_init(void);
62 static int __alarmmgr_init_appsvc(void);
63 bool alarm_power_off(int *error_code);
64 int alarmmgr_check_next_duetime(void);
65
66 typedef struct _alarm_cb_info_t {
67         int alarm_id;
68         alarm_cb_t cb_func;
69         void *priv_data;
70         struct _alarm_cb_info_t *next;
71 } alarm_cb_info_t;
72
73 static alarm_cb_info_t *alarmcb_head = NULL;
74
75 static void __add_resultcb(int alarm_id, alarm_cb_t cb_func,
76                          void *data)
77 {
78         alarm_cb_info_t *info;
79
80         info = (alarm_cb_info_t *) malloc(sizeof(alarm_cb_info_t));
81         if(info == NULL)
82                 return;
83         info->alarm_id = alarm_id;
84         info->cb_func = cb_func;
85         info->priv_data = data;
86
87         info->next = alarmcb_head;
88         alarmcb_head = info;
89 }
90
91 static alarm_cb_info_t *__find_resultcb(int alarm_id)
92 {
93         alarm_cb_info_t *tmp;
94
95         tmp = alarmcb_head;
96         while (tmp) {
97                 if (tmp->alarm_id == alarm_id)
98                         return tmp;
99                 tmp = tmp->next;
100         }
101         return NULL;
102 }
103
104 static void __remove_resultcb(alarm_cb_info_t *info)
105 {
106         alarm_cb_info_t *tmp;
107
108         if (alarmcb_head == NULL || info == NULL)
109                 return;
110
111         if (alarmcb_head == info) {
112                 alarmcb_head = info->next;
113                 free(info);
114                 return;
115         }
116
117         tmp = alarmcb_head;
118         while (tmp) {
119                 if (tmp->next == info) {
120                         tmp->next = info->next;
121                         free(info);
122                         return;
123                 }
124                 tmp = tmp->next;
125         }
126 }
127
128 static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection,
129                                                DBusMessage *message,
130                                                void *user_data)
131 {
132         alarm_cb_info_t *info;
133
134         if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL) {
135                 const char *method_name = dbus_message_get_member(message);
136                 /*"alarm_expired" */
137
138                 if (strcmp(method_name, "alarm_expired") == 0) {
139                         DBusMessageIter iter;
140                         alarm_id_t alarm_id;
141                         const char *service_name =
142                             dbus_message_get_destination(message);
143                         const char *object_path =
144                             dbus_message_get_path(message);
145                         /* "/org/tizen/alarm/client" */
146                         const char *interface_name =
147                             dbus_message_get_interface(message);
148                         /* "org.tizen.alarm.client" */
149
150                         dbus_message_iter_init(message, &iter);
151                         dbus_message_iter_get_basic(&iter, &alarm_id);
152
153                         ALARM_MGR_LOG_PRINT("[alarm-lib]:service_name=%s, "
154                         "object_path=%s, interface_name=%s, method_name=%s, "
155                         "alarm_id=%d, handler=%s\n",
156                         service_name ? service_name : "no name",
157                         object_path ? object_path : "no path",
158                         interface_name ? interface_name : "no interface",
159                         method_name ? method_name : "no method", alarm_id,
160                         alarm_context.alarm_handler ? "ok" : "no handler");
161
162                         if (alarm_context.alarm_handler != NULL)
163                                 /* alarm_context.alarm_handler(alarm_id); */
164                                 alarm_context.alarm_handler(alarm_id,
165                                         alarm_context.user_param);
166                         info = __find_resultcb(alarm_id);
167
168                         if( info && info->cb_func ) {
169                                 info->cb_func(alarm_id, info->priv_data);
170                         //      __remove_resultcb(info);
171                         }
172
173                         return DBUS_HANDLER_RESULT_HANDLED;
174                 }
175         }
176
177         return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
178 }
179
180 static int __alarm_validate_date(alarm_date_t *date, int *error_code)
181 {
182
183         if (date->year == 0 && date->month == 0 && date->day == 0) {
184                 return true;
185         }
186
187         int year = date->year;
188         int month = date->month;
189         int day = date->day;
190
191         if (month < 1 || month > 12) {
192                 if (error_code)
193                         *error_code = ERR_ALARM_INVALID_DATE;
194                 return false;
195         }
196
197         if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8
198              || month == 10 || month == 12)
199             && (day < 1 || day > 31)) {
200                 if (error_code)
201                         *error_code = ERR_ALARM_INVALID_DATE;
202                 return false;
203         }
204
205         if ((month == 4 || month == 6 || month == 9 || month == 11)
206             && (day < 1 || day > 30)) {
207                 if (error_code)
208                         *error_code = ERR_ALARM_INVALID_DATE;
209                 return false;
210         }
211
212         if (month == 2) {
213                 if ((year % 100 != 0 && year % 4 == 0) || (year % 400 == 0)) {
214                         if (day < 1 || day > 29) {
215                                 if (error_code)
216                                         *error_code = ERR_ALARM_INVALID_DATE;
217                                 return false;
218                         }
219                 } else {
220                         if (day < 1 || day > 28) {
221                                 if (error_code)
222                                         *error_code = ERR_ALARM_INVALID_DATE;
223                                 return false;
224                         }
225                 }
226
227         }
228
229         return true;
230
231 }
232
233 static bool __alarm_validate_time(alarm_date_t *date, int *error_code)
234 {
235         if (date->hour < 0 || date->hour > 23) {
236                 if (error_code)
237                         *error_code = ERR_ALARM_INVALID_TIME;
238                 return false;
239         }
240
241         if (date->min < 0 || date->min > 59) {
242                 if (error_code)
243                         *error_code = ERR_ALARM_INVALID_TIME;
244                 return false;
245         }
246
247         return true;
248 }
249
250 static int __sub_init()
251 {
252         GError *error = NULL;
253
254         if (sub_initialized) {
255                 //ALARM_MGR_LOG_PRINT("__sub_init was already called.\n");
256                 return ALARMMGR_RESULT_SUCCESS;
257         }
258
259         g_thread_init(NULL);
260         dbus_g_thread_init();
261
262         alarm_context.bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
263         if (alarm_context.bus == NULL) {
264                 ALARM_MGR_EXCEPTION_PRINT("dbus bus get failed\n");
265
266                 return ERR_ALARM_SYSTEM_FAIL;
267         }
268
269         alarm_context.proxy = dbus_g_proxy_new_for_name(alarm_context.bus,
270                                                         "org.tizen.alarm.manager",
271                                                         "/org/tizen/alarm/manager",
272                                                         "org.tizen.alarm.manager");
273         if (alarm_context.proxy == NULL) {
274                 ALARM_MGR_EXCEPTION_PRINT("dbus bus proxy get failed\n");
275
276                 return ERR_ALARM_SYSTEM_FAIL;
277         }
278
279         alarm_context.pid = getpid();   /*this running appliction's process id*/
280
281         sub_initialized = true;
282
283         return ALARMMGR_RESULT_SUCCESS;
284 }
285
286 bool alarm_power_off(int *error_code)
287 {
288         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_off() is called\n");
289
290 #ifdef __ALARM_BOOT
291         return _send_alarm_power_off(alarm_context, error_code);
292 #else
293         ALARM_MGR_LOG_PRINT(
294                         "[alarm-lib]:ALARM_BOOT feature is not supported. "
295                             "so we return false.\n");
296         if (error_code)
297                 *error_code = -1;       /*-1 means that system failed
298                                                         internally.*/
299         return false;
300 #endif
301 }
302
303 int alarmmgr_check_next_duetime()
304 {
305         int error_code;
306         ALARM_MGR_LOG_PRINT(
307             "[alarm-lib]:alarm_check_next_duetime() is called\n");
308
309 #ifdef __ALARM_BOOT
310         if (!_send_alarm_check_next_duetime(alarm_context, &error_code))
311                 return error_code;
312 #else
313         ALARM_MGR_LOG_PRINT(
314                     "[alarm-lib]:ALARM_BOOT feature is not supported. "
315                             "so we return false.\n");
316         return ERR_ALARM_SYSTEM_FAIL;
317 #endif
318
319         return ALARMMGR_RESULT_SUCCESS;
320 }
321
322 EXPORT_API int alarmmgr_init(const char *appid)
323 {
324         DBusError derror;
325         int request_name_result = 0;
326         char service_name[MAX_SERVICE_NAME_LEN] = { 0 };
327         char service_name_mod[MAX_SERVICE_NAME_LEN]= { 0 };
328
329         int ret;
330         int i = 0;
331         int j = 0;
332         int len = 0;
333
334         if (appid == NULL)
335                 return ERR_ALARM_INVALID_PARAM;
336
337         if (strlen(appid) >= MAX_PKG_NAME_LEN)
338                 return ERR_ALARM_INVALID_PARAM;
339
340         if (b_initialized) {
341                 ALARM_MGR_EXCEPTION_PRINT(
342                      "alarm was already initialized. app_service_name=%s\n",
343                      g_quark_to_string(alarm_context.quark_app_service_name));
344                 return ALARMMGR_RESULT_SUCCESS;
345         }
346
347         ret = __sub_init();
348         if (ret < 0)
349                 return ret;
350
351         memset(service_name_mod, 'a', MAX_SERVICE_NAME_LEN-1);
352
353         len = strlen("ALARM.");
354         strncpy(service_name, "ALARM.", len);
355         strncpy(service_name + len, appid, strlen(appid));
356
357         j=0;
358
359         for(i=0;i<=strlen(service_name);i++)
360         {
361                 if (service_name[i] == '.' )
362                 {
363                         service_name_mod[j] = service_name[i];
364                         j++;
365                 }
366                 else{
367                         service_name_mod[j] = service_name[i];
368                 }
369                 j++;
370         }
371
372         ALARM_MGR_LOG_PRINT("[alarm-lib]: service_name %s\n", service_name);
373         ALARM_MGR_LOG_PRINT("[alarm-lib]: service_name_mod %s\n", service_name_mod);
374
375         dbus_error_init(&derror);
376
377         request_name_result = dbus_bus_request_name(
378                           dbus_g_connection_get_connection(alarm_context.bus),
379                           service_name_mod, 0, &derror);
380         if (dbus_error_is_set(&derror)) /*failure*/ {
381                 ALARM_MGR_EXCEPTION_PRINT(
382                      "Failed to dbus_bus_request_name(%s): %s\n", service_name,
383                      derror.message);
384                 dbus_error_free(&derror);
385
386                 return ERR_ALARM_SYSTEM_FAIL;
387         }
388         alarm_context.quark_app_service_name =
389             g_quark_from_string(service_name);
390         alarm_context.quark_app_service_name_mod=
391             g_quark_from_string(service_name_mod);
392
393
394         if (!dbus_connection_add_filter(
395              dbus_g_connection_get_connection(alarm_context.bus),
396              __expire_alarm_filter, NULL, NULL)) {
397                 ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
398
399                 return ERR_ALARM_SYSTEM_FAIL;
400         }
401
402         b_initialized = true;
403         return ALARMMGR_RESULT_SUCCESS;
404
405 }
406
407 EXPORT_API void alarmmgr_fini()
408 {
409         dbus_connection_remove_filter(dbus_g_connection_get_connection
410                                       (alarm_context.bus),
411                                       __expire_alarm_filter, NULL);
412 }
413
414 EXPORT_API int alarmmgr_set_cb(alarm_cb_t handler, void *user_param)
415 {
416         ALARM_MGR_LOG_PRINT("alarm_set_cb is called\n");
417
418         if (handler == NULL) {
419                 return ERR_ALARM_INVALID_PARAM;
420         }
421         alarm_context.alarm_handler = handler;
422         alarm_context.user_param = user_param;
423         return ALARMMGR_RESULT_SUCCESS;
424 }
425
426 EXPORT_API alarm_entry_t *alarmmgr_create_alarm(void)
427 {
428         alarm_info_t *alarm = (alarm_info_t *) malloc(sizeof(alarm_info_t));
429
430         if (NULL == alarm)
431         {
432                 return NULL;
433         }
434
435         alarm->start.year = 0;
436         alarm->start.month = 0;
437         alarm->start.day = 0;
438         alarm->start.hour = 0;
439         alarm->start.min = 0;
440         alarm->start.sec = 0;
441
442         alarm->end.year = 0;
443         alarm->end.month = 0;
444         alarm->end.day = 0;
445         alarm->end.hour = 0;
446         alarm->end.min = 0;
447         alarm->end.sec = 0;
448
449         alarm->mode.repeat = ALARM_REPEAT_MODE_ONCE;
450         alarm->mode.u_interval.interval = 0;
451
452         alarm->alarm_type = ALARM_TYPE_DEFAULT;
453
454         alarm->reserved_info = 0;
455
456         return (alarm_entry_t *) alarm;
457 }
458
459 EXPORT_API int alarmmgr_free_alarm(alarm_entry_t *alarm)
460 {
461         if (alarm == NULL) {
462                 return ERR_ALARM_INVALID_PARAM;
463         }
464         free(alarm);
465
466         return ALARMMGR_RESULT_SUCCESS;
467 }
468
469 EXPORT_API int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time)
470 {
471         alarm_info_t *alarm_info;       /*= (alarm_info_t*)alarm;*/
472         int error_code;
473
474         if (alarm == NULL) {
475                 return ERR_ALARM_INVALID_PARAM;
476         }
477
478         alarm_info = (alarm_info_t *) alarm;
479
480         if (!__alarm_validate_date(&time, &error_code)) {
481                 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
482                 return error_code;
483         }
484
485         if (!__alarm_validate_time(&time, &error_code)) {
486                 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
487                 return error_code;
488         }
489
490         memcpy(&alarm_info->start, &time, sizeof(alarm_date_t));
491
492         return ALARMMGR_RESULT_SUCCESS;
493 }
494
495 EXPORT_API int alarmmgr_get_time(const alarm_entry_t *alarm,
496                                  alarm_date_t *time)
497 {
498         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
499
500         if (alarm == NULL) {
501                 return ERR_ALARM_INVALID_PARAM;
502         }
503
504         if (time != NULL)
505                 memcpy(time, &alarm_info->start, sizeof(alarm_date_t));
506
507         return ALARMMGR_RESULT_SUCCESS;
508 }
509
510 EXPORT_API int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
511                                         alarm_repeat_mode_t repeat,
512                                         int interval)
513 {
514         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
515
516         if (repeat >= ALARM_REPEAT_MODE_MAX) {
517                 return ERR_ALARM_INVALID_PARAM;
518         }
519
520         alarm_info->mode.repeat = repeat;
521
522         if (repeat == ALARM_REPEAT_MODE_REPEAT
523             || repeat == ALARM_REPEAT_MODE_WEEKLY) {
524                 alarm_info->mode.u_interval.interval = interval;
525         }
526
527         return ALARMMGR_RESULT_SUCCESS;
528 }
529
530 EXPORT_API int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
531                                         alarm_repeat_mode_t *repeat,
532                                         int *interval)
533 {
534         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
535
536         if (alarm == NULL) {
537                 return ERR_ALARM_INVALID_PARAM;
538         }
539
540         if (repeat != NULL)
541                 *repeat = alarm_info->mode.repeat;
542         if (interval != NULL)
543                 *interval = alarm_info->mode.u_interval.interval;
544
545         return ALARMMGR_RESULT_SUCCESS;
546 }
547
548 EXPORT_API int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type)
549 {
550         alarm_info_t *alarm_info;       /*= (alarm_info_t*)alarm;*/
551
552         if (alarm == NULL) {
553                 return ERR_ALARM_INVALID_PARAM;
554         }
555
556         alarm_info = (alarm_info_t *) alarm;
557
558         alarm_info->alarm_type = alarm_type;
559         alarm_info->alarm_type &= (~ALARM_TYPE_RELATIVE);
560
561         return ALARMMGR_RESULT_SUCCESS;
562 }
563
564 EXPORT_API int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type)
565 {
566         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
567
568         if (alarm == NULL) {
569                 return ERR_ALARM_INVALID_PARAM;
570         }
571
572         if (alarm_type != NULL)
573                 *alarm_type = alarm_info->alarm_type;
574
575         return ALARMMGR_RESULT_SUCCESS;
576 }
577
578
579 static int __alarmmgr_init_appsvc(void)
580 {
581         int ret;
582
583         if (b_initialized) {
584                 ALARM_MGR_EXCEPTION_PRINT("alarm was already initialized\n");
585                 return ALARMMGR_RESULT_SUCCESS;
586         }
587
588         g_thread_init(NULL);
589
590         dbus_g_thread_init();
591
592         ret = __sub_init();
593         if (ret < 0)
594                 return ret;
595
596         b_initialized = true;
597
598         return ALARMMGR_RESULT_SUCCESS;
599
600 }
601
602 EXPORT_API void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code){
603
604         int ret = 0;
605
606         ret = __sub_init();
607         if (ret < 0){
608                 if (return_code)
609                         *return_code = ret;
610                 return NULL;
611         }
612
613         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_alarm_appsvc_info() is called\n");
614
615         if (alarm_id <= 0) {
616                 if (return_code)
617                         *return_code = ERR_ALARM_INVALID_ID;
618                 return NULL;
619         }
620
621         return _send_alarm_get_appsvc_info(alarm_context, alarm_id, return_code);
622
623 }
624
625 EXPORT_API int alarmmgr_set_rtc_time(alarm_date_t *time){
626
627         int ret = 0;
628         int error_code = 0;
629
630         if (!time){
631                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter time\n");
632                 return ERR_ALARM_INVALID_PARAM;
633         }
634
635         ret = __sub_init();
636         if (ret < 0){
637                 return ret;
638         }
639
640         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_rtc_time() is called\n");
641
642         if (!__alarm_validate_date(time, &error_code)) {
643                 ALARM_MGR_EXCEPTION_PRINT("RTC date error\n");
644                 return error_code;
645         }
646
647         if (!__alarm_validate_time(time, &error_code)) {
648                 ALARM_MGR_EXCEPTION_PRINT("RTC time error\n");
649                 return error_code;
650         }
651
652         time->year-=1900;
653         time->month-=1;
654
655         if (!_send_alarm_set_rtc_time
656                 (alarm_context, time, &error_code)){
657                         return error_code;
658         }
659
660         return ALARMMGR_RESULT_SUCCESS;
661
662 }
663
664 EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, void *bundle_data, alarm_id_t *alarm_id)
665 {
666         alarm_info_t *alarm_info = NULL;        /* = (alarm_info_t*)alarm; */
667         const char *operation = NULL;
668         int error_code = 0;
669         char *appid = NULL;
670
671         bundle *b=(bundle *)bundle_data;
672
673         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
674
675         if (alarm == NULL) {
676                 return ERR_ALARM_INVALID_PARAM;
677         }
678
679         if (NULL == b)
680         {
681                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle\n");
682                 return ERR_ALARM_INVALID_PARAM;
683         }
684         operation = appsvc_get_operation(b);
685
686         if (NULL == operation)
687         {
688                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle [appsvc operation not present]\n");
689                 return ERR_ALARM_INVALID_PARAM;
690         }
691
692         if (__alarmmgr_init_appsvc() < 0)
693         {
694                 ALARM_MGR_EXCEPTION_PRINT("Unable to initialize dbus!!!\n");
695                 return ERR_ALARM_SYSTEM_FAIL;
696         }
697
698         alarm_info = (alarm_info_t *) alarm;
699
700         appid = appsvc_get_appid(b);
701
702         if (NULL == appid && (alarm_info->alarm_type & ALARM_TYPE_NOLAUNCH) )
703         {
704                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
705                 return ERR_ALARM_INVALID_PARAM;
706         }
707
708         if (alarm_info == NULL || alarm_id == NULL) {
709                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
710                 return ERR_ALARM_INVALID_PARAM;
711         }
712         alarm_mode_t *mode = &alarm_info->mode;
713
714         ALARM_MGR_LOG_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
715                 alarm_info->start.day, alarm_info->start.month, alarm_info->start.year,
716                 alarm_info->start.hour, alarm_info->start.min, alarm_info->start.sec,
717                 alarm_info->end.year, alarm_info->end.month, alarm_info->end.day,
718                 alarm_info->mode.repeat, alarm_info->mode.u_interval, alarm_info->alarm_type);
719
720         /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
721         if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
722                 return ERR_ALARM_INVALID_PARAM;
723         }
724
725         if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
726                 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
727                 return error_code;
728         }
729
730         if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
731                 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
732                 return error_code;
733         }
734
735         if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
736                 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
737                 return error_code;
738         }
739
740
741         if (!_send_alarm_create_appsvc
742             (alarm_context, alarm_info, alarm_id, b,
743              &error_code)) {
744                 return error_code;
745         }
746
747         return ALARMMGR_RESULT_SUCCESS;
748 }
749
750
751
752
753 EXPORT_API int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
754                                                  const char *destination,
755                                                  alarm_id_t *alarm_id)
756 {
757         char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
758         char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
759         alarm_info_t *alarm_info;       /* = (alarm_info_t*)alarm; */
760         int ret;
761         int i = 0;
762         int j = 0;
763
764         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
765
766         if (alarm == NULL) {
767                 return ERR_ALARM_INVALID_PARAM;
768         }
769
770         alarm_info = (alarm_info_t *) alarm;
771         if (alarm_info == NULL || alarm_id == NULL) {
772                 return ERR_ALARM_INVALID_PARAM;
773         }
774
775         int error_code;
776         alarm_mode_t *mode = &alarm_info->mode;
777
778         ret = __sub_init();
779         if (ret < 0)
780                 return ret;
781
782         ALARM_MGR_LOG_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
783                 alarm_info->start.day, alarm_info->start.month, alarm_info->start.year,
784                 alarm_info->start.hour, alarm_info->start.min, alarm_info->start.sec,
785                 alarm_info->end.year, alarm_info->end.month, alarm_info->end.day,
786                 alarm_info->mode.repeat, alarm_info->mode.u_interval, alarm_info->alarm_type);
787
788         /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
789         if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
790                 return ERR_ALARM_INVALID_PARAM;
791         }
792
793         if (destination && strlen(destination) >= MAX_PKG_NAME_LEN){
794                 ALARM_MGR_EXCEPTION_PRINT("[alarm-lib]: destination name is too long!\n");
795                 return ERR_ALARM_INVALID_PARAM;
796         }
797
798
799         if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
800                 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
801                 return error_code;
802         }
803
804         if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
805                 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
806                 return error_code;
807         }
808
809         if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
810                 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
811                 return error_code;
812         }
813
814         if (destination != NULL) {
815                 memset(dst_service_name, 0,
816                        strlen(destination) + strlen("ALARM.") + 2);
817                 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "ALARM.%s",
818                          destination);
819
820                 memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
821
822                 j=0;
823
824                 for(i=0; i<=strlen(dst_service_name); i++)
825                 {
826                         if (dst_service_name[i] == '.' )
827                         {
828                                 dst_service_name_mod[j] = dst_service_name[i];
829                                 j++;
830                         }
831                         else
832                         {
833                                 dst_service_name_mod[j] = dst_service_name[i];
834                         }
835                         j++;
836                 }
837
838                 if (!_send_alarm_create
839                     (alarm_context, alarm_info, alarm_id, dst_service_name, dst_service_name_mod,
840                      &error_code)) {
841                         return error_code;
842                 }
843         } else
844             if (!_send_alarm_create
845                 (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
846                 return error_code;
847         }
848
849         return ALARMMGR_RESULT_SUCCESS;
850 }
851
852
853
854 EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
855                                   time_t interval, void *bundle_data,
856                                   alarm_id_t *alarm_id)
857 {
858         int error_code = 0;;
859         time_t current_time;
860         struct tm duetime_tm;
861         alarm_info_t alarm_info;
862         const char *operation = NULL;
863         char *appid = NULL;
864
865         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
866
867         bundle *b=(bundle *)bundle_data;
868
869         if (NULL == b)
870         {
871                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle\n");
872                 return ERR_ALARM_INVALID_PARAM;
873         }
874         operation = appsvc_get_operation(b);
875
876         if (NULL == operation)
877         {
878                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle [appsvc operation not present]\n");
879                 return ERR_ALARM_INVALID_PARAM;
880         }
881
882         appid = appsvc_get_appid(b);
883
884         if (NULL == appid && (alarm_type & ALARM_TYPE_NOLAUNCH) )
885         {
886                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
887                 return ERR_ALARM_INVALID_PARAM;
888         }
889
890         if (__alarmmgr_init_appsvc() < 0)
891         {
892                 ALARM_MGR_EXCEPTION_PRINT("Unable to initialize dbus!!!\n");
893                 return ERR_ALARM_SYSTEM_FAIL;
894         }
895
896         if (alarm_id == NULL) {
897                 return ERR_ALARM_INVALID_PARAM;
898         }
899
900         if (trigger_at_time < 0) {
901                 return ERR_ALARM_INVALID_PARAM;
902         }
903
904         alarm_info.alarm_type = alarm_type;
905         alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
906
907         time(&current_time);
908
909         current_time += trigger_at_time;
910
911         localtime_r(&current_time, &duetime_tm);
912
913         alarm_info.start.year = duetime_tm.tm_year + 1900;
914         alarm_info.start.month = duetime_tm.tm_mon + 1;
915         alarm_info.start.day = duetime_tm.tm_mday;
916
917         alarm_info.end.year = 0;
918         alarm_info.end.month = 0;
919         alarm_info.end.day = 0;
920
921         alarm_info.start.hour = duetime_tm.tm_hour;
922         alarm_info.start.min = duetime_tm.tm_min;
923         alarm_info.start.sec = duetime_tm.tm_sec;
924
925         if (interval <= 0) {
926                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
927                 alarm_info.mode.u_interval.interval = 0;
928         } else {
929                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
930                 alarm_info.mode.u_interval.interval = interval;
931         }
932
933         ALARM_MGR_LOG_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
934                 trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
935                 alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
936                 alarm_info.mode.repeat, alarm_info.mode.u_interval, alarm_info.alarm_type);
937
938         if (!_send_alarm_create_appsvc
939             (alarm_context, &alarm_info, alarm_id, b,
940              &error_code)) {
941                 return error_code;
942         }
943
944         return ALARMMGR_RESULT_SUCCESS;
945 }
946
947
948 EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
949                                   time_t interval, const char *destination,
950                                   alarm_id_t *alarm_id)
951 {
952         char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
953         char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
954         int i = 0;
955         int j = 0;
956         int error_code;
957         time_t current_time;
958         struct tm duetime_tm;
959         alarm_info_t alarm_info;
960         int ret;
961
962         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
963
964         ret = __sub_init();
965         if (ret < 0)
966                 return ret;
967
968         if (alarm_id == NULL) {
969                 return ERR_ALARM_INVALID_PARAM;
970         }
971
972         if (trigger_at_time < 0) {
973                 return ERR_ALARM_INVALID_PARAM;
974         }
975
976         if (destination && strlen(destination) >= MAX_PKG_NAME_LEN){
977                 ALARM_MGR_EXCEPTION_PRINT("[alarm-lib]: destination name is too long!\n");
978                 return ERR_ALARM_INVALID_PARAM;
979         }
980
981         alarm_info.alarm_type = alarm_type;
982         alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
983
984         time(&current_time);
985
986         current_time += trigger_at_time;
987
988         localtime_r(&current_time, &duetime_tm);
989
990         alarm_info.start.year = duetime_tm.tm_year + 1900;
991         alarm_info.start.month = duetime_tm.tm_mon + 1;
992         alarm_info.start.day = duetime_tm.tm_mday;
993
994         alarm_info.end.year = 0;
995         alarm_info.end.month = 0;
996         alarm_info.end.day = 0;
997
998         alarm_info.start.hour = duetime_tm.tm_hour;
999         alarm_info.start.min = duetime_tm.tm_min;
1000         alarm_info.start.sec = duetime_tm.tm_sec;
1001
1002         if (interval <= 0) {
1003                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
1004                 alarm_info.mode.u_interval.interval = 0;
1005         } else {
1006                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
1007                 alarm_info.mode.u_interval.interval = interval;
1008         }
1009
1010         ALARM_MGR_LOG_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
1011                 trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
1012                 alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
1013                 alarm_info.mode.repeat, alarm_info.mode.u_interval, alarm_info.alarm_type);
1014
1015         if (destination != NULL) {
1016                 memset(dst_service_name, 0,
1017                        strlen(destination) + strlen("ALARM.") + 2);
1018                 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "ALARM.%s",
1019                          destination);
1020                 memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
1021
1022                 j=0;
1023
1024                 for(i=0;i<=strlen(dst_service_name);i++)
1025                 {
1026                         if (dst_service_name[i] == '.')
1027                         {
1028                                 dst_service_name_mod[j]=dst_service_name[i];
1029                                 j++;
1030                         }
1031                         else
1032                         {
1033                                 dst_service_name_mod[j]=dst_service_name[i];
1034                         }
1035                         j++;
1036                 }
1037
1038                 if (!_send_alarm_create
1039                     (alarm_context, &alarm_info, alarm_id, dst_service_name,dst_service_name_mod,
1040                      &error_code)) {
1041                         return error_code;
1042                 }
1043         } else
1044             if (!_send_alarm_create
1045                 (alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) {
1046                 return error_code;
1047         }
1048
1049         return ALARMMGR_RESULT_SUCCESS;
1050 }
1051
1052 EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
1053                                   time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id)
1054 {
1055         char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
1056         char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
1057         int i = 0;
1058         int j = 0;
1059         int error_code;
1060         time_t current_time;
1061         struct tm duetime_tm;
1062         alarm_info_t alarm_info;
1063         int ret;
1064         char appid[256];
1065
1066         aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
1067
1068         ret = alarmmgr_init(appid);
1069         if (ret < 0)
1070                 return ret;
1071
1072         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_add_alarm_withcb() is called\n");
1073
1074         ALARM_MGR_LOG_PRINT("interval(%d)", interval);
1075
1076         if (alarm_id == NULL) {
1077                 return ERR_ALARM_INVALID_PARAM;
1078         }
1079
1080         if (trigger_at_time < 0) {
1081                 return ERR_ALARM_INVALID_PARAM;
1082         }
1083
1084         alarm_info.alarm_type = alarm_type;
1085         alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
1086         alarm_info.alarm_type |= ALARM_TYPE_WITHCB;
1087
1088         time(&current_time);
1089
1090         current_time += trigger_at_time;
1091
1092         localtime_r(&current_time, &duetime_tm);
1093
1094         alarm_info.start.year = duetime_tm.tm_year + 1900;
1095         alarm_info.start.month = duetime_tm.tm_mon + 1;
1096         alarm_info.start.day = duetime_tm.tm_mday;
1097
1098         alarm_info.end.year = 0;
1099         alarm_info.end.month = 0;
1100         alarm_info.end.day = 0;
1101
1102         alarm_info.start.hour = duetime_tm.tm_hour;
1103         alarm_info.start.min = duetime_tm.tm_min;
1104         alarm_info.start.sec = duetime_tm.tm_sec;
1105
1106         if (interval <= 0) {
1107                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
1108                 alarm_info.mode.u_interval.interval = 0;
1109         } else {
1110                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
1111                 alarm_info.mode.u_interval.interval = interval;
1112         }
1113
1114         if (!_send_alarm_create(alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) {
1115                 return error_code;
1116         }
1117         __add_resultcb(*alarm_id, handler, user_param);
1118
1119         return ALARMMGR_RESULT_SUCCESS;
1120 }
1121
1122 EXPORT_API int alarmmgr_remove_alarm(alarm_id_t alarm_id)
1123 {
1124         int error_code;
1125         int ret;
1126         alarm_cb_info_t *info;
1127
1128         ret = __sub_init();
1129         if (ret < 0)
1130                 return ret;
1131
1132         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_delete(%d) is called\n", alarm_id);
1133
1134         if (alarm_id <= 0) {
1135                 return ERR_ALARM_INVALID_ID;
1136         }
1137
1138         if (!_send_alarm_delete(alarm_context, alarm_id, &error_code))
1139                 return error_code;
1140
1141         info = __find_resultcb(alarm_id);
1142         __remove_resultcb(info);
1143
1144         return ALARMMGR_RESULT_SUCCESS;
1145 }
1146
1147 EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
1148 {
1149         GError *error = NULL;
1150         GArray *alarm_array = NULL;
1151         int return_code = 0;
1152         int i = 0;
1153         int maxnum_of_ids;
1154         int num_of_ids;
1155         int alarm_id = -1;
1156         int ret;
1157
1158         if (fn == NULL)
1159                 return ERR_ALARM_INVALID_PARAM;
1160
1161         ret = __sub_init();
1162         if (ret < 0)
1163                 return ret;
1164
1165         if (!org_tizen_alarm_manager_alarm_get_number_of_ids(
1166             alarm_context.proxy, alarm_context.pid, &maxnum_of_ids,
1167                &return_code, &error)) {
1168                 /* dbus-glib error */
1169                 /* error_code should be set */
1170                 ALARM_MGR_EXCEPTION_PRINT(
1171                     "org_tizen_alarm_manager_alarm_get_number_of_ids() "
1172                     "failed. return_code[%d], return_code[%s]\n",
1173                 return_code, error->message);
1174         }
1175
1176         if (return_code != 0) {
1177                 return return_code;
1178         }
1179
1180         if (!org_tizen_alarm_manager_alarm_get_list_of_ids(
1181                      alarm_context.proxy, alarm_context.pid, maxnum_of_ids,
1182              &alarm_array, &num_of_ids, &return_code, &error)) {
1183                 /*dbus-glib error */
1184                 /* error_code should be set */
1185                 ALARM_MGR_EXCEPTION_PRINT(
1186                     "org_tizen_alarm_manager_alarm_get_list_of_ids() "
1187                     "failed. alarm_id[%d], return_code[%d]\n",
1188                      alarm_id, return_code);
1189         }
1190
1191         if (return_code != 0) {
1192                 return return_code;
1193         } else {
1194                 if (error != NULL) {
1195                         ALARM_MGR_LOG_PRINT(
1196                                 "Alarm server not ready dbus error message %s\n", error->message);
1197                         return ERR_ALARM_SYSTEM_FAIL;
1198                 }
1199                 if (NULL == alarm_array) {
1200                         ALARM_MGR_LOG_PRINT(
1201                                 "alarm server not initilized\n");
1202                         return ERR_ALARM_SYSTEM_FAIL;
1203                 }
1204                 for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
1205                         alarm_id = g_array_index(alarm_array, alarm_id_t, i);
1206                         (*fn) (alarm_id, user_param);
1207                         ALARM_MGR_LOG_PRINT(" alarm_id(%d)\n", alarm_id);
1208                 }
1209
1210                 g_array_free(alarm_array, true);
1211         }
1212
1213         return ALARMMGR_RESULT_SUCCESS;
1214 }
1215
1216 EXPORT_API int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm)
1217 {
1218         int error_code;
1219         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
1220
1221         int ret;
1222
1223         ret = __sub_init();
1224         if (ret < 0)
1225                 return ret;
1226
1227         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_info() is called\n");
1228
1229         if (alarm_id < 0 || alarm_info == NULL) {
1230                 return ERR_ALARM_INVALID_PARAM;
1231         }
1232
1233         if (!_send_alarm_get_info(alarm_context, alarm_id, alarm_info,
1234                                   &error_code))
1235                 return error_code;
1236
1237         return ALARMMGR_RESULT_SUCCESS;
1238 }
1239
1240 EXPORT_API int alarmmgr_power_on(bool on_off)
1241 {
1242         int error_code;
1243         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_on() is called\n");
1244
1245 #ifdef __ALARM_BOOT
1246         if (!_send_alarm_power_on(alarm_context, on_off, &error_code))
1247                 return error_code;
1248 #else
1249         ALARM_MGR_LOG_PRINT("[alarm-lib]:ALARM_BOOT feature is not supported. "
1250                             "so we return false.\n");
1251         return ERR_ALARM_SYSTEM_FAIL;
1252 #endif
1253
1254         return ALARMMGR_RESULT_SUCCESS;
1255 }
1256
1257 int alarmmgr_create(alarm_info_t *alarm_info, char *destination,
1258                     alarm_id_t *alarm_id)
1259 {
1260         char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
1261         alarm_mode_t *mode = &alarm_info->mode;
1262         int error_code;
1263
1264         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
1265
1266         if (alarm_info == NULL || alarm_id == NULL) {
1267                 return ERR_ALARM_INVALID_PARAM;
1268         }
1269
1270         ALARM_MGR_LOG_PRINT("alarm_info->start.year(%d), "
1271                             "alarm_info->start.month(%d), alarm_info->start.day(%d)",
1272                             alarm_info->start.year, alarm_info->start.month,
1273                             alarm_info->start.day);
1274
1275         /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
1276         if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
1277                 return ERR_ALARM_INVALID_PARAM;
1278         }
1279
1280         if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
1281                 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
1282                 return error_code;
1283         }
1284
1285         if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
1286                 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
1287                 return error_code;
1288         }
1289
1290         if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
1291                 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
1292                 return error_code;
1293         }
1294
1295         if (destination != NULL) {
1296                 memset(dst_service_name, 0,
1297                        strlen(destination) + strlen("ALARM.") + 2);
1298                 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "ALARM.%s",
1299                          destination);
1300                 if (!_send_alarm_create
1301                     (alarm_context, alarm_info, alarm_id, dst_service_name,"null",
1302                      &error_code)) {
1303                         return error_code;
1304                 }
1305         }
1306 /*TODO: Currently this API is not exported. Hence not modifying*/
1307         if (!_send_alarm_create
1308             (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
1309                 return error_code;
1310         }
1311
1312         return ALARMMGR_RESULT_SUCCESS;
1313
1314 }
1315
1316 int alarmmgr_get_number_of_ids(int *num_of_ids)
1317 {
1318         int error_code;
1319         ALARM_MGR_LOG_PRINT("[alarm-lib]:"
1320                             "alarm_get_number_of_ids() is called\n");
1321
1322         if (num_of_ids == NULL) {
1323                 return ERR_ALARM_INVALID_PARAM;
1324         }
1325         ALARM_MGR_LOG_PRINT("call alarm_get_number_of_ids\n");
1326         if (!_send_alarm_get_number_of_ids(alarm_context, num_of_ids,
1327                                            &error_code))
1328                 return error_code;
1329
1330         return ALARMMGR_RESULT_SUCCESS;
1331 }
1332
1333 int alarmmgr_get_list_of_ids(int maxnum_of_ids, alarm_id_t *alarm_id,
1334                              int *num_of_ids)
1335 {
1336         int error_code;
1337         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_list_of_ids() is called\n");
1338
1339         if (maxnum_of_ids < 0 || alarm_id == NULL || num_of_ids == NULL) {
1340                 return ERR_ALARM_INVALID_PARAM;
1341         }
1342
1343         if (maxnum_of_ids == 0) {
1344                 *num_of_ids = 0;
1345                 return ALARMMGR_RESULT_SUCCESS;
1346         }
1347
1348         if (!_send_alarm_get_list_of_ids
1349             (alarm_context, maxnum_of_ids, alarm_id, num_of_ids, &error_code))
1350                 return error_code;
1351
1352         return ALARMMGR_RESULT_SUCCESS;
1353 }
1354
1355 EXPORT_API int alarmmgr_get_next_duetime(alarm_id_t alarm_id, time_t* duetime)
1356 {
1357         int error_code;
1358         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_next_duetime() is called\n");
1359
1360         if (duetime == NULL) {
1361                 return ERR_ALARM_INVALID_PARAM;
1362         }
1363
1364         if (!_send_alarm_get_next_duetime
1365                 (alarm_context, alarm_id, duetime, &error_code))
1366                 return error_code;
1367
1368         return ALARMMGR_RESULT_SUCCESS;
1369 }