From 5a5813e30a9dd5d99ff7057a5c0501f544c96fa9 Mon Sep 17 00:00:00 2001 From: Inkyun Kil Date: Thu, 26 Sep 2019 10:38:26 +0900 Subject: [PATCH] Remove duplicated codes Change-Id: I4440cdef749a1fc1caa01b6e247c5392ef4a8e9f Signed-off-by: Inkyun Kil Signed-off-by: Jusung Son --- lib/alarm-lib-dbus.c | 429 +++++++++++---------------------------------------- lib/alarm-lib.c | 99 +++++------- 2 files changed, 123 insertions(+), 405 deletions(-) diff --git a/lib/alarm-lib-dbus.c b/lib/alarm-lib-dbus.c index 702faf5..9633b68 100644 --- a/lib/alarm-lib-dbus.c +++ b/lib/alarm-lib-dbus.c @@ -24,10 +24,33 @@ #include "alarm.h" #include "alarm-internal.h" +static int __dbus_call_sync(GDBusProxy *proxy, const gchar *method_name, + GVariant *param, GVariant **reply) +{ + int error_code = ALARMMGR_RESULT_SUCCESS; + GError *error = NULL; + + *reply = g_dbus_proxy_call_sync(proxy, method_name, param, + G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); + if (error) { + if (error->code == G_DBUS_ERROR_ACCESS_DENIED) + error_code = ERR_ALARM_NO_PERMISSION; + else + error_code = ERR_ALARM_SYSTEM_FAIL; + + LOGE("%s : g_dbus_proxy_call_sync() failed.\ + error_code[%d]. error->message is %s(%d)", + method_name, error_code, error->message, error->code); + + g_error_free(error); + } + + return error_code; +} + bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info, alarm_id_t *alarm_id, notification_h noti, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *noti_gv = NULL; char *noti_data; @@ -77,22 +100,10 @@ bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info, free(data); g_variant_unref(noti_gv); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_create_noti", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed. alarm_id[%d],\ - return_code[%d].error->message is %s(%d)", *(int *)alarm_id, - return_code, error->message, error->code); - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_create_noti", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(ii)", alarm_id, &return_code); @@ -114,7 +125,6 @@ bool _send_alarm_create_noti(alarm_context_t context, alarm_info_t *alarm_info, bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info, alarm_id_t *alarm_id, bundle *b, int *error_code) { - GError *error = NULL; int return_code = -1; bundle_raw *b_data = NULL; int datalen = 0; @@ -148,22 +158,10 @@ bool _send_alarm_create_appsvc(alarm_context_t context, alarm_info_t *alarm_info if (b_data) free(b_data); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_create_appsvc", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d], return_code[%d]. error->message is %s(%d)", - *alarm_id, return_code, error->message, error->code); - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_create_appsvc", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(ii)", alarm_id, &return_code); @@ -186,7 +184,6 @@ bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info, alarm_id_t *alarm_id, const char *dst_service_name, const char *dst_service_name_mod, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; @@ -220,23 +217,10 @@ bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info, (gint64)alarm_info->reserved_info, dst_service_name, dst_service_name_mod); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_create", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d], return_code[%d]. error->message is %s(%d)", - *alarm_id, return_code, error->message, error->code); - g_error_free(error); - + return_code = __dbus_call_sync(context.proxy, "alarm_create", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(ii)", alarm_id, &return_code); @@ -258,7 +242,6 @@ bool _send_alarm_create(alarm_context_t context, alarm_info_t *alarm_info, bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_ref, int method, alarm_id_t *alarm_id, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; @@ -275,24 +258,10 @@ bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_r context.app_service_name_mod, interval, is_ref, method); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_create_periodic", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d], return_code[%d]. error->message is %s(%d)", - *(int *)alarm_id, return_code, error->message, error->code); - - g_error_free(error); - + return_code = __dbus_call_sync(context.proxy, "alarm_create_periodic", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(ii)", alarm_id, &return_code); @@ -313,7 +282,6 @@ bool _send_alarm_create_periodic(alarm_context_t context, int interval, int is_r bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code) { - GError *error = NULL; int return_code = -1; bundle *b = NULL; gchar *b_data = NULL; @@ -322,24 +290,10 @@ bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id param = g_variant_new("(i)", alarm_id); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_appsvc_info", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d], return_code[%d]. error->message is %s(%d)", - alarm_id, return_code, error->message, error->code); - - g_error_free(error); - - return NULL; - } + return_code = __dbus_call_sync(context.proxy, "alarm_get_appsvc_info", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) + return false; g_variant_get(reply, "(si)", &b_data, &return_code); @@ -362,7 +316,6 @@ bundle *_send_alarm_get_appsvc_info(alarm_context_t context, alarm_id_t alarm_id notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t alarm_id, int *error_code) { - GError *error = NULL; int return_code = -1; int datalen; GVariant *noti_gv = NULL; @@ -375,24 +328,10 @@ notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t ala param = g_variant_new("(i)", alarm_id); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_noti_info", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d], return_code[%d]. error->message is %s(%d)", - alarm_id, return_code, error->message, error->code); - - g_error_free(error); - - return NULL; - } + return_code = __dbus_call_sync(context.proxy, "alarm_get_noti_info", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) + return false; g_variant_get(reply, "(si)", ¬i_data, &return_code); @@ -427,7 +366,6 @@ notification_h _send_alarm_get_noti_info(alarm_context_t context, alarm_id_t ala bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; @@ -435,24 +373,10 @@ bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int * param = g_variant_new("(iiiiii)", time->year, time->month, time->day, time->hour, time->min, time->sec); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_rtc_time", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - return_code[%d]. error->message is %s(%d)", - return_code, error->message, error->code); - - g_error_free(error); - + return_code = __dbus_call_sync(context.proxy, "alarm_set_rtc_time", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(i)", &return_code); @@ -473,31 +397,16 @@ bool _send_alarm_set_rtc_time(alarm_context_t context, alarm_date_t *time, int * bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; param = g_variant_new("(i)", alarm_id); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_delete", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d], return_code[%d]. error->message is %s(%d)", - alarm_id, return_code, error->message, error->code); - - g_error_free(error); - + return_code = __dbus_call_sync(context.proxy, "alarm_delete", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(i)", &return_code); @@ -518,27 +427,13 @@ bool _send_alarm_delete(alarm_context_t context, alarm_id_t alarm_id, int *error bool _send_alarm_delete_all(alarm_context_t context, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *reply = NULL; - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_delete_all", NULL, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - return_code[%d]. error->message is %s(%d)", - return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_delete_all", + NULL, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(i)", &return_code); @@ -561,7 +456,6 @@ bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids, GVariantIter **iter, int *num_of_ids, int *error_code) { - GError *error = NULL; int return_code = -1; GVariantIter *iter_temp = NULL; GVariant *arr = NULL; @@ -570,23 +464,10 @@ bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids, param = g_variant_new("(i)", maxnum_of_ids); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_list_of_ids", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - LOGE("g_dbus_proxy_call_sync() failed.\ - return_code[%d]. error->message is %s(%d)", - return_code, error->message, error->code); - - g_error_free(error); - + return_code = __dbus_call_sync(context.proxy, "alarm_get_list_of_ids", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(@aiii)", &arr, num_of_ids, &return_code); g_variant_get(arr, "ai", &iter_temp); @@ -612,27 +493,13 @@ bool _send_alarm_get_list_of_ids(alarm_context_t context, int maxnum_of_ids, bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *reply = NULL; - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_number_of_ids", NULL, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - return_code[%d]. error->message is %s(%d)", - return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_get_number_of_ids", + NULL, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(ii)", num_of_ids, &return_code); @@ -655,30 +522,16 @@ bool _send_alarm_get_number_of_ids(alarm_context_t context, int *num_of_ids, bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, alarm_info_t *alarm_info, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; gint64 tmp_reserved_info; param = g_variant_new("(i)", alarm_id); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_info", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id [%d] return_code[%d]. error->message is %s(%d)", - alarm_id, return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_get_info", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(iiiiiiiiiiiixi)", &alarm_info->start.year, @@ -715,7 +568,6 @@ bool _send_alarm_get_info(alarm_context_t context, alarm_id_t alarm_id, bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, time_t *duetime, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; @@ -723,23 +575,10 @@ bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, param = g_variant_new("(i)", alarm_id); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_next_duetime", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id [%d] return_code[%d]. error->message is %s(%d)", - alarm_id, return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_get_next_duetime", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(xi)", &_duetime, &return_code); @@ -761,28 +600,14 @@ bool _send_alarm_get_next_duetime(alarm_context_t context, alarm_id_t alarm_id, bool _send_alarm_get_all_info(alarm_context_t context, char **db_path, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *reply = NULL; char *_db_path = NULL; - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_all_info", NULL, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - return_code[%d]. error->message is %s(%d)", - return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_get_all_info", + NULL, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(si)", &_db_path, &return_code); @@ -804,26 +629,16 @@ bool _send_alarm_get_all_info(alarm_context_t context, char **db_path, int *erro bool _send_alarm_set_time(alarm_context_t context, time_t new_time, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; param = g_variant_new("(x)", (gint64)new_time); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_time", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) - *error_code = ERR_ALARM_SYSTEM_FAIL; - - LOGE("g_dbus_proxy_call_sync() failed.\ - return_code[%d]. error->message is %s(%d)", - return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_set_time", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(i)", &return_code); @@ -892,7 +707,6 @@ bool _send_alarm_set_time_async(alarm_context_t context, time_t new_time, alarm_ bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, struct timespec new_time, struct timespec req_time, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; @@ -900,23 +714,10 @@ bool _send_alarm_set_time_with_propagation_delay(alarm_context_t context, struct param = g_variant_new("(xxxx)", (gint64)new_time.tv_sec, (gint64)new_time.tv_nsec, (gint64)req_time.tv_sec, (gint64)req_time.tv_nsec); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_time_with_propagation_delay", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - return_code[%d]. error->message is %s(%d)", - return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_set_time_with_propagation_delay", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(i)", &return_code); @@ -987,34 +788,20 @@ bool _send_alarm_set_time_with_propagation_delay_async(alarm_context_t context, bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; param = g_variant_new("(s)", tzpath_str); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_timezone", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - return_code[%d]. error->message is %s(%d)", - return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_set_timezone", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(i)", &return_code); - LOGD("alarm_set_timezon dbus sync() success. tz_path[%s] return_code[%d]", + LOGD("alarm_set_timezone dbus sync() success. tz_path[%s] return_code[%d]", tzpath_str, return_code); if (return_code != ALARMMGR_RESULT_SUCCESS) { @@ -1031,30 +818,16 @@ bool _send_alarm_set_timezone(alarm_context_t context, char *tzpath_str, int *er bool _send_alarm_set_global(alarm_context_t context, const alarm_id_t alarm_id, bool global, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; param = g_variant_new("(ib)", alarm_id, (gboolean)global); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_set_global", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error && error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d] return_code[%d]. error->message is %s(%d)", - alarm_id, return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_set_global", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(i)", &return_code); @@ -1075,30 +848,16 @@ bool _send_alarm_set_global(alarm_context_t context, const alarm_id_t alarm_id, bool _send_alarm_get_global(alarm_context_t context, const alarm_id_t alarm_id, bool *global, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; param = g_variant_new("(i)", alarm_id); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_get_global", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d] return_code[%d]. error->message is %s(%d)", - alarm_id, return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_get_global", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(bi)", global, &return_code); @@ -1120,7 +879,6 @@ bool _send_alarm_get_global(alarm_context_t context, const alarm_id_t alarm_id, bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id, alarm_info_t *alarm_info, int update_flag, int *error_code) { - GError *error = NULL; int return_code = -1; GVariant *param = NULL; GVariant *reply = NULL; @@ -1142,23 +900,10 @@ bool _send_alarm_update(alarm_context_t context, alarm_id_t alarm_id, (gint64)alarm_info->reserved_info, update_flag); - reply = g_dbus_proxy_call_sync(context.proxy, "alarm_update", param, - G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); - if (error) { - if (error_code) { - if (error->code == G_DBUS_ERROR_ACCESS_DENIED) - *error_code = ERR_ALARM_NO_PERMISSION; - else - *error_code = ERR_ALARM_SYSTEM_FAIL; - } - - LOGE("g_dbus_proxy_call_sync() failed.\ - alarm_id[%d] return_code[%d]. error->message is %s(%d)", - alarm_id, return_code, error->message, error->code); - - g_error_free(error); + return_code = __dbus_call_sync(context.proxy, "alarm_update", + param, &reply); + if (return_code != ALARMMGR_RESULT_SUCCESS) return false; - } g_variant_get(reply, "(i)", &return_code); diff --git a/lib/alarm-lib.c b/lib/alarm-lib.c index baabca2..40cec26 100644 --- a/lib/alarm-lib.c +++ b/lib/alarm-lib.c @@ -329,6 +329,28 @@ static bool __alarm_validate_time(alarm_date_t *date, int *error_code) return true; } +static int __check_validation(alarm_info_t *alarm_info, const char *function) +{ + int error_code; + + if (!__alarm_validate_date(&alarm_info->start, &error_code)) { + LOGE("%s : start date error\n", function); + return error_code; + } + + if (!__alarm_validate_time(&alarm_info->start, &error_code)) { + LOGE("%s : start time error\n", function); + return error_code; + } + + if (!__alarm_validate_date(&alarm_info->end, &error_code)) { + LOGE("%s : end date error\n", function); + return error_code; + } + + return ALARMMGR_RESULT_SUCCESS; +} + static int __alarm_context_init() { if (sub_initialized) @@ -973,10 +995,12 @@ EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, vo } appid = appsvc_get_appid(b); - if ((appid == NULL && (alarm_info->alarm_type & ALARM_TYPE_NOLAUNCH)) || - (appid == NULL && operation && !strcmp(operation, APPSVC_OPERATION_DEFAULT))) { - LOGE("appid is ivalid"); - return ERR_ALARM_INVALID_PARAM; + if (appid == NULL) { + if ((alarm_info->alarm_type & ALARM_TYPE_NOLAUNCH) || + (operation && !strcmp(operation, APPSVC_OPERATION_DEFAULT))) { + LOGE("appid is invalid"); + return ERR_ALARM_INVALID_PARAM; + } } mode = &alarm_info->mode; @@ -991,20 +1015,9 @@ EXPORT_API int alarmmgr_add_alarm_appsvc_with_localtime(alarm_entry_t *alarm, vo if (mode->repeat >= ALARM_REPEAT_MODE_MAX) return ERR_ALARM_INVALID_PARAM; - if (!__alarm_validate_date(&alarm_info->start, &error_code)) { - LOGE("start date error\n"); - return error_code; - } - - if (!__alarm_validate_time(&alarm_info->start, &error_code)) { - LOGE("start time error\n"); + error_code = __check_validation(alarm_info, __FUNCTION__); + if (error_code != ALARMMGR_RESULT_SUCCESS) return error_code; - } - - if (!__alarm_validate_date(&alarm_info->end, &error_code)) { - LOGE("end date error\n"); - return error_code; - } if (!_send_alarm_create_appsvc(alarm_context, alarm_info, alarm_id, b, &error_code)) return error_code; @@ -1063,21 +1076,9 @@ EXPORT_API int alarmmgr_add_alarm_with_localtime(alarm_entry_t *alarm, return ERR_ALARM_INVALID_PARAM; } - - if (!__alarm_validate_date(&alarm_info->start, &error_code)) { - LOGE("start date error\n"); - return error_code; - } - - if (!__alarm_validate_time(&alarm_info->start, &error_code)) { - LOGE("start time error\n"); - return error_code; - } - - if (!__alarm_validate_date(&alarm_info->end, &error_code)) { - LOGE("end date error\n"); + error_code = __check_validation(alarm_info, __FUNCTION__); + if (error_code != ALARMMGR_RESULT_SUCCESS) return error_code; - } if (destination != NULL) { memset(dst_service_name, 0, strlen(destination) + strlen("ALARM.") + 2); @@ -1123,12 +1124,6 @@ EXPORT_API int alarmmgr_add_alarm_noti_with_localtime(alarm_entry_t *alarm, noti return ERR_ALARM_SYSTEM_FAIL; } - alarm_info = (alarm_info_t *)alarm; - if (alarm_info == NULL || alarm_id == NULL) { - LOGE("Invalid parameter\n"); - return ERR_ALARM_INVALID_PARAM; - } - mode = &alarm_info->mode; LOGW("start(%d-%d-%d, %02d:%02d:%02d), end(%d-%d-%d), repeat(%d), interval(%ld), type(%d)", @@ -1141,20 +1136,9 @@ EXPORT_API int alarmmgr_add_alarm_noti_with_localtime(alarm_entry_t *alarm, noti if (mode->repeat >= ALARM_REPEAT_MODE_MAX) return ERR_ALARM_INVALID_PARAM; - if (!__alarm_validate_date(&alarm_info->start, &error_code)) { - LOGE("start date error\n"); - return error_code; - } - - if (!__alarm_validate_time(&alarm_info->start, &error_code)) { - LOGE("start time error\n"); - return error_code; - } - - if (!__alarm_validate_date(&alarm_info->end, &error_code)) { - LOGE("end date error\n"); + error_code = __check_validation(alarm_info, __FUNCTION__); + if (error_code != ALARMMGR_RESULT_SUCCESS) return error_code; - } if (!_send_alarm_create_noti(alarm_context, alarm_info, alarm_id, noti, &error_code)) return error_code; @@ -1821,20 +1805,9 @@ EXPORT_API int alarmmgr_update_alarm(alarm_id_t alarm_id, alarm_info->mode.repeat, alarm_info->mode.u_interval.interval, alarm_info->alarm_type); if (update_flag == ALARM_UPDATE_FLAG_TIME) { - if (!__alarm_validate_date(&alarm_info->start, &error_code)) { - LOGE("start date error\n"); - return error_code; - } - - if (!__alarm_validate_time(&alarm_info->start, &error_code)) { - LOGE("start time error\n"); + error_code = __check_validation(alarm_info, __FUNCTION__); + if (error_code != ALARMMGR_RESULT_SUCCESS) return error_code; - } - - if (!__alarm_validate_date(&alarm_info->end, &error_code)) { - LOGE("end date error\n"); - return error_code; - } } if (!_send_alarm_update(alarm_context, alarm_id, alarm_info, update_flag, &error_code)) -- 2.7.4