diff options
author | Inkyun Kil <inkyun.kil@samsung.com> | 2022-07-15 10:13:16 +0900 |
---|---|---|
committer | Inkyun Kil <inkyun.kil@samsung.com> | 2022-07-18 13:35:07 +0900 |
commit | aaddd80e049dbc28e39b2b019745264b998246e9 (patch) | |
tree | cad7702f619fb664e62e8fd654d4b8a777269882 | |
parent | 71a8b3b0646647efe1a9b5037e2508c921595857 (diff) | |
download | alarm-aaddd80e049dbc28e39b2b019745264b998246e9.tar.gz alarm-aaddd80e049dbc28e39b2b019745264b998246e9.tar.bz2 alarm-aaddd80e049dbc28e39b2b019745264b998246e9.zip |
Improve duplicated code
- Reduce duplicated codes
- Remove unnecessary memory allocation
Change-Id: I3ae0ebd37733693e445467f9c246ee001d24a4a0
Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
-rwxr-xr-x | src/alarm.c | 574 |
1 files changed, 105 insertions, 469 deletions
diff --git a/src/alarm.c b/src/alarm.c index b98da51..7c24dd5 100755 --- a/src/alarm.c +++ b/src/alarm.c @@ -106,6 +106,37 @@ static int convert_error_code_to_alarm(const char *function, alarm_error_t alarm } /* LCOV_EXCL_STOP */ +static int __set_alarm_info(alarm_entry_t *alarm_info, struct tm *date, + alarm_repeat_mode_t repeat_mode, int repeat_period, int type) +{ + alarm_date_t internal_time; + int result = ALARM_ERROR_NONE; + + 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) + return result; + + if (repeat_period > 0) + result = alarmmgr_set_repeat_mode(alarm_info, repeat_mode, repeat_period); + + if (result < 0) + return result; + + result = alarmmgr_set_type(alarm_info, type); + if (result < 0) + return result; + + return result; +} + int alarm_get_scheduled_date(int alarm_id, struct tm *date) { alarm_error_t result; @@ -128,7 +159,7 @@ int alarm_get_scheduled_date(int alarm_id, struct tm *date) int alarm_get_scheduled_period(int alarm_id, int *period) { alarm_error_t result; - alarm_entry_t *entry = NULL; + alarm_entry_t entry = {0,}; alarm_repeat_mode_t mode; int value; @@ -137,25 +168,13 @@ int alarm_get_scheduled_period(int alarm_id, int *period) return ALARM_ERROR_INVALID_PARAMETER; } - entry = alarmmgr_create_alarm(); - - result = alarmmgr_get_info(alarm_id, entry); - if (result != ALARMMGR_RESULT_SUCCESS) { - if (entry != NULL) - alarmmgr_free_alarm(entry); - + result = alarmmgr_get_info(alarm_id, &entry); + if (result != ALARMMGR_RESULT_SUCCESS) return convert_error_code_to_alarm(__FUNCTION__, result); - } - - result = alarmmgr_get_repeat_mode(entry, &mode, &value); - if (result != ALARMMGR_RESULT_SUCCESS) { - if (entry != NULL) - alarmmgr_free_alarm(entry); + result = alarmmgr_get_repeat_mode(&entry, &mode, &value); + if (result != ALARMMGR_RESULT_SUCCESS) return convert_error_code_to_alarm(__FUNCTION__, result); - } - - alarmmgr_free_alarm(entry); (*period) = value; @@ -167,12 +186,8 @@ int alarm_schedule_after_delay(app_control_h app_control, int delay, int period, 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) { + if (app_control == NULL || + 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; } @@ -196,66 +211,36 @@ int alarm_schedule_noti_after_delay(notification_h noti, int delay, int period, return convert_error_code_to_alarm(__FUNCTION__, result); } -int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int period_in_second, int *alarm_id) +static int __add_alarm_appsvc_with_localtime(app_control_h app_control, + struct tm *date, alarm_repeat_mode_t repeat_mode, int repeat_value, + int alarm_type, int *alarm_id) { - dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: alarm_schedule_at_date() is deprecated and will be removed from next release. Use alarm_schedule_once_at_date() instead."); - alarm_date_t internal_time; - alarm_entry_t *alarm_info; + alarm_entry_t alarm_info = {0,}; 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) { + if (app_control == NULL || date == NULL || + 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(); - - 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); + result = __set_alarm_info(&alarm_info, date, repeat_mode, repeat_value, alarm_type); + if (result < 0) return convert_error_code_to_alarm(__FUNCTION__, result); - } + result = alarmmgr_add_alarm_appsvc_with_localtime(&alarm_info, bundle_data, alarm_id); + if (result < 0) + return convert_error_code_to_alarm(__FUNCTION__, result); - if (period_in_second > 0) - result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_REPEAT, period_in_second); - else - result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_ONCE, period_in_second); - - 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); - } + return ALARM_ERROR_NONE; +} - 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); - } +int alarm_schedule_at_date(app_control_h app_control, struct tm *date, int period_in_second, int *alarm_id) +{ + dlog_print(DLOG_WARN, LOG_TAG, "DEPRECATION WARNING: alarm_schedule_at_date() is deprecated and will be removed from next release. Use alarm_schedule_once_at_date() instead."); - alarmmgr_free_alarm(alarm_info); - return ALARM_ERROR_NONE; + return __add_alarm_appsvc_with_localtime(app_control, date, ALARM_REPEAT_MODE_REPEAT, period_in_second, ALARM_TYPE_DEFAULT, alarm_id); } int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *alarm_id) @@ -263,12 +248,8 @@ int alarm_schedule_once_after_delay(app_control_h app_control, int delay, int *a 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) { + if (app_control == NULL || + 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; } @@ -294,70 +275,13 @@ int alarm_schedule_noti_once_after_delay(notification_h noti, int delay, int *al 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) { - /* LCOV_EXCL_START */ - LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY); - return ALARM_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - - 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; + return __add_alarm_appsvc_with_localtime(app_control, date, ALARM_REPEAT_MODE_ONCE, 0, ALARM_TYPE_DEFAULT, alarm_id); } -int alarm_schedule_noti_once_at_date(notification_h noti, struct tm *date, int *alarm_id) +static int __alarm_noti_with_local_time(alarm_repeat_mode_t mode, int value, + notification_h noti, struct tm *date, int *alarm_id) { - alarm_date_t internal_time; - alarm_entry_t *alarm_info; + alarm_entry_t alarm_info = {0,}; int result; if (noti == NULL || date == NULL) { @@ -365,50 +289,22 @@ int alarm_schedule_noti_once_at_date(notification_h noti, struct tm *date, int * return ALARM_ERROR_INVALID_PARAMETER; } - alarm_info = alarmmgr_create_alarm(); - if (alarm_info == NULL) { - /* LCOV_EXCL_START */ - LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY); - return ALARM_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - - 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 = __set_alarm_info(&alarm_info, date, mode, value, ALARM_TYPE_DEFAULT); + if (result < 0) + return convert_error_code_to_alarm(__FUNCTION__, result); - result = alarmmgr_add_alarm_noti_with_localtime(alarm_info, noti, alarm_id); - if (result < 0) { - alarmmgr_free_alarm(alarm_info); - return convert_error_code_to_alarm(__FUNCTION__, result); - } + result = alarmmgr_add_alarm_noti_with_localtime(&alarm_info, noti, alarm_id); + if (result < 0) + return convert_error_code_to_alarm(__FUNCTION__, result); - alarmmgr_free_alarm(alarm_info); return ALARM_ERROR_NONE; } +int alarm_schedule_noti_once_at_date(notification_h noti, struct tm *date, int *alarm_id) +{ + return __alarm_noti_with_local_time(ALARM_REPEAT_MODE_ONCE, 0, noti, date, alarm_id); +} + int alarm_cancel(int alarm_id) { int result; @@ -465,108 +361,18 @@ int alarm_get_current_time(struct tm *date) int alarm_schedule_with_recurrence_week_flag(app_control_h app_control, struct tm *date, int week_flag, 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(); - - 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); - } - - if (week_flag > 0) { - result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag); - 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); - alarmmgr_free_alarm(alarm_info); - - return convert_error_code_to_alarm(__FUNCTION__, result); + return __add_alarm_appsvc_with_localtime(app_control, date, ALARM_REPEAT_MODE_WEEKLY, week_flag, ALARM_TYPE_DEFAULT, alarm_id); } int alarm_schedule_noti_with_recurrence_week_flag(notification_h noti, struct tm *date, int week_flag, int *alarm_id) { - alarm_date_t internal_time; - alarm_entry_t *alarm_info; - int result; - - if (noti == NULL || date == NULL) { - LOGE("INVALID_PARAMETER(0x%08x)", ALARM_ERROR_INVALID_PARAMETER); - return ALARM_ERROR_INVALID_PARAMETER; - } - - alarm_info = alarmmgr_create_alarm(); - - 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); - } - - if (week_flag > 0) - result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag); - - 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_noti_with_localtime(alarm_info, noti, alarm_id); - alarmmgr_free_alarm(alarm_info); - - return convert_error_code_to_alarm(__FUNCTION__, result); + return __alarm_noti_with_local_time(ALARM_REPEAT_MODE_WEEKLY, week_flag, noti, date, alarm_id); } int alarm_get_scheduled_recurrence_week_flag(int alarm_id, int *week_flag) { alarm_error_t result; - alarm_entry_t *entry = NULL; + alarm_entry_t entry = {0,}; alarm_repeat_mode_t mode; int value; @@ -575,33 +381,17 @@ int alarm_get_scheduled_recurrence_week_flag(int alarm_id, int *week_flag) return ALARM_ERROR_INVALID_PARAMETER; } - entry = alarmmgr_create_alarm(); - - result = alarmmgr_get_info(alarm_id, entry); - if (result != ALARMMGR_RESULT_SUCCESS) { - if (entry != NULL) - alarmmgr_free_alarm(entry); - + result = alarmmgr_get_info(alarm_id, &entry); + if (result != ALARMMGR_RESULT_SUCCESS) return convert_error_code_to_alarm(__FUNCTION__, result); - } - result = alarmmgr_get_repeat_mode(entry, &mode, &value); - - if (mode != ALARM_REPEAT_MODE_WEEKLY) { - if (entry != NULL) - alarmmgr_free_alarm(entry); + result = alarmmgr_get_repeat_mode(&entry, &mode, &value); + if (mode != ALARM_REPEAT_MODE_WEEKLY) return ALARM_ERROR_INVALID_PARAMETER; - } - - if (result != ALARMMGR_RESULT_SUCCESS) { - if (entry != NULL) - alarmmgr_free_alarm(entry); - return convert_error_code_to_alarm(__FUNCTION__, result); - } - - alarmmgr_free_alarm(entry); + if (result != ALARMMGR_RESULT_SUCCESS) + return convert_error_code_to_alarm(__FUNCTION__, result); (*week_flag) = value; @@ -668,7 +458,7 @@ int alarm_get_global(int alarm_id, bool *global) int alarm_update_delay(int alarm_id, int delay) { alarm_date_t internal_time; - alarm_entry_t *alarm_info; + alarm_entry_t alarm_info = {0,}; int result; struct timeval current_time; struct tm date; @@ -694,23 +484,12 @@ int alarm_update_delay(int alarm_id, int delay) internal_time.min = date.tm_min; internal_time.sec = date.tm_sec; - alarm_info = alarmmgr_create_alarm(); - if (alarm_info == NULL) { - /* LCOV_EXCL_START */ - LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY); - return ALARM_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - - 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_time(&alarm_info, internal_time); + if (result < 0) + return convert_error_code_to_alarm(__FUNCTION__, result); - result = alarmmgr_update_alarm(alarm_id, alarm_info, + result = alarmmgr_update_alarm(alarm_id, &alarm_info, ALARM_UPDATE_FLAG_TIME); - alarmmgr_free_alarm(alarm_info); return convert_error_code_to_alarm(__FUNCTION__, result); } @@ -718,7 +497,7 @@ int alarm_update_delay(int alarm_id, int delay) int alarm_update_date(int alarm_id, struct tm *date) { alarm_date_t internal_time; - alarm_entry_t *alarm_info; + alarm_entry_t alarm_info = {0,}; int result; if (date == NULL || alarm_id < 0) { @@ -726,14 +505,6 @@ int alarm_update_date(int alarm_id, struct tm *date) return ALARM_ERROR_INVALID_PARAMETER; } - alarm_info = alarmmgr_create_alarm(); - if (alarm_info == NULL) { - /* LCOV_EXCL_START */ - LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY); - return ALARM_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - internal_time.year = date->tm_year + 1900; internal_time.month = date->tm_mon + 1; internal_time.day = date->tm_mday; @@ -742,22 +513,19 @@ int alarm_update_date(int alarm_id, struct tm *date) 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); + result = alarmmgr_set_time(&alarm_info, internal_time); + if (result < 0) return convert_error_code_to_alarm(__FUNCTION__, result); - } - result = alarmmgr_update_alarm(alarm_id, alarm_info, + result = alarmmgr_update_alarm(alarm_id, &alarm_info, ALARM_UPDATE_FLAG_TIME); - alarmmgr_free_alarm(alarm_info); return convert_error_code_to_alarm(__FUNCTION__, result); } int alarm_update_period(int alarm_id, int period) { - alarm_entry_t *alarm_info; + alarm_entry_t alarm_info = {0,}; int result; if (period < 0 || alarm_id < 0) { @@ -765,38 +533,26 @@ int alarm_update_period(int alarm_id, int period) return ALARM_ERROR_INVALID_PARAMETER; } - alarm_info = alarmmgr_create_alarm(); - if (alarm_info == NULL) { - /* LCOV_EXCL_START */ - LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY); - return ALARM_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - if (period == 0) { - result = alarmmgr_update_alarm(alarm_id, alarm_info, + result = alarmmgr_update_alarm(alarm_id, &alarm_info, ALARM_UPDATE_FLAG_CLEAR_PERIOD); - alarmmgr_free_alarm(alarm_info); return convert_error_code_to_alarm(__FUNCTION__, result); } - result = alarmmgr_set_repeat_mode(alarm_info, + result = alarmmgr_set_repeat_mode(&alarm_info, ALARM_REPEAT_MODE_REPEAT, period); - if (result < 0) { - alarmmgr_free_alarm(alarm_info); - return convert_error_code_to_alarm(__FUNCTION__, result); - } + if (result < 0) + return convert_error_code_to_alarm(__FUNCTION__, result); - result = alarmmgr_update_alarm(alarm_id, alarm_info, + result = alarmmgr_update_alarm(alarm_id, &alarm_info, ALARM_UPDATE_FLAG_PERIOD); - alarmmgr_free_alarm(alarm_info); return convert_error_code_to_alarm(__FUNCTION__, result); } int alarm_update_week_flag(int alarm_id, int week_flag) { - alarm_entry_t *alarm_info; + alarm_entry_t alarm_info = {0,}; int result; if (week_flag < 0 || alarm_id < 0) { @@ -804,30 +560,18 @@ int alarm_update_week_flag(int alarm_id, int week_flag) return ALARM_ERROR_INVALID_PARAMETER; } - alarm_info = alarmmgr_create_alarm(); - if (alarm_info == NULL) { - /* LCOV_EXCL_START */ - LOGE("OUT_OF_MEMORY(0x%08x)", ALARM_ERROR_OUT_OF_MEMORY); - return ALARM_ERROR_OUT_OF_MEMORY; - /* LCOV_EXCL_STOP */ - } - if (week_flag == 0) { - result = alarmmgr_update_alarm(alarm_id, alarm_info, + result = alarmmgr_update_alarm(alarm_id, &alarm_info, ALARM_UPDATE_FLAG_CLEAR_WEEK_FLAG); - alarmmgr_free_alarm(alarm_info); return convert_error_code_to_alarm(__FUNCTION__, result); } - result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag); - if (result < 0) { - alarmmgr_free_alarm(alarm_info); + result = alarmmgr_set_repeat_mode(&alarm_info, ALARM_REPEAT_MODE_WEEKLY, week_flag); + if (result < 0) return convert_error_code_to_alarm(__FUNCTION__, result); - } - result = alarmmgr_update_alarm(alarm_id, alarm_info, + result = alarmmgr_update_alarm(alarm_id, &alarm_info, ALARM_UPDATE_FLAG_WEEK); - alarmmgr_free_alarm(alarm_info); return convert_error_code_to_alarm(__FUNCTION__, result); } @@ -840,12 +584,8 @@ int alarm_schedule_service_once_after_delay(app_control_h app_control, int delay 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) { + if (app_control == NULL || + 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; } @@ -857,61 +597,7 @@ int alarm_schedule_service_once_after_delay(app_control_h app_control, int delay int alarm_schedule_service_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(); - - 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 | ALARM_TYPE_EXACT_SERVICE_APP); - - 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; + return __add_alarm_appsvc_with_localtime(app_control, date, ALARM_REPEAT_MODE_ONCE, 0, ALARM_TYPE_DEFAULT | ALARM_TYPE_EXACT_SERVICE_APP, alarm_id); } int alarm_set_systime(int new_time) @@ -951,55 +637,5 @@ int alarm_set_timezone(char *tzpath_str) int alarm_schedule_service_with_recurrence_seconds(app_control_h app_control, struct tm *date, int period, 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(); - - 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); - } - - if (period > 0) { - result = alarmmgr_set_repeat_mode(alarm_info, ALARM_REPEAT_MODE_REPEAT, - period); - 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 | ALARM_TYPE_EXACT_SERVICE_APP); - 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); - alarmmgr_free_alarm(alarm_info); - - return convert_error_code_to_alarm(__FUNCTION__, result); + return __add_alarm_appsvc_with_localtime(app_control, date, ALARM_REPEAT_MODE_REPEAT, period, ALARM_TYPE_DEFAULT | ALARM_TYPE_EXACT_SERVICE_APP, alarm_id); } |