diff options
author | Jiwoong Im <jiwoong.im@samsung.com> | 2015-05-27 11:06:55 +0900 |
---|---|---|
committer | Jiwoong Im <jiwoong.im@samsung.com> | 2015-05-29 11:38:47 +0900 |
commit | 92347d23b966073f61e210b2ea6ba35bb596df91 (patch) | |
tree | 95d4e980ea8ed8bc47047ca16d1ae602ffd187b2 | |
parent | 30092aebab638aeeef491a92801f71f658f66e6a (diff) | |
download | application-92347d23b966073f61e210b2ea6ba35bb596df91.tar.gz application-92347d23b966073f61e210b2ea6ba35bb596df91.tar.bz2 application-92347d23b966073f61e210b2ea6ba35bb596df91.zip |
add the new APIS for alarm
- alarm_schedule_once_after_delay
- alarm_schedule_once_at_date
Change-Id: Iab54567af28aa11a8b5cb88da80f98ab2fe97c42
Signed-off-by: Jiwoong Im <jiwoong.im@samsung.com>
-rwxr-xr-x | alarm/alarm.c | 82 | ||||
-rwxr-xr-x | include/app_alarm.h | 56 |
2 files changed, 138 insertions, 0 deletions
diff --git a/alarm/alarm.c b/alarm/alarm.c index 374fd04..6ef1f17 100755 --- a/alarm/alarm.c +++ b/alarm/alarm.c @@ -281,6 +281,88 @@ int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int perio alarmmgr_free_alarm(alarm_info); return ALARM_ERROR_NONE; } +int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *alarm_id) +{ + bundle *bundle_data; + int result = 0; + + if (app_control == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + result = alarmmgr_add_alarm_appsvc(ALARM_TYPE_DEFAULT, delay, 0, bundle_data, alarm_id); + + return convert_error_code_to_alarm(__FUNCTION__, result); +} + +int alarm_schedule_once_at_date(app_control_h app_control, struct tm *date, int *alarm_id) +{ + alarm_date_t internal_time; + alarm_entry_t* alarm_info; + bundle *bundle_data; + int result; + + if (app_control == NULL || date == NULL) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + if (app_control_to_bundle(app_control, &bundle_data) != APP_CONTROL_ERROR_NONE) { + LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); + return ALARM_ERROR_INVALID_PARAMETER; + } + + alarm_info = alarmmgr_create_alarm(); + if (alarm_info == NULL) { + LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY); + return ALARM_ERROR_OUT_OF_MEMORY; + } + + internal_time.year = date->tm_year + 1900; + internal_time.month = date->tm_mon + 1; + internal_time.day = date->tm_mday; + + internal_time.hour = date->tm_hour; + internal_time.min = date->tm_min; + internal_time.sec = date->tm_sec; + + result = alarmmgr_set_time(alarm_info, internal_time); + + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, 0); + + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_set_type(alarm_info, ALARM_TYPE_DEFAULT); + + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + result = alarmmgr_add_alarm_appsvc_with_localtime(alarm_info, bundle_data, alarm_id); + + if (result < 0) { + alarmmgr_free_alarm(alarm_info); + return convert_error_code_to_alarm(__FUNCTION__, result); + } + + alarmmgr_free_alarm(alarm_info); + return ALARM_ERROR_NONE; +} int alarm_cancel(int alarm_id) { diff --git a/include/app_alarm.h b/include/app_alarm.h index 7b3ad0a..c61d2b1 100755 --- a/include/app_alarm.h +++ b/include/app_alarm.h @@ -129,6 +129,62 @@ int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int perio /** + * @brief Sets an alarm to be triggered after a specific time. + * @details The alarm will go off @a delay seconds later. + * To cancel the alarm, call alarm_cancel() with @a alarm_id. + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/alarm.set + * @remarks If the application is uninstalled after setting an alarm, the alarm is cancelled automatically. + * + * @param[in] app_control The destination app_control to perform a specific task when the alarm is triggered + * @param[in] delay The amount of time before the execution (in seconds) + * @param[out] alarm_id The alarm ID that uniquely identifies an alarm + * @return @c 0 on success, + * otherwise a negative error value + * @retval #ALARM_ERROR_NONE Successful + * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ALARM_ERROR_INVALID_TIME Triggered time is invalid + * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server + * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied + * @see alarm_cancel() + * @see alarm_cancel_all() + * @see alarm_get_scheduled_date() + * @see alarm_get_scheduled_period() + */ +int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *alarm_id); + + +/** + * @brief Sets an alarm to be triggered at a specific time. + * @details The @a date describes the time of the first occurrence. + * To cancel the alarm, call alarm_cancel() with @a alarm_id. + * @since_tizen 2.4 + * @privlevel public + * @privilege %http://tizen.org/privilege/alarm.set + * @remarks If application is uninstalled after setting an alarm, the alarm is cancelled automatically. + * If the operation of @a app_control is not specified, #APP_CONTROL_OPERATION_DEFAULT is used for the launch request. + * If the operation of @a app_control is #APP_CONTROL_OPERATION_DEFAULT, the package information is mandatory to explicitly launch the application. + * + * @param[in] app_control The destination app_control to perform specific work when the alarm is triggered + * @param[in] date The first active alarm time + * @param[out] alarm_id The alarm ID that uniquely identifies an alarm + * @return @c 0 on success, + * otherwise a negative error value + * @retval #ALARM_ERROR_NONE Successful + * @retval #ALARM_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #ALARM_ERROR_INVALID_DATE Triggered date is invalid + * @retval #ALARM_ERROR_CONNECTION_FAIL Failed to connect to an alarm server + * @retval #ALARM_ERROR_PERMISSION_DENIED Permission denied + * @see alarm_cancel() + * @see alarm_cancel_all() + * @see alarm_get_scheduled_date() + * @see alarm_get_scheduled_period() + */ +int alarm_schedule_once_at_date(app_control_h app_control, struct tm *date, int *alarm_id); + + +/** * @brief Sets an alarm to be triggered at a specific time with recurrence repeat. * @details * The @a date describes the time of first occurrence. |