From df03367cd6d9cd10d47c26c402819b1122ec8813 Mon Sep 17 00:00:00 2001 From: San Cho Date: Mon, 11 Jul 2016 17:02:07 +0900 Subject: [PATCH] the order of auto download attachment was wrong [Problem] the order of auto download attachment was wrong [Cause & Measure] Cause: the older mail's attachment was downloaded first. Measure: sorting mails by server id and download attachment. Change-Id: Ib7d4649ba3b960bc2a66e23f8032ea0d068d157e --- email-core/email-core-auto-download.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/email-core/email-core-auto-download.c b/email-core/email-core-auto-download.c index 156ec89..b990f97 100755 --- a/email-core/email-core-auto-download.c +++ b/email-core/email-core-auto-download.c @@ -59,6 +59,7 @@ INTERNAL_FUNC int auto_download_thread_run = 0; #define AUTO_DOWNLOAD_QUEUE_MAX 100 static void* worker_auto_download_queue(void *arg); +static gint auto_download_compare_func(gconstpointer a, gconstpointer b, gpointer user_data); INTERNAL_FUNC int emcore_start_auto_download_loop(int *err_code) { @@ -175,14 +176,9 @@ INTERNAL_FUNC int emcore_insert_auto_download_event(email_event_auto_download *e EM_DEBUG_EXCEPTION("auto download que is full..."); error = EMAIL_ERROR_EVENT_QUEUE_FULL; ret = false; - } else if (event_data->status == EMAIL_EVENT_STATUS_DIRECT) { - event_data->status = EMAIL_EVENT_STATUS_WAIT; - g_queue_push_head(g_auto_download_que, event_data); - //WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal); - ret = true; } else { event_data->status = EMAIL_EVENT_STATUS_WAIT; - g_queue_push_tail(g_auto_download_que, event_data); + g_queue_insert_sorted(g_auto_download_que, event_data, auto_download_compare_func, event_data); //WAKE_CONDITION_VARIABLE(_auto_downalod_available_signal); ret = true; } @@ -467,7 +463,7 @@ static void* worker_auto_download_queue(void *arg) } activity->activity_id = activity_list[di].activity_id; - activity->status = 0; + activity->status = EMAIL_EVENT_STATUS_DIRECT; activity->account_id = activity_list[di].account_id; activity->mail_id = activity_list[di].mail_id; activity->server_mail_id = activity_list[di].server_mail_id; @@ -862,4 +858,12 @@ FINISH_OFF: return ret; } - +static gint auto_download_compare_func(gconstpointer a, gconstpointer b, gpointer user_data) +{ + email_event_auto_download *first = (email_event_auto_download*)a; + email_event_auto_download *second = (email_event_auto_download*)b; + if (first->server_mail_id == second->server_mail_id) return 0; + else if (first->server_mail_id > second->server_mail_id) return -1; + else return 1; + return 1; +} -- 2.7.4