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);
555 EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, void *bundle_data, alarm_id_t *alarm_id)
557 alarm_info_t *alarm_info = NULL; /* = (alarm_info_t*)alarm; */
558 const char *operation = NULL;
561 bundle *b=(bundle *)bundle_data;
564 return ERR_ALARM_INVALID_PARAM;
569 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle\n");
570 return ERR_ALARM_INVALID_PARAM;
572 operation = appsvc_get_operation(b);
574 if (NULL == operation)
576 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle [appsvc operation not present]\n");
577 return ERR_ALARM_INVALID_PARAM;
580 if (__alarmmgr_init_appsvc() < 0)
582 ALARM_MGR_EXCEPTION_PRINT("Unable to initialize dbus!!!\n");
583 return ERR_ALARM_SYSTEM_FAIL;
586 alarm_info = (alarm_info_t *) alarm;
588 if (alarm_info == NULL || alarm_id == NULL) {
589 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter\n");
590 return ERR_ALARM_INVALID_PARAM;
592 alarm_mode_t *mode = &alarm_info->mode;
594 ALARM_MGR_LOG_PRINT("alarm_info->start.year(%d), "
595 "alarm_info->start.month(%d), alarm_info->start.day(%d)",
596 alarm_info->start.year, alarm_info->start.month,
597 alarm_info->start.day);
599 /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
600 if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
601 return ERR_ALARM_INVALID_PARAM;
604 if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
605 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
609 if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
610 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
614 if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
615 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
620 if (!_send_alarm_create_appsvc
621 (alarm_context, alarm_info, alarm_id, b,
626 return ALARMMGR_RESULT_SUCCESS;
632 EXPORT_API int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm,
633 const char *destination,
634 alarm_id_t *alarm_id)
636 char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
637 char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
638 alarm_info_t *alarm_info; /* = (alarm_info_t*)alarm; */
644 return ERR_ALARM_INVALID_PARAM;
647 alarm_info = (alarm_info_t *) alarm;
650 alarm_mode_t *mode = &alarm_info->mode;
656 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
658 ALARM_MGR_LOG_PRINT("alarm_info->start.year(%d), "
659 "alarm_info->start.month(%d), alarm_info->start.day(%d)",
660 alarm_info->start.year, alarm_info->start.month,
661 alarm_info->start.day);
663 if (alarm_info == NULL || alarm_id == NULL) {
664 return ERR_ALARM_INVALID_PARAM;
666 /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
667 if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
668 return ERR_ALARM_INVALID_PARAM;
671 if (destination && strlen(destination) >= MAX_PKG_NAME_LEN){
672 ALARM_MGR_EXCEPTION_PRINT("[alarm-lib]: destination name is too long!\n");
673 return ERR_ALARM_INVALID_PARAM;
677 if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
678 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
682 if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
683 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
687 if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
688 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
692 if (destination != NULL) {
693 memset(dst_service_name, 0,
694 strlen(destination) + strlen(".ALARM") + 2);
695 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s",
698 memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
702 for(i=0; i<=strlen(dst_service_name); i++)
704 if (dst_service_name[i] == '.' )
706 dst_service_name_mod[j] = dst_service_name[i];
711 dst_service_name_mod[j] = dst_service_name[i];
716 strncat(dst_service_name, ".ALARM", strlen(".ALARM"));
717 strncat(dst_service_name_mod, ".ALARM", strlen(".ALARM"));
719 if (!_send_alarm_create
720 (alarm_context, alarm_info, alarm_id, dst_service_name, dst_service_name_mod,
725 if (!_send_alarm_create
726 (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
730 return ALARMMGR_RESULT_SUCCESS;
735 EXPORT_API int alarmmgr_add_alarm_appsvc(int alarm_type, time_t trigger_at_time,
736 time_t interval, void *bundle_data,
737 alarm_id_t *alarm_id)
741 struct tm duetime_tm;
742 alarm_info_t alarm_info;
743 const char *operation = NULL;
745 bundle *b=(bundle *)bundle_data;
749 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle\n");
750 return ERR_ALARM_INVALID_PARAM;
752 operation = appsvc_get_operation(b);
754 if (NULL == operation)
756 ALARM_MGR_EXCEPTION_PRINT("Invalid parameter bundle [appsvc operation not present]\n");
757 return ERR_ALARM_INVALID_PARAM;
760 if (__alarmmgr_init_appsvc() < 0)
762 ALARM_MGR_EXCEPTION_PRINT("Unable to initialize dbus!!!\n");
763 return ERR_ALARM_SYSTEM_FAIL;
766 ALARM_MGR_LOG_PRINT("interval(%d)", interval);
768 if (alarm_id == NULL) {
769 return ERR_ALARM_INVALID_PARAM;
772 if (trigger_at_time < 0) {
773 return ERR_ALARM_INVALID_PARAM;
776 alarm_info.alarm_type = alarm_type;
777 alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
781 current_time += trigger_at_time;
783 localtime_r(¤t_time, &duetime_tm);
785 alarm_info.start.year = duetime_tm.tm_year + 1900;
786 alarm_info.start.month = duetime_tm.tm_mon + 1;
787 alarm_info.start.day = duetime_tm.tm_mday;
789 alarm_info.end.year = 0;
790 alarm_info.end.month = 0;
791 alarm_info.end.day = 0;
793 alarm_info.start.hour = duetime_tm.tm_hour;
794 alarm_info.start.min = duetime_tm.tm_min;
795 alarm_info.start.sec = duetime_tm.tm_sec;
798 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
799 alarm_info.mode.u_interval.interval = 0;
801 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
802 alarm_info.mode.u_interval.interval = interval;
805 if (!_send_alarm_create_appsvc
806 (alarm_context, &alarm_info, alarm_id, b,
811 return ALARMMGR_RESULT_SUCCESS;
815 EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time,
816 time_t interval, const char *destination,
817 alarm_id_t *alarm_id)
819 char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
820 char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 };
825 struct tm duetime_tm;
826 alarm_info_t alarm_info;
833 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
835 ALARM_MGR_LOG_PRINT("interval(%d)", interval);
837 if (alarm_id == NULL) {
838 return ERR_ALARM_INVALID_PARAM;
841 if (trigger_at_time < 0) {
842 return ERR_ALARM_INVALID_PARAM;
845 if (destination && strlen(destination) >= MAX_PKG_NAME_LEN){
846 ALARM_MGR_EXCEPTION_PRINT("[alarm-lib]: destination name is too long!\n");
847 return ERR_ALARM_INVALID_PARAM;
850 alarm_info.alarm_type = alarm_type;
851 alarm_info.alarm_type |= ALARM_TYPE_RELATIVE;
855 current_time += trigger_at_time;
857 localtime_r(¤t_time, &duetime_tm);
859 alarm_info.start.year = duetime_tm.tm_year + 1900;
860 alarm_info.start.month = duetime_tm.tm_mon + 1;
861 alarm_info.start.day = duetime_tm.tm_mday;
863 alarm_info.end.year = 0;
864 alarm_info.end.month = 0;
865 alarm_info.end.day = 0;
867 alarm_info.start.hour = duetime_tm.tm_hour;
868 alarm_info.start.min = duetime_tm.tm_min;
869 alarm_info.start.sec = duetime_tm.tm_sec;
872 alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE;
873 alarm_info.mode.u_interval.interval = 0;
875 alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT;
876 alarm_info.mode.u_interval.interval = interval;
879 if (destination != NULL) {
880 memset(dst_service_name, 0,
881 strlen(destination) + strlen(".ALARM") + 2);
882 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s",
884 memset(dst_service_name_mod,'a',MAX_SERVICE_NAME_LEN-1);
888 for(i=0;i<=strlen(dst_service_name);i++)
890 if (dst_service_name[i] == '.')
892 dst_service_name_mod[j]=dst_service_name[i];
897 dst_service_name_mod[j]=dst_service_name[i];
902 strncat(dst_service_name, ".ALARM", strlen(".ALARM"));
903 strncat(dst_service_name_mod, ".ALARM", strlen(".ALARM"));
905 if (!_send_alarm_create
906 (alarm_context, &alarm_info, alarm_id, dst_service_name,dst_service_name_mod,
911 if (!_send_alarm_create
912 (alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) {
916 return ALARMMGR_RESULT_SUCCESS;
919 EXPORT_API int alarmmgr_remove_alarm(alarm_id_t alarm_id)
928 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_delete() is called\n");
931 return ERR_ALARM_INVALID_ID;
934 if (!_send_alarm_delete(alarm_context, alarm_id, &error_code))
937 return ALARMMGR_RESULT_SUCCESS;
940 EXPORT_API int alarmmgr_enum_alarm_ids(alarm_enum_fn_t fn, void *user_param)
942 GError *error = NULL;
943 GArray *alarm_array = NULL;
952 return ERR_ALARM_INVALID_PARAM;
958 if (!org_tizen_alarm_manager_alarm_get_number_of_ids(
959 alarm_context.proxy, alarm_context.pid, &maxnum_of_ids,
960 &return_code, &error)) {
961 /* dbus-glib error */
962 /* error_code should be set */
963 ALARM_MGR_EXCEPTION_PRINT(
964 "org_tizen_alarm_manager_alarm_get_number_of_ids() "
965 "failed. return_code[%d], return_code[%s]\n",
966 return_code, error->message);
969 if (return_code != 0) {
973 if (!org_tizen_alarm_manager_alarm_get_list_of_ids(
974 alarm_context.proxy, alarm_context.pid, maxnum_of_ids,
975 &alarm_array, &num_of_ids, &return_code, &error)) {
977 /* error_code should be set */
978 ALARM_MGR_EXCEPTION_PRINT(
979 "org_tizen_alarm_manager_alarm_get_list_of_ids() "
980 "failed. alarm_id[%d], return_code[%d]\n",
981 alarm_id, return_code);
984 if (return_code != 0) {
987 for (i = 0; i < alarm_array->len && i < maxnum_of_ids; i++) {
988 alarm_id = g_array_index(alarm_array, alarm_id_t, i);
989 (*fn) (alarm_id, user_param);
990 ALARM_MGR_LOG_PRINT(" alarm_id(%d)\n", alarm_id);
993 g_array_free(alarm_array, true);
996 return ALARMMGR_RESULT_SUCCESS;
999 EXPORT_API int alarmmgr_get_info(alarm_id_t alarm_id, alarm_entry_t *alarm)
1002 alarm_info_t *alarm_info = (alarm_info_t *) alarm;
1010 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_info() is called\n");
1012 if (alarm_id < 0 || alarm_info == NULL) {
1013 return ERR_ALARM_INVALID_PARAM;
1016 if (!_send_alarm_get_info(alarm_context, alarm_id, alarm_info,
1020 return ALARMMGR_RESULT_SUCCESS;
1023 EXPORT_API int alarmmgr_power_on(bool on_off)
1026 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_power_on() is called\n");
1029 if (!_send_alarm_power_on(alarm_context, on_off, &error_code))
1032 ALARM_MGR_LOG_PRINT("[alarm-lib]:ALARM_BOOT feature is not supported. "
1033 "so we return false.\n");
1034 return ERR_ALARM_SYSTEM_FAIL;
1037 return ALARMMGR_RESULT_SUCCESS;
1040 int alarmmgr_create(alarm_info_t *alarm_info, char *destination,
1041 alarm_id_t *alarm_id)
1043 char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 };
1044 alarm_mode_t *mode = &alarm_info->mode;
1047 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_create() is called\n");
1049 if (alarm_info == NULL || alarm_id == NULL) {
1050 return ERR_ALARM_INVALID_PARAM;
1053 ALARM_MGR_LOG_PRINT("alarm_info->start.year(%d), "
1054 "alarm_info->start.month(%d), alarm_info->start.day(%d)",
1055 alarm_info->start.year, alarm_info->start.month,
1056 alarm_info->start.day);
1058 /* TODO: This should be changed to > ALARM_REPEAT_MODE_MAX ? */
1059 if (mode->repeat >= ALARM_REPEAT_MODE_MAX) {
1060 return ERR_ALARM_INVALID_PARAM;
1063 if (!__alarm_validate_date(&alarm_info->start, &error_code)) {
1064 ALARM_MGR_EXCEPTION_PRINT("start date error\n");
1068 if (!__alarm_validate_time(&alarm_info->start, &error_code)) {
1069 ALARM_MGR_EXCEPTION_PRINT("start time error\n");
1073 if (!__alarm_validate_date(&alarm_info->end, &error_code)) {
1074 ALARM_MGR_EXCEPTION_PRINT("end date error\n");
1078 if (destination != NULL) {
1079 memset(dst_service_name, 0,
1080 strlen(destination) + strlen(".ALARM") + 2);
1081 snprintf(dst_service_name, MAX_SERVICE_NAME_LEN, "%s.ALARM",
1083 if (!_send_alarm_create
1084 (alarm_context, alarm_info, alarm_id, dst_service_name,"null",
1089 /*TODO: Currently this API is not exported. Hence not modifying*/
1090 if (!_send_alarm_create
1091 (alarm_context, alarm_info, alarm_id, "null", "null", &error_code)) {
1095 return ALARMMGR_RESULT_SUCCESS;
1099 int alarmmgr_get_number_of_ids(int *num_of_ids)
1102 ALARM_MGR_LOG_PRINT("[alarm-lib]:"
1103 "alarm_get_number_of_ids() is called\n");
1105 if (num_of_ids == NULL) {
1106 return ERR_ALARM_INVALID_PARAM;
1108 ALARM_MGR_LOG_PRINT("call alarm_get_number_of_ids\n");
1109 if (!_send_alarm_get_number_of_ids(alarm_context, num_of_ids,
1113 return ALARMMGR_RESULT_SUCCESS;
1116 int alarmmgr_get_list_of_ids(int maxnum_of_ids, alarm_id_t *alarm_id,
1120 ALARM_MGR_LOG_PRINT("[alarm-lib]:alarm_get_list_of_ids() is called\n");
1122 if (maxnum_of_ids < 0 || alarm_id == NULL || num_of_ids == NULL) {
1123 return ERR_ALARM_INVALID_PARAM;
1126 if (maxnum_of_ids == 0) {
1128 return ALARMMGR_RESULT_SUCCESS;
1131 if (!_send_alarm_get_list_of_ids
1132 (alarm_context, maxnum_of_ids, alarm_id, num_of_ids, &error_code))
1135 return ALARMMGR_RESULT_SUCCESS;