Notify total sync progress 25/226625/5
authorJihoon Kim <jihoon48.kim@samsung.com>
Wed, 4 Mar 2020 07:33:06 +0000 (16:33 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 5 Mar 2020 12:11:35 +0000 (21:11 +0900)
Change-Id: I190b9c1ab519b80abd3dbf1af91613eea2dd30d2
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
packaging/capi-ui-sticker.spec
receiver/CMakeLists.txt
receiver/inc/message.h [new file with mode: 0644]
receiver/src/ft.cpp
receiver/src/message.cpp [new file with mode: 0644]

index 269d1fb..d0a5352 100644 (file)
@@ -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
 
index 247230a..7838d26 100644 (file)
@@ -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 (file)
index 0000000..392f1cd
--- /dev/null
@@ -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 <glib.h>
+#include <message_port.h>
+
+#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__ */
index b926aca..7e22b1c 100644 (file)
@@ -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 (file)
index 0000000..4513000
--- /dev/null
@@ -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 <stdlib.h>
+
+#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