From: Jihoon Kim Date: Wed, 4 Mar 2020 07:33:06 +0000 (+0900) Subject: Notify total sync progress X-Git-Tag: accepted/tizen/5.5/unified/20200306.124905~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=12ff94b22ef8b0c32a0993e9cb3fef8a009936b6;p=platform%2Fcore%2Fuifw%2Fcapi-ui-sticker.git Notify total sync progress Change-Id: I190b9c1ab519b80abd3dbf1af91613eea2dd30d2 Signed-off-by: Jihoon Kim --- diff --git a/packaging/capi-ui-sticker.spec b/packaging/capi-ui-sticker.spec index 269d1fb..d0a5352 100644 --- a/packaging/capi-ui-sticker.spec +++ b/packaging/capi-ui-sticker.spec @@ -27,6 +27,7 @@ BuildRequires: pkgconfig(sqlite3) %if 0%{?sec_product_feature_profile_wearable} BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-appfw-service-application) +BuildRequires: pkgconfig(capi-message-port) BuildRequires: pkgconfig(sap-client-stub-api) BuildRequires: hash-signer diff --git a/receiver/CMakeLists.txt b/receiver/CMakeLists.txt index 247230a..7838d26 100644 --- a/receiver/CMakeLists.txt +++ b/receiver/CMakeLists.txt @@ -5,6 +5,7 @@ SET(SRCS src/main.cpp src/ft.cpp src/sticker_info.cpp + src/message.cpp ) INCLUDE(FindPkgConfig) @@ -12,6 +13,7 @@ pkg_check_modules(pkgs_test REQUIRED capi-base-common dlog capi-appfw-service-application + capi-message-port sap-client-stub-api json-glib-1.0 ) diff --git a/receiver/inc/message.h b/receiver/inc/message.h new file mode 100644 index 0000000..392f1cd --- /dev/null +++ b/receiver/inc/message.h @@ -0,0 +1,26 @@ +/* + * 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. + */ +#include +#include + +#ifndef __MESSAGE_H__ +#define __MESSAGE_H__ + +bool message_sink_init(message_port_message_cb callback, void *user_data); +void message_sink_shutdown(void); +bool send_message(const char *cmd, const char *data); + +#endif /* __MESSAGE_H__ */ diff --git a/receiver/src/ft.cpp b/receiver/src/ft.cpp index b926aca..7e22b1c 100644 --- a/receiver/src/ft.cpp +++ b/receiver/src/ft.cpp @@ -34,6 +34,7 @@ #include "ft.h" #include "log.h" #include "sticker_info.h" +#include "message.h" #define ACCESSORY_SERVICE_PROFILE_ID "/sample/filetransfersender" #define ACCESSORY_SERVICE_CHANNEL_ID 107 @@ -84,6 +85,7 @@ 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 gboolean _send_json_data(JsonObject *obj) { @@ -132,6 +134,19 @@ cleanup: return result ? FALSE : TRUE; } +static void notify_sync_progress(unsigned int file_progress) +{ + if (total_file_count == 0) + return; + + double total_progress = (((double)rec_file_cnt / (double)total_file_count) + (1.0/(double)total_file_count*file_progress/100))*100; + + LOGI("recv : %d, total : %d, file_progress : %d, %u%%", rec_file_cnt, total_file_count, file_progress, (unsigned int)total_progress); + char progress_str[32]; + snprintf(progress_str, sizeof(progress_str), "%u", (unsigned int)total_progress); + send_message("sync_progress", progress_str); +} + static void _on_send_completed(sap_file_transaction_h file_transaction, sap_ft_transfer_e result, const char *file_path, @@ -216,6 +231,7 @@ static void _on_sending_file_in_progress(sap_file_transaction_h file_transaction void *user_data) { LOGI("# progress %d", percentage_progress); + notify_sync_progress(percentage_progress); } static void __set_file_transfer_cb(sap_file_transaction_h file_socket) @@ -392,6 +408,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in LOGD("result : %s, resultCode : %d", result.c_str(), result_code); } else if (msg_id == STICKER_SEND_START_REQ) { LOGD("msg : %s", msg_id.c_str()); + total_file_count = 0; rec_file_cnt = 0; t_id = json_object_get_int_member(root_obj, "tID"); JsonArray *file_list = json_object_get_array_member(root_obj, "list"); @@ -408,6 +425,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in if (file_len > 0) { LOGD("fileName : %s, len : %d", file_name.c_str(), file_len); + total_file_count++; } else { // Delete sticker LOGD("fileName : %s, len : %d", file_name.c_str(), file_len); diff --git a/receiver/src/message.cpp b/receiver/src/message.cpp new file mode 100644 index 0000000..4513000 --- /dev/null +++ b/receiver/src/message.cpp @@ -0,0 +1,88 @@ +/* + * 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. + */ + +#include + +#include "message.h" +#include "log.h" + +#define REMOTE_APP_ID "com.samsung.w-input-selector" +#define MESSAGE_PORT_REMOTE_NAME REMOTE_APP_ID"_msg_port_rcv" + +static int port_id = -1; + +bool message_sink_init(message_port_message_cb callback, void *user_data) +{ + port_id = message_port_register_local_port(MESSAGE_PORT_REMOTE_NAME, callback, user_data); + if (port_id < 0) + { + LOGW("Function message_port_register_local_port() failed."); + return false; + } + + return true; +} + +void message_sink_shutdown(void) +{ + int ret; + bool exists = false; + + port_id = -1; + + ret = message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &exists); + if (exists) + { + ret = message_port_unregister_local_port(port_id); + if (ret != MESSAGE_PORT_ERROR_NONE) + LOGE("Function message_port_unregister_local_port() failed."); + } + else if (ret != MESSAGE_PORT_ERROR_NONE) + { + LOGE("Function message_port_check_remote_port() failed."); + } +} + +bool send_message(const char *cmd, const char *data) +{ + bool result = false; + int ret; + bool found = false; + + message_port_check_remote_port(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, &found); + if (!found) { + LOGW("Can't find remote port"); + return false; + } + + bundle *b = bundle_create(); + bundle_add_str(b, "command", cmd); + bundle_add_str(b, "data", data); + ret = message_port_send_message(REMOTE_APP_ID, MESSAGE_PORT_REMOTE_NAME, b); + if (ret != MESSAGE_PORT_ERROR_NONE) { + LOGW("message port send message error. err : %d", ret); + result = false; + } + else + { + LOGI("send message done"); + result = true; + } + + bundle_free(b); + + return result; +} \ No newline at end of file