From: jay.ho.park Date: Tue, 5 Jan 2021 01:35:50 +0000 (+0900) Subject: Pop item from queue to prevent duplicated request X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a47417b5e25e5ab9529d73f489561a66c34571a8;p=platform%2Fcore%2Fuifw%2Fcapi-ui-sticker.git Pop item from queue to prevent duplicated request Change-Id: I04f4d7d7f07aa74e94b7a85ece4a29ed0f3501ea --- diff --git a/receiver/inc/ft.h b/receiver/inc/ft.h index afab92e..f3a735c 100644 --- a/receiver/inc/ft.h +++ b/receiver/inc/ft.h @@ -33,10 +33,9 @@ gboolean is_init_sap(); void request_all_sticker_data(const char *mode, const char *type); bool request_sticker_data(const char *mode, const char *category, const char *type); -void request_auto_sync(); -void request_sticker_feature(); +bool request_sticker_feature(); void send_disconnect_message(); -void request_show_sync_notification(); +bool request_show_sync_notification(); bool get_job_progress(); diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 4d24be9..9a717ee 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -93,6 +93,26 @@ static int sync_success_cnt = 0; static gboolean job_progress = FALSE; static int sync_complete_flags = 0; +void push_sticker_request(request_type req_type, const char *mode, const char *category, const char *type) +{ + StickerRequest pending_request; + + pending_request.req_type = req_type; + + if (mode != NULL) + pending_request.mode = string(mode); + + if (category != NULL) + pending_request.category = string(category); + + if (type != NULL) + pending_request.type = string(type); + + ReqQueue.push(pending_request); + STLOGI("Push sticker request: req_type[%d], mode[%s], category[%s], type[%s]", + pending_request.req_type, pending_request.mode.c_str(), pending_request.category.c_str(), pending_request.type.c_str()); +} + static void sticker_service_quit(); static void save_last_sync_info() @@ -374,14 +394,6 @@ bool request_sticker_data(const char *mode, const char *category, const char *ty if (!priv_data.socket) { job_progress = TRUE; - StickerRequest pending_request; - pending_request.req_type = REQUEST_TYPE_SYNC; - pending_request.mode = string(mode ? mode : "manual"); - pending_request.category = string(category ? category : "arsticker"); - pending_request.type = string(type ? type : "input"); - - ReqQueue.push(pending_request); - STLOGI("Push sync request"); return false; } @@ -403,6 +415,7 @@ bool request_sticker_data(const char *mode, const char *category, const char *ty if (_send_json_data(j_object) == FALSE) { STLOGE("Failed to send STICKER_SYNC_START_REQ"); + result = false; } else { @@ -429,19 +442,26 @@ static bool process_request_queue() switch (request.req_type) { case REQUEST_TYPE_FEATURE_REQ: STLOGD("[Request feature exchange]"); - request_sticker_feature(); + + if (true == request_sticker_feature()) + ReqQueue.pop(); + break; case REQUEST_TYPE_SYNC: STLOGD("[Request to sync sticker] mode: %s, category: %s, type: %s", request.mode.c_str(), request.category.c_str(), request.type.c_str()); - request_sticker_data(request.mode.c_str(), request.category.c_str(), request.type.c_str()); + if (true == request_sticker_data(request.mode.c_str(), request.category.c_str(), request.type.c_str())) + ReqQueue.pop(); + break; case REQUEST_TYPE_SHOW_NOTIFICATION: STLOGD("[Request to show notification]"); - request_show_sync_notification(); - ReqQueue.pop(); + + if (true == request_show_sync_notification()) + ReqQueue.pop(); + break; case REQUEST_TYPE_AUTOSYNC: STLOGD("[Request to sync automatically]"); @@ -455,65 +475,45 @@ static bool process_request_queue() return true; } -void request_auto_sync() -{ - STLOGD("Add request to sync automatically"); - StickerRequest pending_request; - pending_request.req_type = REQUEST_TYPE_AUTOSYNC; - ReqQueue.push(pending_request); -} - void request_all_sticker_data(const char *mode, const char *type) { - StickerRequest pending_request; - pending_request.req_type = REQUEST_TYPE_SYNC; - pending_request.mode = string(mode); - pending_request.type = string(type); - #ifdef VCONFKEY_STICKER_SUPPORTED_FEATURE int feature_flag = 0; if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0) { if (feature_flag & VCONFKEY_STICKER_FEATURE_AREMOJI) { - pending_request.category = string("arsticker"); - ReqQueue.push(pending_request); + push_sticker_request(REQUEST_TYPE_SYNC, mode, "arsticker", type); } if (feature_flag & VCONFKEY_STICKER_FEATURE_BITMOJI) { - pending_request.category = string("bitmoji"); - ReqQueue.push(pending_request); + push_sticker_request(REQUEST_TYPE_SYNC, mode, "bitmoji", type); } } else STLOGW("Failed to get value of VCONFKEY_STICKER_SUPPORTED_FEATURE"); #else - pending_request.category = string("arsticker"); - ReqQueue.push(pending_request); - pending_request.category = string("bitmoji"); - ReqQueue.push(pending_request); + push_sticker_request(REQUEST_TYPE_SYNC, mode, "arsticker", type); + push_sticker_request(REQUEST_TYPE_SYNC, mode, "bitmoji", type); #endif if (priv_data.socket) process_request_queue(); } -void request_sticker_feature() +bool request_sticker_feature() { + bool result = false; JsonObject *j_object = NULL; if (!priv_data.socket) { job_progress = TRUE; - StickerRequest pending_request; - pending_request.req_type = REQUEST_TYPE_FEATURE_REQ; - ReqQueue.push(pending_request); - STLOGI("Push sync feature request"); - return; + return false; } j_object = json_object_new(); if (j_object == NULL) { STLOGE("json object create error"); - return; + return false; } json_object_set_string_member(j_object, "msgId", STICKER_SYNC_FEATURE_REQ); @@ -521,15 +521,19 @@ void request_sticker_feature() if (_send_json_data(j_object) == FALSE) { STLOGE("Failed to send STICKER_SYNC_FEATURE_REQ"); + result = false; } else { job_progress = TRUE; + result = true; } json_object_unref(j_object); if (_create_thumbnail_directory() != 0) STLOGE("Failed to create thumbnail directory"); + + return result; } void send_disconnect_message() @@ -551,23 +555,20 @@ void send_disconnect_message() json_object_unref(j_object); } -void request_show_sync_notification() +bool request_show_sync_notification() { + bool result = false; JsonObject *j_object = NULL; if (!priv_data.socket) { job_progress = TRUE; - StickerRequest pending_request; - pending_request.req_type = REQUEST_TYPE_SHOW_NOTIFICATION; - ReqQueue.push(pending_request); - STLOGI("Push show notification request"); - return; + return false; } j_object = json_object_new(); if (j_object == NULL) { STLOGE("json object create error"); - return; + return false; } json_object_set_string_member(j_object, "msgId", STICKER_REQUEST_NOTI_REQ); @@ -575,11 +576,14 @@ void request_show_sync_notification() if (_send_json_data(j_object) == FALSE) { STLOGE("Failed to send STICKER_REQUEST_NOTI_REQ"); + result = false; } else { job_progress = TRUE; + result = true; } json_object_unref(j_object); + return result; } void reject_file() @@ -722,19 +726,6 @@ static void send_sync_start_response(int result_code) #endif } -static void pop_sticker_request(request_type req_type) -{ - if (ReqQueue.empty()) - return; - - StickerRequest request = ReqQueue.front(); - STLOGD ("request type : %d", request.req_type); - if (request.req_type == req_type) { - STLOGD ("pop sync request"); - ReqQueue.pop(); - } -} - void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, void *user_data) /* message exchange on_receive callback (sap_agent_data_received_cb) */ @@ -793,9 +784,6 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in #else STLOGW("No vconf supported feature"); #endif - - pop_sticker_request(REQUEST_TYPE_FEATURE_REQ); - if (!process_request_queue()) { sticker_service_quit(); } @@ -855,8 +843,6 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in save_last_sync_info(); sticker_service_quit(); } - - pop_sticker_request(REQUEST_TYPE_SYNC); } } else if (msg_id == STICKER_SEND_START_REQ) { STLOGD("msg : %s", msg_id.c_str()); diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 6ba29ed..968b4f4 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -114,7 +114,8 @@ static bool check_sync_time_condition() if (timediff > MAX_WAIT_TIME) { STLOGD("Starting manual synchronization"); initialize_sap(); - request_show_sync_notification(); + if (false == request_show_sync_notification()) + push_sticker_request(REQUEST_TYPE_SHOW_NOTIFICATION, NULL, NULL, NULL); result = false; } else { if (timediff > SYNC_INTERVAL) @@ -205,7 +206,9 @@ static void process_request(app_control_h app_control, char *request) } else if (strcmp(request, "oobe") == 0) { initialize_sap(); - request_sticker_feature(); + + if (false == request_sticker_feature()) + push_sticker_request(REQUEST_TYPE_FEATURE_REQ, NULL, NULL, NULL); } else { STLOGW("Unknown command : %s", request); @@ -235,8 +238,11 @@ static void process_auto_sync() if (preference_set_int(LAST_SYNC_STATUS, LAST_SYNC_STATUS_SYNC_NEEDED) != PREFERENCE_ERROR_NONE) STLOGE("Failed to set sync status as NEEDED"); initialize_sap(); - request_sticker_feature(); - request_auto_sync(); + + if (false == request_sticker_feature()) + push_sticker_request(REQUEST_TYPE_FEATURE_REQ, NULL, NULL, NULL); + + push_sticker_request(REQUEST_TYPE_AUTOSYNC, NULL, NULL, NULL); } else { STLOGI("The status of battery is low"); @@ -257,8 +263,11 @@ static void process_auto_sync() if (last_sync_status == LAST_SYNC_STATUS_SYNC_NEEDED) { STLOGD("Last sync status is NEEDED(code: %d). Retrying to sync.", last_sync_status); initialize_sap(); - request_sticker_feature(); - request_auto_sync(); + + if (false == request_sticker_feature()) + push_sticker_request(REQUEST_TYPE_FEATURE_REQ, NULL, NULL, NULL); + + push_sticker_request(REQUEST_TYPE_AUTOSYNC, NULL, NULL, NULL); } else { STLOGD("Last sync status is SUCCESS(code: %d). Don't have to retrying sync", last_sync_status); service_app_exit(); @@ -275,7 +284,9 @@ static void get_sticker_feature() if (vconf_get_int(VCONFKEY_STICKER_SUPPORTED_FEATURE, &feature_flag) == 0 && feature_flag == 0) { STLOGD("Request to get sticker feature"); initialize_sap(); - request_sticker_feature(); + + if (false == request_sticker_feature()) + push_sticker_request(REQUEST_TYPE_FEATURE_REQ, NULL, NULL, NULL); } else { if (!is_init_sap())