From: Jihoon Kim Date: Wed, 18 Mar 2020 11:11:41 +0000 (+0900) Subject: Use request queue X-Git-Tag: accepted/tizen/5.5/unified/20200326.232334~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1f5ca3b282adbf20ced43e8c140767b1d69099c4;p=platform%2Fcore%2Fuifw%2Fcapi-ui-sticker.git Use request queue Change-Id: I707e5b8bc720659afefc04f1c4cc5adc54ed0f44 Signed-off-by: Jihoon Kim --- diff --git a/receiver/inc/ft.h b/receiver/inc/ft.h index a95204c..10ccb0e 100644 --- a/receiver/inc/ft.h +++ b/receiver/inc/ft.h @@ -29,7 +29,7 @@ void accept_file(void); gboolean initialize_sap(void); void deinitialize_sap(void); -void request_sticker_data(const char *mode, const char *category, const char *type); +bool request_sticker_data(const char *mode, const char *category, const char *type); void request_sticker_feature(); #endif /* __FT_H__ */ diff --git a/receiver/inc/sticker_request.h b/receiver/inc/sticker_request.h new file mode 100644 index 0000000..9c8089f --- /dev/null +++ b/receiver/inc/sticker_request.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020 Samsung Electronics Co., Ltd. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef __STICKER_REQUEST_H__ +#define __STICKER_REQUEST_H__ + +#include + +using namespace std; + +typedef enum { + REQUEST_TYPE_SYNC, + REQUEST_TYPE_FEATURE_REQ +} request_type; + +struct StickerRequest { + request_type req_type; + string mode; + string category; + string type; +}; +#endif /* __STICKER_REQUEST_H__ */ diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index 9a8addd..e2b703d 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -31,11 +31,13 @@ #include #include #include +#include #include "ft.h" #include "log.h" #include "sticker_info.h" #include "../inc/sticker_data.h" +#include "sticker_request.h" #include "message.h" #include "sync_alarm.h" @@ -54,11 +56,6 @@ using namespace std; -typedef enum { - REQUEST_TYPE_SYNC, - REQUEST_TYPE_FEATURE_REQ -} request_type; - enum { SYNC_START_RSP_SUCCESS = 1000, SYNC_START_RSP_NO_STICKER = 1001 @@ -71,22 +68,17 @@ struct sap_info_s { sap_file_transaction_h file_socket; }; -struct request { - request_type req_type; - string mode; - string category; - string type; -}; - static struct sap_info_s priv_data = { 0 }; static struct sticker_info sticker_data; -static struct request pending_request, current_request; +static queue ReqQueue; +static StickerRequest current_request; gboolean file_on_progress = 0; static string incoming_file_name; static int t_id = 0; static int rec_file_cnt = 0; static int total_file_count = 0; +static int sync_success_cnt = 0; static gboolean _send_json_data(JsonObject *obj) { @@ -271,23 +263,28 @@ void accept_file() file_on_progress = 1; } -void request_sticker_data(const char *mode, const char *category, const char *type) +bool request_sticker_data(const char *mode, const char *category, const char *type) { + bool result = false; JsonObject *j_object = NULL; + if (!priv_data.socket) { + 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); LOGI("Push sync request"); - return; + + return false; } j_object = json_object_new(); if (j_object == NULL) { LOGE("json object create error"); - return; + return false; } json_object_set_string_member(j_object, "msgId", STICKER_SYNC_START_REQ); @@ -298,15 +295,19 @@ void request_sticker_data(const char *mode, const char *category, const char *ty if (_send_json_data(j_object) == FALSE) { LOGE("Failed to send STICKER_SYNC_START_REQ"); + result = false; } else { current_request.req_type = REQUEST_TYPE_SYNC; current_request.mode = string(mode ? mode : "manual"); current_request.category = string(category ? category : "arsticker"); current_request.type = string(type ? type : "input"); + result = true; } json_object_unref(j_object); + + return result; } void request_sticker_feature() @@ -314,7 +315,9 @@ void request_sticker_feature() JsonObject *j_object = NULL; if (!priv_data.socket) { + StickerRequest pending_request; pending_request.req_type = REQUEST_TYPE_FEATURE_REQ; + ReqQueue.push(pending_request); LOGI("Push sync feature request"); return; } @@ -392,6 +395,29 @@ void conn_terminated(sap_peer_agent_h peer_agent, service_app_exit(); } +static bool process_request_queue() +{ + if (ReqQueue.empty()) + return false; + + StickerRequest request = ReqQueue.front(); + + if (request.req_type == REQUEST_TYPE_FEATURE_REQ) { + LOGD("[Request feature exchange]"); + request_sticker_feature(); + ReqQueue.pop(); + } + else if (request.req_type == REQUEST_TYPE_SYNC) { + LOGD("[Request to sync sticker] mode: %s, category: %s, type : %s", request.mode.c_str(), + request.category.c_str(), + request.type.c_str()); + + if (request_sticker_data(request.mode.c_str(), request.category.c_str(), request.type.c_str())) + ReqQueue.pop(); + } + + return true; +} void on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned int payload_length, void *buffer, @@ -448,7 +474,9 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in LOGW("Fail to set supported feature"); #endif - service_app_exit(); + if (!process_request_queue()) { + service_app_exit(); + } } else if (msg_id == STICKER_SYNC_START_RSP) { LOGD("msg : %s", msg_id.c_str()); const char *json_result = json_object_get_string_member(root_obj, "result"); @@ -471,8 +499,11 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in send_message("sync_start_response", response_to_app.c_str()); - if (result_code != SYNC_START_RSP_SUCCESS) - service_app_exit(); + if (result_code != SYNC_START_RSP_SUCCESS) { + if (!process_request_queue()) { + service_app_exit(); + } + } } else if (msg_id == STICKER_SEND_START_REQ) { LOGD("msg : %s", msg_id.c_str()); total_file_count = 0; @@ -542,8 +573,9 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in json_object_set_string_member(j_object, "msgId", STICKER_SEND_STOP_RSP); json_object_set_int_member(j_object, "tID", t_id); - if (reason == "complete" && rec_file_cnt != file_len) + if (reason == "complete" && rec_file_cnt != file_len) { json_object_set_string_member(j_object, "result", "failure"); + } else { int complete_flags = 0; if (vconf_get_int(VCONFKEY_STICKER_SYNC_COMPLETE, &complete_flags) == 0) { @@ -564,25 +596,30 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in } json_object_set_string_member(j_object, "result", "success"); - - if (current_request.mode == string("manual")) { - if (!sync_alarm_exist()) - sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL); - } + sync_success_cnt++; } if (_send_json_data(j_object) == FALSE) LOGE("Failed to send message"); + json_object_unref(j_object); + send_message("sync_stop_result", reason.c_str()); - json_object_unref(j_object); + if (!process_request_queue()) { + if (sync_success_cnt > 0 && current_request.mode == string("manual")) { + if (!sync_alarm_exist()) + sync_alarm_register(APP_CONTROL_OPERATION_SYNC_ALARM, SYNC_ALARM_DELAY, SYNC_ALARM_INTERVAL); + } + + sync_success_cnt = 0; + + service_app_exit(); + } current_request.mode.clear(); current_request.category.clear(); current_request.type.clear(); - - service_app_exit(); } else LOGW("unknown msg id : %s", msg_id.c_str()); @@ -655,25 +692,7 @@ _on_service_connection_created(sap_peer_agent_h peer_agent, priv->socket = socket; LOGI("Connection Established"); - LOGD("pending_request : %d", pending_request.req_type); - - if (pending_request.req_type == REQUEST_TYPE_FEATURE_REQ) { - LOGD("[Request feature exchange]"); - request_sticker_feature(); - } - else if (pending_request.req_type == REQUEST_TYPE_SYNC) { - if (!pending_request.mode.empty()) { - LOGD("[Request to sync sticker] mode: %s, category: %s, type : %s", pending_request.mode.c_str(), - pending_request.category.c_str(), - pending_request.type.c_str()); - - request_sticker_data(pending_request.mode.c_str(), pending_request.category.c_str(), pending_request.type.c_str()); - - pending_request.mode.clear(); - pending_request.category.clear(); - pending_request.type.clear(); - } - } + process_request_queue(); break; diff --git a/receiver/src/main.cpp b/receiver/src/main.cpp index 7a5e20d..3fd98e1 100644 --- a/receiver/src/main.cpp +++ b/receiver/src/main.cpp @@ -117,8 +117,10 @@ static void app_control(app_control_h app_control, void *data) if (param_error) goto cleanup; - if (mode && type) + if (mode && type) { request_sticker_data(mode, "arsticker", type); + request_sticker_data(mode, "bitmoji", type); + } } else if (strcmp(request, "oobe") == 0) { LOGI("[OOBE] register sync alarm");