add alarmmgr_get_next_duetime api
[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
333         if (appid == NULL)
334                 return ERR_ALARM_INVALID_PARAM;
335
336         if (strlen(appid) >= MAX_PKG_NAME_LEN)
337                 return ERR_ALARM_INVALID_PARAM;
338
339         if (b_initialized) {
340                 ALARM_MGR_EXCEPTION_PRINT(
341                      "alarm was already initialized. app_service_name=%s\n",
342                      g_quark_to_string(alarm_context.quark_app_service_name));
343                 return ALARMMGR_RESULT_SUCCESS;
344         }
345
346         ret = __sub_init();
347         if (ret < 0)
348                 return ret;
349
350         memset(service_name_mod, 'a', MAX_SERVICE_NAME_LEN-1);
351         strncpy(service_name, appid, MAX_PKG_NAME_LEN);
352
353         j=0;
354
355         for(i=0;i<=strlen(service_name);i++)
356         {
357                 if (service_name[i] == '.' )
358                 {
359                         service_name_mod[j] = service_name[i];
360                         j++;
361                 }
362                 else{
363                         service_name_mod[j] = service_name[i];
364                 }
365                 j++;
366         }
367
368         strncat(service_name, ".ALARM", strlen(".ALARM"));
369
370         strncat(service_name_mod, ".ALARM", strlen(".ALARM"));
371
372
373         dbus_error_init(&derror);
374
375         request_name_result = dbus_bus_request_name(
376                           dbus_g_connection_get_connection(alarm_context.bus),
377                           service_name_mod, 0, &derror);
378         if (dbus_error_is_set(&derror)) /*failure*/ {
379                 ALARM_MGR_EXCEPTION_PRINT(
380                      "Failed to dbus_bus_request_name(%s): %s\n", service_name,
381                      derror.message);
382                 dbus_error_free(&derror);
383
384                 return ERR_ALARM_SYSTEM_FAIL;
385         }
386         alarm_context.quark_app_service_name =
387             g_quark_from_string(service_name);
388         alarm_context.quark_app_service_name_mod=
389             g_quark_from_string(service_name_mod);
390
391
392         if (!dbus_connection_add_filter(
393              dbus_g_connection_get_connection(alarm_context.bus),
394              __expire_alarm_filter, NULL, NULL)) {
395                 ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
396
397                 return ERR_ALARM_SYSTEM_FAIL;
398         }
399
400         b_initialized = true;
401         return ALARMMGR_RESULT_SUCCESS;
402
403 }
404
405 EXPORT_API void alarmmgr_fini()
406 {
407         dbus_connection_remove_filter(dbus_g_connection_get_connection
408                                       (alarm_context.bus),
409                                       __expire_alarm_filter, NULL);
410 }
411
412 EXPORT_API int alarmmgr_set_cb(alarm_cb_t handler, void *user_param)
413 {
414         ALARM_MGR_LOG_PRINT("alarm_set_cb is called\n");
415
416         if (handler == NULL) {
417                 return ERR_ALARM_INVALID_PARAM;
418         }
419         alarm_context.alarm_handler = handler;
420         alarm_context.user_param = user_param;
421         return ALARMMGR_RESULT_SUCCESS;
422 }
423
424 EXPORT_API alarm_entry_t *alarmmgr_create_alarm(void)
425 {
426         alarm_info_t *alarm = (alarm_info_t *) malloc(sizeof(alarm_info_t));
427
428         if (NULL == alarm)
429         {
430                 return NULL;
431         }
432
433         alarm->start.year = 0;
434         alarm->start.month = 0;
435         alarm->start.day = 0;
436         alarm->start.hour = 0;
437         alarm->start.min = 0;
438         alarm->start.sec = 0;
439
440         alarm->end.year = 0;
441         alarm->end.month = 0;
442         alarm->end.day = 0;
443         alarm->end.hour = 0;
444         alarm->end.min = 0;
445         alarm->end.sec = 0;
446
447         alarm->mode.repeat = ALARM_REPEAT_MODE_ONCE;
448         alarm->mode.u_interval.interval = 0;
449
450         alarm->alarm_type = ALARM_TYPE_DEFAULT;
451
452         alarm->reserved_info = 0;
453
454         return (alarm_entry_t *) alarm;
455 }
456
457 EXPORT_API int alarmmgr_free_alarm(alarm_entry_t *alarm)
458 {
459         if (alarm == NULL) {
460                 return ERR_ALARM_INVALID_PARAM;
461         }
462         free(alarm);
463
464         return ALARMMGR_RESULT_SUCCESS;
465 }
466
467 EXPORT_API int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time)
468 {
469         alarm_info_t *alarm_info;       /*= (alarm_info_t*)alarm;*/
470         int error_code;
471
472         if (alarm == NULL) {
473                 return ERR_ALARM_INVALID_PARAM;
474         }
475
476         alarm_info = (alarm_info_t *) alarm;
477
478         if (!__alarm_validate_date(&time, &error_code)) {
479                 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
480                 return error_code;
481         }
482
483         if (!__alarm_validate_time(&time, &error_code)) {
484                 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
485                 return error_code;
486         }
487
488         memcpy(&alarm_info->start, &time, sizeof(alarm_date_t));
489
490         return ALARMMGR_RESULT_SUCCESS;
491 }
492
493 EXPORT_API int alarmmgr_get_time(const alarm_entry_t *alarm,
494                                  alarm_date_t *time)
495 {
496         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
497
498         if (alarm == NULL) {
499                 return ERR_ALARM_INVALID_PARAM;
500         }
501
502         if (time != NULL)
503                 memcpy(time, &alarm_info->start, sizeof(alarm_date_t));
504
505         return ALARMMGR_RESULT_SUCCESS;
506 }
507
508 EXPORT_API int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
509                                         alarm_repeat_mode_t repeat,
510                                         int interval)
511 {
512         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
513
514         if (repeat >= ALARM_REPEAT_MODE_MAX) {
515                 return ERR_ALARM_INVALID_PARAM;
516         }
517
518         alarm_info->mode.repeat = repeat;
519
520         if (repeat == ALARM_REPEAT_MODE_REPEAT
521             || repeat == ALARM_REPEAT_MODE_WEEKLY) {
522                 alarm_info->mode.u_interval.interval = interval;
523         }
524
525         return ALARMMGR_RESULT_SUCCESS;
526 }
527
528 EXPORT_API int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
529                                         alarm_repeat_mode_t *repeat,
530                                         int *interval)
531 {
532         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
533
534         if (alarm == NULL) {
535                 return ERR_ALARM_INVALID_PARAM;
536         }
537
538         if (repeat != NULL)
539                 *repeat = alarm_info->mode.repeat;
540         if (interval != NULL)
541                 *interval = alarm_info->mode.u_interval.interval;
542
543         return ALARMMGR_RESULT_SUCCESS;
544 }
545
546 EXPORT_API int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type)
547 {
548         alarm_info_t *alarm_info;       /*= (alarm_info_t*)alarm;*/
549
550         if (alarm == NULL) {
551                 return ERR_ALARM_INVALID_PARAM;
552         }
553
554         alarm_info = (alarm_info_t *) alarm;
555
556         alarm_info->alarm_type = alarm_type;
557         alarm_info->alarm_type &= (~ALARM_TYPE_RELATIVE);
558
559         return ALARMMGR_RESULT_SUCCESS;
560 }
561
562 EXPORT_API int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type)
563 {
564         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
565
566         if (alarm == NULL) {
567                 return ERR_ALARM_INVALID_PARAM;
568         }
569
570         if (alarm_type != NULL)
571                 *alarm_type = alarm_info->alarm_type;
572
573         return ALARMMGR_RESULT_SUCCESS;
574 }
575
576
577 static int __alarmmgr_init_appsvc(void)
578 {
579         int ret;
580
581         if (b_initialized) {
582                 ALARM_MGR_EXCEPTION_PRINT("alarm was already initialized\n");
583                 return ALARMMGR_RESULT_SUCCESS;
584         }
585
586         g_thread_init(NULL);
587
588         dbus_g_thread_init();
589
590         ret = __sub_init();
591         if (ret < 0)
592                 return ret;
593
594         b_initialized = true;
595
596         return ALARMMGR_RESULT_SUCCESS;
597
598 }
599
600 EXPORT_API void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code){
601
602         int ret = 0;
603
604         ret = __sub_init();
605         if (ret < 0){
606                 if (return_code)
607                         *return_code = ret;
608                 return NULL;
609         }
610
611         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_alarm_appsvc_info() is called\n");
612
613         if (alarm_id <= 0) {
614                 if (return_code)
615                         *return_code = ERR_ALARM_INVALID_ID;
616                 return NULL;
617         }
618
619         return _send_alarm_get_appsvc_info(alarm_context, alarm_id, return_code);
620
621 }
622
623 EXPORT_API int alarmmgr_set_rtc_time(alarm_date_t *time){
624
625         int ret = 0;
626         int error_code = 0;
627
628         if (!time){
629                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter time\n");
630                 return ERR_ALARM_INVALID_PARAM;
631         }
632
633         ret = __sub_init();
634         if (ret < 0){
635                 return ret;
636         }
637
638         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_rtc_time() is called\n");
639
640         if (!__alarm_validate_date(time, &error_code)) {
641                 ALARM_MGR_EXCEPTION_PRINT("RTC date error\n");
642                 return error_code;
643         }
644
645         if (!__alarm_validate_time(time, &error_code)) {
646                 ALARM_MGR_EXCEPTION_PRINT("RTC time error\n");
647                 return error_code;
648         }
649
650         time->year-=1900;
651         time->month-=1;
652
653         if (!_send_alarm_set_rtc_time
654                 (alarm_context, time, &error_code)){
655                         return error_code;
656         }
657
658         return ALARMMGR_RESULT_SUCCESS;
659
660 }
661
662 EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, void *bundle_data, alarm_id_t *alarm_id)
663 {
664         alarm_info_t *alarm_info = NULL;        /* = (alarm_info_t*)alarm; */
665         const char *operation = NULL;
666         int error_code = 0;
667         char *appid = NULL;
668
669         bundle *b=(bundle *)bundle_data;
670
671         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
672
673         if (alarm == NULL) {
674                 return ERR_ALARM_INVALID_PARAM;
675         }
676
677         if (NULL == b)
678         {
679                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle\n");
680                 return ERR_ALARM_INVALID_PARAM;
681         }
682         operation = appsvc_get_operation(b);
683
684         if (NULL == operation)
685         {
686                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle [appsvc operation not present]\n");
687                 return ERR_ALARM_INVALID_PARAM;
688         }
689
690         if (__alarmmgr_init_appsvc() < 0)
691         {
692                 ALARM_MGR_EXCEPTION_PRINT("Unable to initialize dbus!!!\n");
693                 return ERR_ALARM_SYSTEM_FAIL;
694         }
695
696         alarm_info = (alarm_info_t *) alarm;
697
698         appid = appsvc_get_appid(b);
699
700         if (NULL == appid && (alarm_info->alarm_type & ALARM_TYPE_NOLAUNCH) )
701         {
702                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
703                 return ERR_ALARM_INVALID_PARAM;
704         }
705
706         if (alarm_info == NULL || alarm_id == NULL) {
707                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
708                 return ERR_ALARM_INVALID_PARAM;
709         }
710         alarm_mode_t *mode = &alarm_info->mode;
711
712         ALARM_MGR_LOG_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
713                 alarm_info->start.day, alarm_info->start.month, alarm_info->start.year,
714                 alarm_info->start.hour, alarm_info->start.min, alarm_info->start.sec,
715                 alarm_info->end.year, alarm_info->end.month, alarm_info->end.day,
716                 alarm_info->mode.repeat, alarm_info->mode.u_interval, alarm_info->alarm_type);
717
718         /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
719         if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
720                 return ERR_ALARM_INVALID_PARAM;
721         }
722
723         if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
724                 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
725                 return error_code;
726         }
727
728         if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
729                 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
730                 return error_code;
731         }
732
733         if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
734                 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
735                 return error_code;
736         }
737
738
739         if (!_send_alarm_create_appsvc
740             (alarm_context, alarm_info, alarm_id, b,
741              &error_code)) {
742                 return error_code;
743         }
744
745         return ALARMMGR_RESULT_SUCCESS;
746 }
747
748
749
750
751 EXPORT_API int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
752                                                  const char *destination,
753                                                  alarm_id_t *alarm_id)
754 {
755         char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
756         char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
757         alarm_info_t *alarm_info;       /* = (alarm_info_t*)alarm; */
758         int ret;
759         int i = 0;
760         int j = 0;
761
762         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
763
764         if (alarm == NULL) {
765                 return ERR_ALARM_INVALID_PARAM;
766         }
767
768         alarm_info = (alarm_info_t *) alarm;
769         if (alarm_info == NULL || alarm_id == NULL) {
770                 return ERR_ALARM_INVALID_PARAM;
771         }
772
773         int error_code;
774         alarm_mode_t *mode = &alarm_info->mode;
775
776         ret = __sub_init();
777         if (ret < 0)
778                 return ret;
779
780         ALARM_MGR_LOG_PRINT("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%d), type(%d)",
781                 alarm_info->start.day, alarm_info->start.month, alarm_info->start.year,
782                 alarm_info->start.hour, alarm_info->start.min, alarm_info->start.sec,
783                 alarm_info->end.year, alarm_info->end.month, alarm_info->end.day,
784                 alarm_info->mode.repeat, alarm_info->mode.u_interval, alarm_info->alarm_type);
785
786         /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
787         if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
788                 return ERR_ALARM_INVALID_PARAM;
789         }
790
791         if (destination && strlen(destination) >= MAX_PKG_NAME_LEN){
792                 ALARM_MGR_EXCEPTION_PRINT("[alarm-lib]: destination name is too long!\n");
793                 return ERR_ALARM_INVALID_PARAM;
794         }
795
796
797         if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
798                 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
799                 return error_code;
800         }
801
802         if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
803                 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
804                 return error_code;
805         }
806
807         if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
808                 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
809                 return error_code;
810         }
811
812         if (destination != NULL) {
813                 memset(dst_service_name, 0,
814                        strlen(destination) + strlen(".ALARM") + 2);
815                 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s",
816                          destination);
817
818                 memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
819
820                 j=0;
821
822                 for(i=0; i<=strlen(dst_service_name); i++)
823                 {
824                         if (dst_service_name[i] == '.' )
825                         {
826                                 dst_service_name_mod[j] = dst_service_name[i];
827                                 j++;
828                         }
829                         else
830                         {
831                                 dst_service_name_mod[j] = dst_service_name[i];
832                         }
833                         j++;
834                 }
835
836                 strncat(dst_service_name, ".ALARM", strlen(".ALARM"));
837                 strncat(dst_service_name_mod, ".ALARM", strlen(".ALARM"));
838
839                 if (!_send_alarm_create
840                     (alarm_context, alarm_info, alarm_id, dst_service_name, dst_service_name_mod,
841                      &error_code)) {
842                         return error_code;
843                 }
844         } else
845             if (!_send_alarm_create
846                 (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
847                 return error_code;
848         }
849
850         return ALARMMGR_RESULT_SUCCESS;
851 }
852
853
854
855 EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
856                                   time_t interval, void *bundle_data,
857                                   alarm_id_t *alarm_id)
858 {
859         int error_code = 0;;
860         time_t current_time;
861         struct tm duetime_tm;
862         alarm_info_t alarm_info;
863         const char *operation = NULL;
864         char *appid = NULL;
865
866         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
867
868         bundle *b=(bundle *)bundle_data;
869
870         if (NULL == b)
871         {
872                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle\n");
873                 return ERR_ALARM_INVALID_PARAM;
874         }
875         operation = appsvc_get_operation(b);
876
877         if (NULL == operation)
878         {
879                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle [appsvc operation not present]\n");
880                 return ERR_ALARM_INVALID_PARAM;
881         }
882
883         appid = appsvc_get_appid(b);
884
885         if (NULL == appid && (alarm_type & ALARM_TYPE_NOLAUNCH) )
886         {
887                 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
888                 return ERR_ALARM_INVALID_PARAM;
889         }
890
891         if (__alarmmgr_init_appsvc() < 0)
892         {
893                 ALARM_MGR_EXCEPTION_PRINT("Unable to initialize dbus!!!\n");
894                 return ERR_ALARM_SYSTEM_FAIL;
895         }
896
897         if (alarm_id == NULL) {
898                 return ERR_ALARM_INVALID_PARAM;
899         }
900
901         if (trigger_at_time < 0) {
902                 return ERR_ALARM_INVALID_PARAM;
903         }
904
905         alarm_info.alarm_type = alarm_type;
906         alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
907
908         time(&current_time);
909
910         current_time += trigger_at_time;
911
912         localtime_r(&current_time, &duetime_tm);
913
914         alarm_info.start.year = duetime_tm.tm_year + 1900;
915         alarm_info.start.month = duetime_tm.tm_mon + 1;
916         alarm_info.start.day = duetime_tm.tm_mday;
917
918         alarm_info.end.year = 0;
919         alarm_info.end.month = 0;
920         alarm_info.end.day = 0;
921
922         alarm_info.start.hour = duetime_tm.tm_hour;
923         alarm_info.start.min = duetime_tm.tm_min;
924         alarm_info.start.sec = duetime_tm.tm_sec;
925
926         if (interval <= 0) {
927                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
928                 alarm_info.mode.u_interval.interval = 0;
929         } else {
930                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
931                 alarm_info.mode.u_interval.interval = interval;
932         }
933
934         ALARM_MGR_LOG_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
935                 trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
936                 alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
937                 alarm_info.mode.repeat, alarm_info.mode.u_interval, alarm_info.alarm_type);
938
939         if (!_send_alarm_create_appsvc
940             (alarm_context, &alarm_info, alarm_id, b,
941              &error_code)) {
942                 return error_code;
943         }
944
945         return ALARMMGR_RESULT_SUCCESS;
946 }
947
948
949 EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
950                                   time_t interval, const char *destination,
951                                   alarm_id_t *alarm_id)
952 {
953         char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
954         char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
955         int i = 0;
956         int j = 0;
957         int error_code;
958         time_t current_time;
959         struct tm duetime_tm;
960         alarm_info_t alarm_info;
961         int ret;
962
963         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
964
965         ret = __sub_init();
966         if (ret < 0)
967                 return ret;
968
969         if (alarm_id == NULL) {
970                 return ERR_ALARM_INVALID_PARAM;
971         }
972
973         if (trigger_at_time < 0) {
974                 return ERR_ALARM_INVALID_PARAM;
975         }
976
977         if (destination && strlen(destination) >= MAX_PKG_NAME_LEN){
978                 ALARM_MGR_EXCEPTION_PRINT("[alarm-lib]: destination name is too long!\n");
979                 return ERR_ALARM_INVALID_PARAM;
980         }
981
982         alarm_info.alarm_type = alarm_type;
983         alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
984
985         time(&current_time);
986
987         current_time += trigger_at_time;
988
989         localtime_r(&current_time, &duetime_tm);
990
991         alarm_info.start.year = duetime_tm.tm_year + 1900;
992         alarm_info.start.month = duetime_tm.tm_mon + 1;
993         alarm_info.start.day = duetime_tm.tm_mday;
994
995         alarm_info.end.year = 0;
996         alarm_info.end.month = 0;
997         alarm_info.end.day = 0;
998
999         alarm_info.start.hour = duetime_tm.tm_hour;
1000         alarm_info.start.min = duetime_tm.tm_min;
1001         alarm_info.start.sec = duetime_tm.tm_sec;
1002
1003         if (interval <= 0) {
1004                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
1005                 alarm_info.mode.u_interval.interval = 0;
1006         } else {
1007                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
1008                 alarm_info.mode.u_interval.interval = interval;
1009         }
1010
1011         ALARM_MGR_LOG_PRINT("trigger_at_time(%d), start(%d-%d-%d, %02d:%02d:%02d), repeat(%d), interval(%d), type(%d)",
1012                 trigger_at_time, alarm_info.start.day, alarm_info.start.month, alarm_info.start.year,
1013                 alarm_info.start.hour, alarm_info.start.min, alarm_info.start.sec,
1014                 alarm_info.mode.repeat, alarm_info.mode.u_interval, alarm_info.alarm_type);
1015
1016         if (destination != NULL) {
1017                 memset(dst_service_name, 0,
1018                        strlen(destination) + strlen(".ALARM") + 2);
1019                 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s",
1020                          destination);
1021                 memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
1022
1023                 j=0;
1024
1025                 for(i=0;i<=strlen(dst_service_name);i++)
1026                 {
1027                         if (dst_service_name[i] == '.')
1028                         {
1029                                 dst_service_name_mod[j]=dst_service_name[i];
1030                                 j++;
1031                         }
1032                         else
1033                         {
1034                                 dst_service_name_mod[j]=dst_service_name[i];
1035                         }
1036                         j++;
1037                 }
1038
1039                 strncat(dst_service_name, ".ALARM", strlen(".ALARM"));
1040                 strncat(dst_service_name_mod, ".ALARM", strlen(".ALARM"));
1041
1042                 if (!_send_alarm_create
1043                     (alarm_context, &alarm_info, alarm_id, dst_service_name,dst_service_name_mod,
1044                      &error_code)) {
1045                         return error_code;
1046                 }
1047         } else
1048             if (!_send_alarm_create
1049                 (alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) {
1050                 return error_code;
1051         }
1052
1053         return ALARMMGR_RESULT_SUCCESS;
1054 }
1055
1056 EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time,
1057                                   time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id)
1058 {
1059         char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
1060         char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
1061         int i = 0;
1062         int j = 0;
1063         int error_code;
1064         time_t current_time;
1065         struct tm duetime_tm;
1066         alarm_info_t alarm_info;
1067         int ret;
1068         char appid[256];
1069
1070         aul_app_get_appid_bypid(getpid(), appid, sizeof(appid));
1071
1072         ret = alarmmgr_init(appid);
1073         if (ret < 0)
1074                 return ret;
1075
1076         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_add_alarm_withcb() is called\n");
1077
1078         ALARM_MGR_LOG_PRINT("interval(%d)", interval);
1079
1080         if (alarm_id == NULL) {
1081                 return ERR_ALARM_INVALID_PARAM;
1082         }
1083
1084         if (trigger_at_time < 0) {
1085                 return ERR_ALARM_INVALID_PARAM;
1086         }
1087
1088         alarm_info.alarm_type = alarm_type;
1089         alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
1090         alarm_info.alarm_type |= ALARM_TYPE_WITHCB;
1091
1092         time(&current_time);
1093
1094         current_time += trigger_at_time;
1095
1096         localtime_r(&current_time, &duetime_tm);
1097
1098         alarm_info.start.year = duetime_tm.tm_year + 1900;
1099         alarm_info.start.month = duetime_tm.tm_mon + 1;
1100         alarm_info.start.day = duetime_tm.tm_mday;
1101
1102         alarm_info.end.year = 0;
1103         alarm_info.end.month = 0;
1104         alarm_info.end.day = 0;
1105
1106         alarm_info.start.hour = duetime_tm.tm_hour;
1107         alarm_info.start.min = duetime_tm.tm_min;
1108         alarm_info.start.sec = duetime_tm.tm_sec;
1109
1110         if (interval <= 0) {
1111                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
1112                 alarm_info.mode.u_interval.interval = 0;
1113         } else {
1114                 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
1115                 alarm_info.mode.u_interval.interval = interval;
1116         }
1117
1118         if (!_send_alarm_create(alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) {
1119                 return error_code;
1120         }
1121         __add_resultcb(*alarm_id, handler, user_param);
1122
1123         return ALARMMGR_RESULT_SUCCESS;
1124 }
1125
1126 EXPORT_API int alarmmgr_remove_alarm(alarm_id_t alarm_id)
1127 {
1128         int error_code;
1129         int ret;
1130         alarm_cb_info_t *info;
1131
1132         ret = __sub_init();
1133         if (ret < 0)
1134                 return ret;
1135
1136         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_delete() is called\n");
1137
1138         if (alarm_id <= 0) {
1139                 return ERR_ALARM_INVALID_ID;
1140         }
1141
1142         if (!_send_alarm_delete(alarm_context, alarm_id, &error_code))
1143                 return error_code;
1144
1145         info = __find_resultcb(alarm_id);
1146         __remove_resultcb(info);
1147
1148         return ALARMMGR_RESULT_SUCCESS;
1149 }
1150
1151 EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
1152 {
1153         GError *error = NULL;
1154         GArray *alarm_array = NULL;
1155         int return_code = 0;
1156         int i = 0;
1157         int maxnum_of_ids;
1158         int num_of_ids;
1159         int alarm_id = -1;
1160         int ret;
1161
1162         if (fn == NULL)
1163                 return ERR_ALARM_INVALID_PARAM;
1164
1165         ret = __sub_init();
1166         if (ret < 0)
1167                 return ret;
1168
1169         if (!org_tizen_alarm_manager_alarm_get_number_of_ids(
1170             alarm_context.proxy, alarm_context.pid, &maxnum_of_ids,
1171                &return_code, &error)) {
1172                 /* dbus-glib error */
1173                 /* error_code should be set */
1174                 ALARM_MGR_EXCEPTION_PRINT(
1175                     "org_tizen_alarm_manager_alarm_get_number_of_ids() "
1176                     "failed. return_code[%d], return_code[%s]\n",
1177                 return_code, error->message);
1178         }
1179
1180         if (return_code != 0) {
1181                 return return_code;
1182         }
1183
1184         if (!org_tizen_alarm_manager_alarm_get_list_of_ids(
1185                      alarm_context.proxy, alarm_context.pid, maxnum_of_ids,
1186              &alarm_array, &num_of_ids, &return_code, &error)) {
1187                 /*dbus-glib error */
1188                 /* error_code should be set */
1189                 ALARM_MGR_EXCEPTION_PRINT(
1190                     "org_tizen_alarm_manager_alarm_get_list_of_ids() "
1191                     "failed. alarm_id[%d], return_code[%d]\n",
1192                      alarm_id, return_code);
1193         }
1194
1195         if (return_code != 0) {
1196                 return return_code;
1197         } else {
1198                 if (error != NULL) {
1199                         ALARM_MGR_LOG_PRINT(
1200                                 "Alarm server not ready dbus error message %s\n", error->message);
1201                         return ERR_ALARM_SYSTEM_FAIL;
1202                 }
1203                 if (NULL == alarm_array) {
1204                         ALARM_MGR_LOG_PRINT(
1205                                 "alarm server not initilized\n");
1206                         return ERR_ALARM_SYSTEM_FAIL;
1207                 }
1208                 for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
1209                         alarm_id = g_array_index(alarm_array, alarm_id_t, i);
1210                         (*fn) (alarm_id, user_param);
1211                         ALARM_MGR_LOG_PRINT(" alarm_id(%d)\n", alarm_id);
1212                 }
1213
1214                 g_array_free(alarm_array, true);
1215         }
1216
1217         return ALARMMGR_RESULT_SUCCESS;
1218 }
1219
1220 EXPORT_API int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm)
1221 {
1222         int error_code;
1223         alarm_info_t *alarm_info = (alarm_info_t *) alarm;
1224
1225         int ret;
1226
1227         ret = __sub_init();
1228         if (ret < 0)
1229                 return ret;
1230
1231         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_info() is called\n");
1232
1233         if (alarm_id < 0 || alarm_info == NULL) {
1234                 return ERR_ALARM_INVALID_PARAM;
1235         }
1236
1237         if (!_send_alarm_get_info(alarm_context, alarm_id, alarm_info,
1238                                   &error_code))
1239                 return error_code;
1240
1241         return ALARMMGR_RESULT_SUCCESS;
1242 }
1243
1244 EXPORT_API int alarmmgr_power_on(bool on_off)
1245 {
1246         int error_code;
1247         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_on() is called\n");
1248
1249 #ifdef __ALARM_BOOT
1250         if (!_send_alarm_power_on(alarm_context, on_off, &error_code))
1251                 return error_code;
1252 #else
1253         ALARM_MGR_LOG_PRINT("[alarm-lib]:ALARM_BOOT feature is not supported. "
1254                             "so we return false.\n");
1255         return ERR_ALARM_SYSTEM_FAIL;
1256 #endif
1257
1258         return ALARMMGR_RESULT_SUCCESS;
1259 }
1260
1261 int alarmmgr_create(alarm_info_t *alarm_info, char *destination,
1262                     alarm_id_t *alarm_id)
1263 {
1264         char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
1265         alarm_mode_t *mode = &alarm_info->mode;
1266         int error_code;
1267
1268         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
1269
1270         if (alarm_info == NULL || alarm_id == NULL) {
1271                 return ERR_ALARM_INVALID_PARAM;
1272         }
1273
1274         ALARM_MGR_LOG_PRINT("alarm_info->start.year(%d), "
1275                             "alarm_info->start.month(%d), alarm_info->start.day(%d)",
1276                             alarm_info->start.year, alarm_info->start.month,
1277                             alarm_info->start.day);
1278
1279         /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
1280         if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
1281                 return ERR_ALARM_INVALID_PARAM;
1282         }
1283
1284         if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
1285                 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
1286                 return error_code;
1287         }
1288
1289         if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
1290                 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
1291                 return error_code;
1292         }
1293
1294         if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
1295                 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
1296                 return error_code;
1297         }
1298
1299         if (destination != NULL) {
1300                 memset(dst_service_name, 0,
1301                        strlen(destination) + strlen(".ALARM") + 2);
1302                 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s.ALARM",
1303                          destination);
1304                 if (!_send_alarm_create
1305                     (alarm_context, alarm_info, alarm_id, dst_service_name,"null",
1306                      &error_code)) {
1307                         return error_code;
1308                 }
1309         }
1310 /*TODO: Currently this API is not exported. Hence not modifying*/
1311         if (!_send_alarm_create
1312             (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
1313                 return error_code;
1314         }
1315
1316         return ALARMMGR_RESULT_SUCCESS;
1317
1318 }
1319
1320 int alarmmgr_get_number_of_ids(int *num_of_ids)
1321 {
1322         int error_code;
1323         ALARM_MGR_LOG_PRINT("[alarm-lib]:"
1324                             "alarm_get_number_of_ids() is called\n");
1325
1326         if (num_of_ids == NULL) {
1327                 return ERR_ALARM_INVALID_PARAM;
1328         }
1329         ALARM_MGR_LOG_PRINT("call alarm_get_number_of_ids\n");
1330         if (!_send_alarm_get_number_of_ids(alarm_context, num_of_ids,
1331                                            &error_code))
1332                 return error_code;
1333
1334         return ALARMMGR_RESULT_SUCCESS;
1335 }
1336
1337 int alarmmgr_get_list_of_ids(int maxnum_of_ids, alarm_id_t *alarm_id,
1338                              int *num_of_ids)
1339 {
1340         int error_code;
1341         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_list_of_ids() is called\n");
1342
1343         if (maxnum_of_ids < 0 || alarm_id == NULL || num_of_ids == NULL) {
1344                 return ERR_ALARM_INVALID_PARAM;
1345         }
1346
1347         if (maxnum_of_ids == 0) {
1348                 *num_of_ids = 0;
1349                 return ALARMMGR_RESULT_SUCCESS;
1350         }
1351
1352         if (!_send_alarm_get_list_of_ids
1353             (alarm_context, maxnum_of_ids, alarm_id, num_of_ids, &error_code))
1354                 return error_code;
1355
1356         return ALARMMGR_RESULT_SUCCESS;
1357 }
1358
1359 EXPORT_API int alarmmgr_get_next_duetime(alarm_id_t alarm_id, time_t* duetime)
1360 {
1361         int error_code;
1362         ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_next_duetime() is called\n");
1363
1364         if (duetime == NULL) {
1365                 return ERR_ALARM_INVALID_PARAM;
1366         }
1367
1368         if (!_send_alarm_get_next_duetime
1369                 (alarm_context, alarm_id, duetime, &error_code))
1370                 return error_code;
1371
1372         return ALARMMGR_RESULT_SUCCESS;
1373 }