diff options
author | Jaeho Lee <jaeho81.lee@samsung.com> | 2013-05-06 16:09:27 +0900 |
---|---|---|
committer | Jaeho Lee <jaeho81.lee@samsung.com> | 2013-05-06 16:09:27 +0900 |
commit | fbcdc2791644e370679097bac88da22cb375beef (patch) | |
tree | a98357b31cb1404ee51e5107c553d5635bda87be | |
parent | 5361bf5dfdbd74d0ebd35d83251f8fd81d6440a7 (diff) | |
parent | 47b76815ba51b77284e2c75d75ccffa27ca84a12 (diff) | |
download | alarm-manager-tizen_2.1.tar.gz alarm-manager-tizen_2.1.tar.bz2 alarm-manager-tizen_2.1.zip |
Merge branch 'master' into tizen_2.1submit/tizen_2.1/20130514.050845submit/tizen/20130517.044749accepted/tizen/20130520.100857tizen_2.1
Conflicts:
packaging/alarm-manager.spec
added new API
Signed-off-by: Jaeho Lee <jaeho81.lee@samsung.com>
-rwxr-xr-x | alarm-lib.c | 145 | ||||
-rwxr-xr-x | alarm-manager.c | 5 | ||||
-rwxr-xr-x | include/alarm-internal.h | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | include/alarm.h | 2 | ||||
-rwxr-xr-x | packaging/alarm-manager.spec | 2 |
5 files changed, 154 insertions, 2 deletions
diff --git a/alarm-lib.c b/alarm-lib.c index d2deab5..1d8e1d7 100755 --- a/alarm-lib.c +++ b/alarm-lib.c @@ -41,6 +41,7 @@ #include "alarm-stub.h" #include <bundle.h> #include <appsvc.h> +#include <aul.h> #define MAX_KEY_SIZE 256 @@ -62,12 +63,74 @@ static int __alarmmgr_init_appsvc(void); bool alarm_power_off(int *error_code); int alarmmgr_check_next_duetime(void); +typedef struct _alarm_cb_info_t { + int alarm_id; + alarm_cb_t cb_func; + void *priv_data; + struct _alarm_cb_info_t *next; +} alarm_cb_info_t; +static alarm_cb_info_t *alarmcb_head = NULL; + +static void __add_resultcb(int alarm_id, alarm_cb_t cb_func, + void *data) +{ + alarm_cb_info_t *info; + + info = (alarm_cb_info_t *) malloc(sizeof(alarm_cb_info_t)); + if(info == NULL) + return; + info->alarm_id = alarm_id; + info->cb_func = cb_func; + info->priv_data = data; + + info->next = alarmcb_head; + alarmcb_head = info; +} + +static alarm_cb_info_t *__find_resultcb(int alarm_id) +{ + alarm_cb_info_t *tmp; + + tmp = alarmcb_head; + while (tmp) { + if (tmp->alarm_id == alarm_id) + return tmp; + tmp = tmp->next; + } + return NULL; +} + +static void __remove_resultcb(alarm_cb_info_t *info) +{ + alarm_cb_info_t *tmp; + + if (alarmcb_head == NULL || info == NULL) + return; + + if (alarmcb_head == info) { + alarmcb_head = info->next; + free(info); + return; + } + + tmp = alarmcb_head; + while (tmp) { + if (tmp->next == info) { + tmp->next = info->next; + free(info); + return; + } + tmp = tmp->next; + } +} static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection, DBusMessage *message, void *user_data) { + alarm_cb_info_t *info; + if (dbus_message_get_type(message) == DBUS_MESSAGE_TYPE_METHOD_CALL) { const char *method_name = dbus_message_get_member(message); /*"alarm_expired" */ @@ -100,12 +163,18 @@ static DBusHandlerResult __expire_alarm_filter(DBusConnection *connection, /* alarm_context.alarm_handler(alarm_id); */ alarm_context.alarm_handler(alarm_id, alarm_context.user_param); + info = __find_resultcb(alarm_id); + + if( info && info->cb_func ) { + info->cb_func(alarm_id, info->priv_data); + // __remove_resultcb(info); + } + return DBUS_HANDLER_RESULT_HANDLED; } } return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; - } static int __alarm_validate_date(alarm_date_t *date, int *error_code) @@ -972,10 +1041,81 @@ EXPORT_API int alarmmgr_add_alarm(int alarm_type, time_t trigger_at_time, return ALARMMGR_RESULT_SUCCESS; } +EXPORT_API int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time, + time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id) +{ + char dst_service_name[MAX_SERVICE_NAME_LEN] = { 0 }; + char dst_service_name_mod[MAX_SERVICE_NAME_LEN] = { 0 }; + int i = 0; + int j = 0; + int error_code; + time_t current_time; + struct tm duetime_tm; + alarm_info_t alarm_info; + int ret; + char appid[256]; + + aul_app_get_appid_bypid(getpid(), appid, sizeof(appid)); + + ret = alarmmgr_init(appid); + if (ret < 0) + return ret; + + ALARM_MGR_LOG_PRINT("[alarm-lib]:alarmmgr_add_alarm_withcb() is called\n"); + + ALARM_MGR_LOG_PRINT("interval(%d)", interval); + + if (alarm_id == NULL) { + return ERR_ALARM_INVALID_PARAM; + } + + if (trigger_at_time < 0) { + return ERR_ALARM_INVALID_PARAM; + } + + alarm_info.alarm_type = alarm_type; + alarm_info.alarm_type |= ALARM_TYPE_RELATIVE; + alarm_info.alarm_type |= ALARM_TYPE_WITHCB; + + time(¤t_time); + + current_time += trigger_at_time; + + localtime_r(¤t_time, &duetime_tm); + + alarm_info.start.year = duetime_tm.tm_year + 1900; + alarm_info.start.month = duetime_tm.tm_mon + 1; + alarm_info.start.day = duetime_tm.tm_mday; + + alarm_info.end.year = 0; + alarm_info.end.month = 0; + alarm_info.end.day = 0; + + alarm_info.start.hour = duetime_tm.tm_hour; + alarm_info.start.min = duetime_tm.tm_min; + alarm_info.start.sec = duetime_tm.tm_sec; + + if (interval <= 0) { + alarm_info.mode.repeat = ALARM_REPEAT_MODE_ONCE; + alarm_info.mode.u_interval.interval = 0; + } else { + alarm_info.mode.repeat = ALARM_REPEAT_MODE_REPEAT; + alarm_info.mode.u_interval.interval = interval; + } + + if (!_send_alarm_create(alarm_context, &alarm_info, alarm_id, "null","null", &error_code)) { + return error_code; + } + __add_resultcb(*alarm_id, handler, user_param); + + return ALARMMGR_RESULT_SUCCESS; +} + EXPORT_API int alarmmgr_remove_alarm(alarm_id_t alarm_id) { int error_code; int ret; + alarm_cb_info_t *info; ret = __sub_init(); if (ret < 0) @@ -990,6 +1130,9 @@ EXPORT_API int alarmmgr_remove_alarm(alarm_id_t alarm_id) if (!_send_alarm_delete(alarm_context, alarm_id, &error_code)) return error_code; + info = __find_resultcb(alarm_id); + __remove_resultcb(info); + return ALARMMGR_RESULT_SUCCESS; } diff --git a/alarm-manager.c b/alarm-manager.c index b9af14f..951b96b 100755 --- a/alarm-manager.c +++ b/alarm-manager.c @@ -1486,6 +1486,11 @@ static void __alarm_expired() char appid[MAX_SERVICE_NAME_LEN] = { 0, }; char alarm_id_str[32] = { 0, }; + if (__alarm_info->alarm_info.alarm_type & ALARM_TYPE_WITHCB) { + __alarm_remove_from_list(__alarm_info->pid, alarm_id, NULL); + goto done; + } + expire_info = malloc(sizeof(__expired_alarm_t)); if (G_UNLIKELY(NULL == expire_info)){ ALARM_MGR_ASSERT_PRINT("[alarm-server]:Malloc failed!Can't notify alarm expiry info\n"); diff --git a/include/alarm-internal.h b/include/alarm-internal.h index 307ebf8..33a588e 100755 --- a/include/alarm-internal.h +++ b/include/alarm-internal.h @@ -104,6 +104,8 @@ typedef enum }alarm_type_t; */ #define ALARM_TYPE_RELATIVE 0x80000000 /**< relative */ +#define ALARM_TYPE_WITHCB 0x40000000 /**< withcb */ + /** * This struct has the information of an alarm diff --git a/include/alarm.h b/include/alarm.h index d58e8b0..ee1a27e 100644..100755 --- a/include/alarm.h +++ b/include/alarm.h @@ -1357,6 +1357,8 @@ int main(int argc,char **argv { */ int alarmmgr_set_rtc_time(alarm_date_t *time); +int alarmmgr_add_alarm_withcb(int alarm_type, time_t trigger_at_time, + time_t interval, alarm_cb_t handler, void *user_param, alarm_id_t *alarm_id); /** * @} diff --git a/packaging/alarm-manager.spec b/packaging/alarm-manager.spec index d62a29b..7ee7d8c 100755 --- a/packaging/alarm-manager.spec +++ b/packaging/alarm-manager.spec @@ -1,6 +1,6 @@ Name: alarm-manager Summary: Alarm library -Version: 0.4.69 +Version: 0.4.70 Release: 1 Group: System/Libraries License: Apache License, Version 2.0 |