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