Merge branch 'tizen_5.5' into tizen 24/228824/1 submit/tizen/20200326.032838
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 26 Mar 2020 03:16:13 +0000 (12:16 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Thu, 26 Mar 2020 03:16:21 +0000 (12:16 +0900)
Change-Id: I6bb014c11434d41ff37edbcfc8a3d37e3abcd1a2

packaging/capi-ui-sticker.spec
receiver/inc/ft.h
receiver/inc/sticker_request.h [new file with mode: 0644]
receiver/src/ft.cpp
receiver/src/main.cpp
receiver/src/message.cpp
receiver/tizen-manifest.xml

index ecf1cd0..ba3d59b 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-ui-sticker
 Summary:    Sticker client library and daemon
-Version:    0.1.24
+Version:    0.1.25
 Release:    1
 Group:      Graphics & UI Framework/Input
 License:    Apache-2.0
index a95204c..10ccb0e 100644 (file)
@@ -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 (file)
index 0000000..9c8089f
--- /dev/null
@@ -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 <string>
+
+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__ */
index 4a2ec79..e6f085b 100644 (file)
 #include <pwd.h>
 #include <json-glib/json-glib.h>
 #include <vconf.h>
+#include <queue>
 
 #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"
 
 
 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<StickerRequest> 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 rec_file_cnt_in_group = 0;
+static int total_file_count_in_group = 0;
+static int sync_success_cnt = 0;
 
 static gboolean _send_json_data(JsonObject *obj)
 {
@@ -137,15 +129,11 @@ cleanup:
 
 static void notify_sync_progress(unsigned int file_progress)
 {
-    if (total_file_count == 0)
+    if (total_file_count_in_group == 0)
         return;
 
-    double total_progress = (((double)rec_file_cnt / (double)total_file_count) + (1.0/(double)total_file_count*file_progress/100))*100;
-
-    LOGI("(%2d / %2d), file progress : %3u%%, total progress : %3u%%", 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);
+    LOGI("(%2d / %2d), file progress : %3u%%", rec_file_cnt_in_group+1, total_file_count_in_group, file_progress);
+    send_message("sync_progress", NULL);
 }
 
 static void _on_send_completed(sap_file_transaction_h file_transaction,
@@ -175,7 +163,7 @@ static void _on_send_completed(sap_file_transaction_h file_transaction,
             }
         }
 
-        rec_file_cnt++;
+        rec_file_cnt_in_group++;
     } else {
         switch (result) {
             case (SAP_FT_TRANSFER_FAIL_CHANNEL_IO): {
@@ -271,12 +259,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)
 {
-    JsonObject *j_object = json_object_new();
+    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 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);
@@ -286,26 +290,35 @@ void request_sticker_data(const char *mode, const char *category, const char *ty
     json_object_set_string_member(j_object, "type", type);
 
     if (_send_json_data(j_object) == FALSE) {
-        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");
-
-        LOGI("Push sync request");
+        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.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()
 {
-    JsonObject *j_object = json_object_new();
+    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;
+    }
+
+    j_object = json_object_new();
     if (j_object == NULL) {
         LOGE("json object create error");
         return;
@@ -315,7 +328,6 @@ void request_sticker_feature()
     json_object_set_int_member(j_object, "tID", ++t_id);
 
     if (_send_json_data(j_object) == FALSE) {
-        pending_request.req_type = REQUEST_TYPE_FEATURE_REQ;
         LOGE("Failed to send STICKER_SYNC_FEATURE_REQ");
     }
 
@@ -379,6 +391,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,
@@ -435,7 +470,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");
@@ -458,12 +495,15 @@ 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;
-        rec_file_cnt = 0;
+        total_file_count_in_group = 0;
+        rec_file_cnt_in_group = 0;
         t_id = json_object_get_int_member(root_obj, "tID");
         JsonArray *file_list = json_object_get_array_member(root_obj, "list");
         if (file_list) {
@@ -476,7 +516,7 @@ on_data_received(sap_socket_h socket, unsigned short int channel_id, unsigned in
 
                 if (file_len > 0) {
                     LOGD("Add file : %s, len : %d", file_name.c_str(), file_len);
-                    total_file_count++;
+                    total_file_count_in_group++;
                 } else {
                     LOGD("Delete file : %s, len : %d", file_name.c_str(), file_len);
                     if (create_sticker_provider_handle() == STICKER_ERROR_NONE) {
@@ -529,8 +569,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_in_group != 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) {
@@ -551,25 +592,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());
 
@@ -642,25 +688,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;
 
index 7a5e20d..3fd98e1 100644 (file)
@@ -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");
index f67b29e..8dde6a6 100644 (file)
@@ -72,7 +72,8 @@ bool send_message(const char *cmd, const char *data)
 
     bundle *b = bundle_create();
     bundle_add_str(b, "command", cmd);
-    bundle_add_str(b, "data", data);
+    if (data)
+        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);
@@ -87,4 +88,4 @@ bool send_message(const char *cmd, const char *data)
     bundle_free(b);
 
     return result;
-}
\ No newline at end of file
+}
index aeaa201..71b376e 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
-<manifest xmlns="http://tizen.org/ns/packages" api-version="5.5" package="org.tizen.sticker-receiver" version="1.0.24">
+<manifest xmlns="http://tizen.org/ns/packages" api-version="5.5" package="org.tizen.sticker-receiver" version="1.0.25">
         <profile name="wearable" />
         <service-application appid="org.tizen.sticker-receiver" exec="sticker-receiver" type="capp" multiple="false" taskmanage="false" nodisplay="true" launch_mode="single">
         <label>sticker-receiver</label>