4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
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>
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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.
34 #include<dbus/dbus-glib.h>
37 #include <dbus/dbus-glib-lowlevel.h>
40 #include "alarm-internal.h"
41 #include "alarm-stub.h"
45 #define MAX_KEY_SIZE 256
47 static alarm_context_t alarm_context = { NULL, NULL, NULL, NULL, -1 };
49 static bool b_initialized = false;
50 static bool sub_initialized = false;
52 #define MAX_OBJECT_PATH_LEN 256
53 #define DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT 0
55 static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection,
58 static int __alarm_validate_date(alarm_date_t *date, int *error_code);
59 static bool __alarm_validate_time(alarm_date_t *date, int *error_code);
60 static int __sub_init(void);
61 static int __alarmmgr_init_appsvc(void);
62 bool alarm_power_off(int *error_code);
63 int alarmmgr_check_next_duetime(void);
67 static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection,
71 if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL) {
72 const char *method_name = dbus_message_get_member(message);
75 if (strcmp(method_name, "alarm_expired") == 0) {
78 const char *service_name =
79 dbus_message_get_destination(message);
80 const char *object_path =
81 dbus_message_get_path(message);
82 /* "/org/tizen/alarm/client" */
83 const char *interface_name =
84 dbus_message_get_interface(message);
85 /* "org.tizen.alarm.client" */
87 dbus_message_iter_init(message, &iter);
88 dbus_message_iter_get_basic(&iter, &alarm_id);
90 ALARM_MGR_LOG_PRINT("[alarm-lib]:service_name=%s, "
91 "object_path=%s, interface_name=%s, method_name=%s, "
92 "alarm_id=%d, handler=%s\n",
93 service_name ? service_name : "no name",
94 object_path ? object_path : "no path",
95 interface_name ? interface_name : "no interface",
96 method_name ? method_name : "no method", alarm_id,
97 alarm_context.alarm_handler ? "ok" : "no handler");
99 if (alarm_context.alarm_handler != NULL)
100 /* alarm_context.alarm_handler(alarm_id); */
101 alarm_context.alarm_handler(alarm_id,
102 alarm_context.user_param);
103 return DBUS_HANDLER_RESULT_HANDLED;
107 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
111 static int __alarm_validate_date(alarm_date_t *date, int *error_code)
114 if (date->year == 0 && date->month == 0 && date->day == 0) {
118 int year = date->year;
119 int month = date->month;
122 if (month < 1 || month > 12) {
124 *error_code = ERR_ALARM_INVALID_DATE;
128 if ((month == 1 || month == 3 || month == 5 || month == 7 || month == 8
129 || month == 10 || month == 12)
130 && (day < 1 || day > 31)) {
132 *error_code = ERR_ALARM_INVALID_DATE;
136 if ((month == 4 || month == 6 || month == 9 || month == 11)
137 && (day < 1 || day > 30)) {
139 *error_code = ERR_ALARM_INVALID_DATE;
144 if ((year % 100 != 0 && year % 4 == 0) || (year % 400 == 0)) {
145 if (day < 1 || day > 29) {
147 *error_code = ERR_ALARM_INVALID_DATE;
151 if (day < 1 || day > 28) {
153 *error_code = ERR_ALARM_INVALID_DATE;
164 static bool __alarm_validate_time(alarm_date_t *date, int *error_code)
166 if (date->hour < 0 || date->hour > 23) {
168 *error_code = ERR_ALARM_INVALID_TIME;
172 if (date->min < 0 || date->min > 59) {
174 *error_code = ERR_ALARM_INVALID_TIME;
181 static int __sub_init()
183 GError *error = NULL;
185 if (sub_initialized) {
186 ALARM_MGR_EXCEPTION_PRINT("__sub_init was already called.\n");
187 return ALARMMGR_RESULT_SUCCESS;
191 dbus_g_thread_init();
193 alarm_context.bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
194 if (alarm_context.bus == NULL) {
195 ALARM_MGR_EXCEPTION_PRINT("dbus bus get failed\n");
197 return ERR_ALARM_SYSTEM_FAIL;
200 alarm_context.proxy = dbus_g_proxy_new_for_name(alarm_context.bus,
201 "org.tizen.alarm.manager",
202 "/org/tizen/alarm/manager",
203 "org.tizen.alarm.manager");
204 if (alarm_context.proxy == NULL) {
205 ALARM_MGR_EXCEPTION_PRINT("dbus bus proxy get failed\n");
207 return ERR_ALARM_SYSTEM_FAIL;
210 alarm_context.pid = getpid(); /*this running appliction's process id*/
212 sub_initialized = true;
214 return ALARMMGR_RESULT_SUCCESS;
217 bool alarm_power_off(int *error_code)
219 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_off() is called\n");
222 return _send_alarm_power_off(alarm_context, error_code);
225 "[alarm-lib]:ALARM_BOOT feature is not supported. "
226 "so we return false.\n");
228 *error_code = -1; /*-1 means that system failed
234 int alarmmgr_check_next_duetime()
238 "[alarm-lib]:alarm_check_next_duetime() is called\n");
241 if (!_send_alarm_check_next_duetime(alarm_context, &error_code))
245 "[alarm-lib]:ALARM_BOOT feature is not supported. "
246 "so we return false.\n");
247 return ERR_ALARM_SYSTEM_FAIL;
250 return ALARMMGR_RESULT_SUCCESS;
253 EXPORT_API int alarmmgr_init(const char *pkg_name)
256 int request_name_result = 0;
257 char service_name[MAX_SERVICE_NAME_LEN] = { 0 };
258 char service_name_mod[MAX_SERVICE_NAME_LEN]= { 0 };
264 if (pkg_name == NULL)
265 return ERR_ALARM_INVALID_PARAM;
267 if (strlen(pkg_name) >= MAX_PKG_NAME_LEN)
268 return ERR_ALARM_INVALID_PARAM;
271 ALARM_MGR_EXCEPTION_PRINT(
272 "alarm was already initialized. app_service_name=%s\n",
273 g_quark_to_string(alarm_context.quark_app_service_name));
274 return ALARMMGR_RESULT_SUCCESS;
281 memset(service_name_mod, 'a', MAX_SERVICE_NAME_LEN-1);
282 strncpy(service_name, pkg_name, MAX_PKG_NAME_LEN);
286 for(i=0;i<=strlen(service_name);i++)
288 if (service_name[i] == '.' )
290 service_name_mod[j] = service_name[i];
294 service_name_mod[j] = service_name[i];
299 strncat(service_name, ".ALARM", strlen(".ALARM"));
301 strncat(service_name_mod, ".ALARM", strlen(".ALARM"));
304 dbus_error_init(&derror);
306 request_name_result = dbus_bus_request_name(
307 dbus_g_connection_get_connection(alarm_context.bus),
308 service_name_mod, 0, &derror);
309 if (dbus_error_is_set(&derror)) /*failure*/ {
310 ALARM_MGR_EXCEPTION_PRINT(
311 "Failed to dbus_bus_request_name(%s): %s\n", service_name,
313 dbus_error_free(&derror);
315 return ERR_ALARM_SYSTEM_FAIL;
317 alarm_context.quark_app_service_name =
318 g_quark_from_string(service_name);
319 alarm_context.quark_app_service_name_mod=
320 g_quark_from_string(service_name_mod);
323 if (!dbus_connection_add_filter(
324 dbus_g_connection_get_connection(alarm_context.bus),
325 __expire_alarm_filter, NULL, NULL)) {
326 ALARM_MGR_EXCEPTION_PRINT("add __expire_alarm_filter failed\n");
328 return ERR_ALARM_SYSTEM_FAIL;
331 b_initialized = true;
332 return ALARMMGR_RESULT_SUCCESS;
336 EXPORT_API void alarmmgr_fini()
338 dbus_connection_remove_filter(dbus_g_connection_get_connection
340 __expire_alarm_filter, NULL);
343 EXPORT_API int alarmmgr_set_cb(alarm_cb_t handler, void *user_param)
345 ALARM_MGR_LOG_PRINT("alarm_set_cb is called\n");
347 if (handler == NULL) {
348 return ERR_ALARM_INVALID_PARAM;
350 alarm_context.alarm_handler = handler;
351 alarm_context.user_param = user_param;
352 return ALARMMGR_RESULT_SUCCESS;
355 EXPORT_API alarm_entry_t *alarmmgr_create_alarm(void)
357 alarm_info_t *alarm = (alarm_info_t *) malloc(sizeof(alarm_info_t));
364 alarm->start.year = 0;
365 alarm->start.month = 0;
366 alarm->start.day = 0;
367 alarm->start.hour = 0;
368 alarm->start.min = 0;
369 alarm->start.sec = 0;
372 alarm->end.month = 0;
378 alarm->mode.repeat = ALARM_REPEAT_MODE_ONCE;
379 alarm->mode.u_interval.interval = 0;
381 alarm->alarm_type = ALARM_TYPE_DEFAULT;
383 alarm->reserved_info = 0;
385 return (alarm_entry_t *) alarm;
388 EXPORT_API int alarmmgr_free_alarm(alarm_entry_t *alarm)
391 return ERR_ALARM_INVALID_PARAM;
395 return ALARMMGR_RESULT_SUCCESS;
398 EXPORT_API int alarmmgr_set_time(alarm_entry_t *alarm, alarm_date_t time)
400 alarm_info_t *alarm_info; /*= (alarm_info_t*)alarm;*/
404 return ERR_ALARM_INVALID_PARAM;
407 alarm_info = (alarm_info_t *) alarm;
409 if (!__alarm_validate_date(&time, &error_code)) {
410 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
414 if (!__alarm_validate_time(&time, &error_code)) {
415 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
419 memcpy(&alarm_info->start, &time, sizeof(alarm_date_t));
421 return ALARMMGR_RESULT_SUCCESS;
424 EXPORT_API int alarmmgr_get_time(const alarm_entry_t *alarm,
427 alarm_info_t *alarm_info = (alarm_info_t *) alarm;
430 return ERR_ALARM_INVALID_PARAM;
434 memcpy(time, &alarm_info->start, sizeof(alarm_date_t));
436 return ALARMMGR_RESULT_SUCCESS;
439 EXPORT_API int alarmmgr_set_repeat_mode(alarm_entry_t *alarm,
440 alarm_repeat_mode_t repeat,
443 alarm_info_t *alarm_info = (alarm_info_t *) alarm;
445 if (repeat >= ALARM_REPEAT_MODE_MAX) {
446 return ERR_ALARM_INVALID_PARAM;
449 alarm_info->mode.repeat = repeat;
451 if (repeat == ALARM_REPEAT_MODE_REPEAT
452 || repeat == ALARM_REPEAT_MODE_WEEKLY) {
453 alarm_info->mode.u_interval.interval = interval;
456 return ALARMMGR_RESULT_SUCCESS;
459 EXPORT_API int alarmmgr_get_repeat_mode(const alarm_entry_t *alarm,
460 alarm_repeat_mode_t *repeat,
463 alarm_info_t *alarm_info = (alarm_info_t *) alarm;
466 return ERR_ALARM_INVALID_PARAM;
470 *repeat = alarm_info->mode.repeat;
471 if (interval != NULL)
472 *interval = alarm_info->mode.u_interval.interval;
474 return ALARMMGR_RESULT_SUCCESS;
477 EXPORT_API int alarmmgr_set_type(alarm_entry_t *alarm, int alarm_type)
479 alarm_info_t *alarm_info; /*= (alarm_info_t*)alarm;*/
482 return ERR_ALARM_INVALID_PARAM;
485 alarm_info = (alarm_info_t *) alarm;
487 alarm_info->alarm_type = alarm_type;
488 alarm_info->alarm_type &= (~ALARM_TYPE_RELATIVE);
490 return ALARMMGR_RESULT_SUCCESS;
493 EXPORT_API int alarmmgr_get_type(const alarm_entry_t *alarm, int *alarm_type)
495 alarm_info_t *alarm_info = (alarm_info_t *) alarm;
498 return ERR_ALARM_INVALID_PARAM;
501 if (alarm_type != NULL)
502 *alarm_type = alarm_info->alarm_type;
504 return ALARMMGR_RESULT_SUCCESS;
508 static int __alarmmgr_init_appsvc(void)
513 ALARM_MGR_EXCEPTION_PRINT("alarm was already initialized\n");
514 return ALARMMGR_RESULT_SUCCESS;
519 dbus_g_thread_init();
525 b_initialized = true;
527 return ALARMMGR_RESULT_SUCCESS;
531 EXPORT_API void *alarmmgr_get_alarm_appsvc_info(alarm_id_t alarm_id, int *return_code){
542 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_get_alarm_appsvc_info() is called\n");
546 *return_code = ERR_ALARM_INVALID_ID;
550 return _send_alarm_get_appsvc_info(alarm_context, alarm_id, return_code);
554 EXPORT_API int alarmmgr_set_rtc_time(alarm_date_t *time){
560 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter time\n");
561 return ERR_ALARM_INVALID_PARAM;
569 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_set_rtc_time() is called\n");
571 if (!__alarm_validate_date(time, &error_code)) {
572 ALARM_MGR_EXCEPTION_PRINT("RTC date error\n");
576 if (!__alarm_validate_time(time, &error_code)) {
577 ALARM_MGR_EXCEPTION_PRINT("RTC time error\n");
584 if (!_send_alarm_set_rtc_time
585 (alarm_context, time, &error_code)){
589 return ALARMMGR_RESULT_SUCCESS;
593 EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, void *bundle_data, alarm_id_t *alarm_id)
595 alarm_info_t *alarm_info = NULL; /* = (alarm_info_t*)alarm; */
596 const char *operation = NULL;
599 bundle *b=(bundle *)bundle_data;
602 return ERR_ALARM_INVALID_PARAM;
607 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle\n");
608 return ERR_ALARM_INVALID_PARAM;
610 operation = appsvc_get_operation(b);
612 if (NULL == operation)
614 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle [appsvc operation not present]\n");
615 return ERR_ALARM_INVALID_PARAM;
618 if (__alarmmgr_init_appsvc() < 0)
620 ALARM_MGR_EXCEPTION_PRINT("Unable to initialize dbus!!!\n");
621 return ERR_ALARM_SYSTEM_FAIL;
624 alarm_info = (alarm_info_t *) alarm;
626 if (alarm_info == NULL || alarm_id == NULL) {
627 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
628 return ERR_ALARM_INVALID_PARAM;
630 alarm_mode_t *mode = &alarm_info->mode;
632 ALARM_MGR_LOG_PRINT("alarm_info->start.year(%d), "
633 "alarm_info->start.month(%d), alarm_info->start.day(%d)",
634 alarm_info->start.year, alarm_info->start.month,
635 alarm_info->start.day);
637 /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
638 if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
639 return ERR_ALARM_INVALID_PARAM;
642 if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
643 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
647 if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
648 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
652 if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
653 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
658 if (!_send_alarm_create_appsvc
659 (alarm_context, alarm_info, alarm_id, b,
664 return ALARMMGR_RESULT_SUCCESS;
670 EXPORT_API int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
671 const char *destination,
672 alarm_id_t *alarm_id)
674 char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
675 char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
676 alarm_info_t *alarm_info; /* = (alarm_info_t*)alarm; */
682 return ERR_ALARM_INVALID_PARAM;
685 alarm_info = (alarm_info_t *) alarm;
686 if (alarm_info == NULL || alarm_id == NULL) {
687 return ERR_ALARM_INVALID_PARAM;
691 alarm_mode_t *mode = &alarm_info->mode;
697 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
699 ALARM_MGR_LOG_PRINT("alarm_info->start.year(%d), "
700 "alarm_info->start.month(%d), alarm_info->start.day(%d)",
701 alarm_info->start.year, alarm_info->start.month,
702 alarm_info->start.day);
704 /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
705 if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
706 return ERR_ALARM_INVALID_PARAM;
709 if (destination && strlen(destination) >= MAX_PKG_NAME_LEN){
710 ALARM_MGR_EXCEPTION_PRINT("[alarm-lib]: destination name is too long!\n");
711 return ERR_ALARM_INVALID_PARAM;
715 if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
716 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
720 if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
721 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
725 if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
726 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
730 if (destination != NULL) {
731 memset(dst_service_name, 0,
732 strlen(destination) + strlen(".ALARM") + 2);
733 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s",
736 memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
740 for(i=0; i<=strlen(dst_service_name); i++)
742 if (dst_service_name[i] == '.' )
744 dst_service_name_mod[j] = dst_service_name[i];
749 dst_service_name_mod[j] = dst_service_name[i];
754 strncat(dst_service_name, ".ALARM", strlen(".ALARM"));
755 strncat(dst_service_name_mod, ".ALARM", strlen(".ALARM"));
757 if (!_send_alarm_create
758 (alarm_context, alarm_info, alarm_id, dst_service_name, dst_service_name_mod,
763 if (!_send_alarm_create
764 (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
768 return ALARMMGR_RESULT_SUCCESS;
773 EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
774 time_t interval, void *bundle_data,
775 alarm_id_t *alarm_id)
779 struct tm duetime_tm;
780 alarm_info_t alarm_info;
781 const char *operation = NULL;
783 bundle *b=(bundle *)bundle_data;
787 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle\n");
788 return ERR_ALARM_INVALID_PARAM;
790 operation = appsvc_get_operation(b);
792 if (NULL == operation)
794 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle [appsvc operation not present]\n");
795 return ERR_ALARM_INVALID_PARAM;
798 if (__alarmmgr_init_appsvc() < 0)
800 ALARM_MGR_EXCEPTION_PRINT("Unable to initialize dbus!!!\n");
801 return ERR_ALARM_SYSTEM_FAIL;
804 ALARM_MGR_LOG_PRINT("interval(%d)", interval);
806 if (alarm_id == NULL) {
807 return ERR_ALARM_INVALID_PARAM;
810 if (trigger_at_time < 0) {
811 return ERR_ALARM_INVALID_PARAM;
814 alarm_info.alarm_type = alarm_type;
815 alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
819 current_time += trigger_at_time;
821 localtime_r(¤t_time, &duetime_tm);
823 alarm_info.start.year = duetime_tm.tm_year + 1900;
824 alarm_info.start.month = duetime_tm.tm_mon + 1;
825 alarm_info.start.day = duetime_tm.tm_mday;
827 alarm_info.end.year = 0;
828 alarm_info.end.month = 0;
829 alarm_info.end.day = 0;
831 alarm_info.start.hour = duetime_tm.tm_hour;
832 alarm_info.start.min = duetime_tm.tm_min;
833 alarm_info.start.sec = duetime_tm.tm_sec;
836 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
837 alarm_info.mode.u_interval.interval = 0;
839 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
840 alarm_info.mode.u_interval.interval = interval;
843 if (!_send_alarm_create_appsvc
844 (alarm_context, &alarm_info, alarm_id, b,
849 return ALARMMGR_RESULT_SUCCESS;
853 EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
854 time_t interval, const char *destination,
855 alarm_id_t *alarm_id)
857 char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
858 char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
863 struct tm duetime_tm;
864 alarm_info_t alarm_info;
871 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
873 ALARM_MGR_LOG_PRINT("interval(%d)", interval);
875 if (alarm_id == NULL) {
876 return ERR_ALARM_INVALID_PARAM;
879 if (trigger_at_time < 0) {
880 return ERR_ALARM_INVALID_PARAM;
883 if (destination && strlen(destination) >= MAX_PKG_NAME_LEN){
884 ALARM_MGR_EXCEPTION_PRINT("[alarm-lib]: destination name is too long!\n");
885 return ERR_ALARM_INVALID_PARAM;
888 alarm_info.alarm_type = alarm_type;
889 alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
893 current_time += trigger_at_time;
895 localtime_r(¤t_time, &duetime_tm);
897 alarm_info.start.year = duetime_tm.tm_year + 1900;
898 alarm_info.start.month = duetime_tm.tm_mon + 1;
899 alarm_info.start.day = duetime_tm.tm_mday;
901 alarm_info.end.year = 0;
902 alarm_info.end.month = 0;
903 alarm_info.end.day = 0;
905 alarm_info.start.hour = duetime_tm.tm_hour;
906 alarm_info.start.min = duetime_tm.tm_min;
907 alarm_info.start.sec = duetime_tm.tm_sec;
910 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
911 alarm_info.mode.u_interval.interval = 0;
913 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
914 alarm_info.mode.u_interval.interval = interval;
917 if (destination != NULL) {
918 memset(dst_service_name, 0,
919 strlen(destination) + strlen(".ALARM") + 2);
920 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s",
922 memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
926 for(i=0;i<=strlen(dst_service_name);i++)
928 if (dst_service_name[i] == '.')
930 dst_service_name_mod[j]=dst_service_name[i];
935 dst_service_name_mod[j]=dst_service_name[i];
940 strncat(dst_service_name, ".ALARM", strlen(".ALARM"));
941 strncat(dst_service_name_mod, ".ALARM", strlen(".ALARM"));
943 if (!_send_alarm_create
944 (alarm_context, &alarm_info, alarm_id, dst_service_name,dst_service_name_mod,
949 if (!_send_alarm_create
950 (alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) {
954 return ALARMMGR_RESULT_SUCCESS;
957 EXPORT_API int alarmmgr_remove_alarm(alarm_id_t alarm_id)
966 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_delete() is called\n");
969 return ERR_ALARM_INVALID_ID;
972 if (!_send_alarm_delete(alarm_context, alarm_id, &error_code))
975 return ALARMMGR_RESULT_SUCCESS;
978 EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
980 GError *error = NULL;
981 GArray *alarm_array = NULL;
990 return ERR_ALARM_INVALID_PARAM;
996 if (!org_tizen_alarm_manager_alarm_get_number_of_ids(
997 alarm_context.proxy, alarm_context.pid, &maxnum_of_ids,
998 &return_code, &error)) {
999 /* dbus-glib error */
1000 /* error_code should be set */
1001 ALARM_MGR_EXCEPTION_PRINT(
1002 "org_tizen_alarm_manager_alarm_get_number_of_ids() "
1003 "failed. return_code[%d], return_code[%s]\n",
1004 return_code, error->message);
1007 if (return_code != 0) {
1011 if (!org_tizen_alarm_manager_alarm_get_list_of_ids(
1012 alarm_context.proxy, alarm_context.pid, maxnum_of_ids,
1013 &alarm_array, &num_of_ids, &return_code, &error)) {
1014 /*dbus-glib error */
1015 /* error_code should be set */
1016 ALARM_MGR_EXCEPTION_PRINT(
1017 "org_tizen_alarm_manager_alarm_get_list_of_ids() "
1018 "failed. alarm_id[%d], return_code[%d]\n",
1019 alarm_id, return_code);
1022 if (return_code != 0) {
1025 for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
1026 alarm_id = g_array_index(alarm_array, alarm_id_t, i);
1027 (*fn) (alarm_id, user_param);
1028 ALARM_MGR_LOG_PRINT(" alarm_id(%d)\n", alarm_id);
1031 g_array_free(alarm_array, true);
1034 return ALARMMGR_RESULT_SUCCESS;
1037 EXPORT_API int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm)
1040 alarm_info_t *alarm_info = (alarm_info_t *) alarm;
1048 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_info() is called\n");
1050 if (alarm_id < 0 || alarm_info == NULL) {
1051 return ERR_ALARM_INVALID_PARAM;
1054 if (!_send_alarm_get_info(alarm_context, alarm_id, alarm_info,
1058 return ALARMMGR_RESULT_SUCCESS;
1061 EXPORT_API int alarmmgr_power_on(bool on_off)
1064 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_on() is called\n");
1067 if (!_send_alarm_power_on(alarm_context, on_off, &error_code))
1070 ALARM_MGR_LOG_PRINT("[alarm-lib]:ALARM_BOOT feature is not supported. "
1071 "so we return false.\n");
1072 return ERR_ALARM_SYSTEM_FAIL;
1075 return ALARMMGR_RESULT_SUCCESS;
1078 int alarmmgr_create(alarm_info_t *alarm_info, char *destination,
1079 alarm_id_t *alarm_id)
1081 char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
1082 alarm_mode_t *mode = &alarm_info->mode;
1085 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
1087 if (alarm_info == NULL || alarm_id == NULL) {
1088 return ERR_ALARM_INVALID_PARAM;
1091 ALARM_MGR_LOG_PRINT("alarm_info->start.year(%d), "
1092 "alarm_info->start.month(%d), alarm_info->start.day(%d)",
1093 alarm_info->start.year, alarm_info->start.month,
1094 alarm_info->start.day);
1096 /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
1097 if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
1098 return ERR_ALARM_INVALID_PARAM;
1101 if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
1102 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
1106 if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
1107 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
1111 if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
1112 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
1116 if (destination != NULL) {
1117 memset(dst_service_name, 0,
1118 strlen(destination) + strlen(".ALARM") + 2);
1119 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s.ALARM",
1121 if (!_send_alarm_create
1122 (alarm_context, alarm_info, alarm_id, dst_service_name,"null",
1127 /*TODO: Currently this API is not exported. Hence not modifying*/
1128 if (!_send_alarm_create
1129 (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
1133 return ALARMMGR_RESULT_SUCCESS;
1137 int alarmmgr_get_number_of_ids(int *num_of_ids)
1140 ALARM_MGR_LOG_PRINT("[alarm-lib]:"
1141 "alarm_get_number_of_ids() is called\n");
1143 if (num_of_ids == NULL) {
1144 return ERR_ALARM_INVALID_PARAM;
1146 ALARM_MGR_LOG_PRINT("call alarm_get_number_of_ids\n");
1147 if (!_send_alarm_get_number_of_ids(alarm_context, num_of_ids,
1151 return ALARMMGR_RESULT_SUCCESS;
1154 int alarmmgr_get_list_of_ids(int maxnum_of_ids, alarm_id_t *alarm_id,
1158 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_list_of_ids() is called\n");
1160 if (maxnum_of_ids < 0 || alarm_id == NULL || num_of_ids == NULL) {
1161 return ERR_ALARM_INVALID_PARAM;
1164 if (maxnum_of_ids == 0) {
1166 return ALARMMGR_RESULT_SUCCESS;
1169 if (!_send_alarm_get_list_of_ids
1170 (alarm_context, maxnum_of_ids, alarm_id, num_of_ids, &error_code))
1173 return ALARMMGR_RESULT_SUCCESS;