Process pending request after autofill service connects 16/244116/3
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 15 Sep 2020 06:17:39 +0000 (15:17 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 15 Sep 2020 10:23:43 +0000 (19:23 +0900)
Change-Id: I698c6a115ba0109628148d1bd957a18315def86b
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
CMakeLists.txt
src/autofill-daemon.c
src/autofill_config.c
src/autofill_request_item.h [new file with mode: 0644]
src/autofill_request_list.c [new file with mode: 0644]
src/autofill_request_list.h [new file with mode: 0644]

index 000d611..96baa4a 100644 (file)
@@ -4,6 +4,7 @@ PROJECT(autofilld C)
 SET(SRCS
     src/autofill-daemon.c
     src/autofill_config.c
+    src/autofill_request_list.c
     src/autofill_stub.c
     src/autofill_manager_stub.c
     src/autofill_service_proxy.c
index 4e3f01d..8ff8cee 100644 (file)
@@ -28,6 +28,8 @@
 #include "autofill_service_proxy.h"
 #include "autofill_manager_stub.h"
 #include "autofill_config.h"
+#include "autofill_request_item.h"
+#include "autofill_request_list.h"
 
 #define RECONNECT_PERIOD 1.0
 
@@ -366,12 +368,10 @@ static int __auth_info_request_cb(rpc_port_stub_AutofillAppPort_context_h contex
 
     if (!g_autofill_service_connected) {
         LOGW("Not connected to autofill service");
-        return 0;
     }
 
     if (!svc_rpc_h) {
         LOGW("RPC port for autofill service is not created");
-        return 0;
     }
 
     rpc_port_stub_AutofillAppPort_context_get_sender(context, &sender);
@@ -390,9 +390,14 @@ static int __auth_info_request_cb(rpc_port_stub_AutofillAppPort_context_h contex
 
     rpc_port_autofill_view_info_foreach_items(vi, __view_info_item_cb, svi);
 
-    rpc_port_proxy_AutofillSvcPort_invoke_request_auth_info(svc_rpc_h, context_id, svi);
-
-    rpc_port_autofill_svc_view_info_destroy(svi);
+    if (g_autofill_service_connected && svc_rpc_h) {
+        rpc_port_proxy_AutofillSvcPort_invoke_request_auth_info(svc_rpc_h, context_id, svi);
+        rpc_port_autofill_svc_view_info_destroy(svi);
+    }
+    else {
+        LOGI("Add auth info request in pending list");
+        add_request_item(AUTH_INFO_REQUEST, context_id, svi);
+    }
 
 end:
     if (sender) {
@@ -413,12 +418,10 @@ static int __autofill_fill_request_cb(rpc_port_stub_AutofillAppPort_context_h co
 
     if (!g_autofill_service_connected) {
         LOGW("Not connected to autofill service");
-        return 0;
     }
 
     if (!svc_rpc_h) {
         LOGW("RPC port for autofill service is not created");
-        return 0;
     }
 
     rpc_port_stub_AutofillAppPort_context_get_sender(context, &sender);
@@ -436,9 +439,15 @@ static int __autofill_fill_request_cb(rpc_port_stub_AutofillAppPort_context_h co
 
     rpc_port_autofill_view_info_foreach_items(vi, __view_info_item_cb, svi);
 
-    rpc_port_proxy_AutofillSvcPort_invoke_send_fill_request(svc_rpc_h, context_id, svi);
+    if (g_autofill_service_connected && svc_rpc_h) {
+        rpc_port_proxy_AutofillSvcPort_invoke_send_fill_request(svc_rpc_h, context_id, svi);
 
-    rpc_port_autofill_svc_view_info_destroy(svi);
+        rpc_port_autofill_svc_view_info_destroy(svi);
+    }
+    else {
+        LOGI("Add fill request in pending list");
+        add_request_item(FILL_REQUEST, context_id, svi);
+    }
 
 end:
     if (sender)
@@ -457,12 +466,10 @@ static int __autofill_cancel_fill_request_cb(rpc_port_stub_AutofillAppPort_conte
 
     if (!g_autofill_service_connected) {
         LOGW("Not connected to autofill service");
-        return 0;
     }
 
     if (!svc_rpc_h) {
         LOGW("RPC port for autofill service is not created");
-        return 0;
     }
 
     rpc_port_stub_AutofillAppPort_context_get_sender(context, &sender);
@@ -480,9 +487,15 @@ static int __autofill_cancel_fill_request_cb(rpc_port_stub_AutofillAppPort_conte
 
     rpc_port_autofill_view_info_foreach_items(vi, __view_info_item_cb, svi);
 
-    rpc_port_proxy_AutofillSvcPort_invoke_cancel_fill_request(svc_rpc_h, context_id, svi);
+    if (g_autofill_service_connected && svc_rpc_h) {
+        rpc_port_proxy_AutofillSvcPort_invoke_cancel_fill_request(svc_rpc_h, context_id, svi);
 
-    rpc_port_autofill_svc_view_info_destroy(svi);
+        rpc_port_autofill_svc_view_info_destroy(svi);
+    }
+    else {
+        LOGI("Add cancel fill request in pending list");
+        add_request_item(CANCEL_FILL_REQUEST, context_id, svi);
+    }
 
 end:
     if (sender)
@@ -746,6 +759,8 @@ static void __on_autofill_service_connected(rpc_port_proxy_AutofillSvcPort_h h,
         LOGW("Failed to invoke Register");
 
     g_autofill_service_connected = true;
+
+    process_pending_request(svc_rpc_h);
 }
 
 static Eina_Bool connect_timer_cb(void *data)
@@ -1032,6 +1047,8 @@ void service_app_terminate(void *data)
         __client_list = NULL;
     }
 
+    remove_all_pending_request_item_list();
+
     if (g_connect_timer) {
         ecore_timer_del(g_connect_timer);
         g_connect_timer = NULL;
index 6e5f099..0443107 100644 (file)
@@ -1,18 +1,18 @@
  /*
- * Copyright (c) 2018 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.
- */
 * Copyright (c) 2018 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 <tizen.h>
 #include <stdlib.h>
diff --git a/src/autofill_request_item.h b/src/autofill_request_item.h
new file mode 100644 (file)
index 0000000..eb121b4
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * 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 __AUTOFILL_REQUEST_ITEM_H__
+#define __AUTOFILL_REQUEST_ITEM_H__
+
+typedef enum {
+    AUTH_INFO_REQUEST,
+    FILL_REQUEST,
+    CANCEL_FILL_REQUEST,
+} autofill_request_type;
+
+typedef struct {
+    autofill_request_type req_type;
+    int context_id;
+    void *req_data;
+} autofill_request_item_s;
+
+#endif /* __AUTOFILL_REQUEST_ITEM_H__ */
diff --git a/src/autofill_request_list.c b/src/autofill_request_list.c
new file mode 100644 (file)
index 0000000..c767190
--- /dev/null
@@ -0,0 +1,111 @@
+ /*
+  * 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 <tizen.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <glib.h>
+#include <dlog.h>
+
+#include "autofill_daemon_dlog.h"
+#include "autofill_request_item.h"
+#include "autofill_service_proxy.h"
+
+static GList *__pending_request_item_list = NULL;
+
+static void __destroy_pending_request(gpointer data)
+{
+    LOGD("");
+    autofill_request_item_s *handle = data;
+
+    if (!handle)
+        return;
+
+    rpc_port_autofill_svc_view_info_h svi = handle->req_data;
+
+    switch (handle->req_type) {
+        case AUTH_INFO_REQUEST:
+        case FILL_REQUEST:
+        case CANCEL_FILL_REQUEST:
+            rpc_port_autofill_svc_view_info_destroy(svi);
+            break;
+        default:
+            break;
+    }
+
+    free(handle);
+}
+
+void add_request_item(autofill_request_type type, int context_id, void *req_data)
+{
+    autofill_request_item_s* request_item_h = calloc(1, sizeof(autofill_request_item_s));
+    request_item_h->req_type = type;
+    request_item_h->req_data = (void *)req_data;
+    request_item_h->context_id = context_id;
+
+    __pending_request_item_list = g_list_append(__pending_request_item_list, request_item_h);
+}
+
+void remove_all_pending_request_item_list()
+{
+    if (__pending_request_item_list) {
+        g_list_free_full(__pending_request_item_list, __destroy_pending_request);
+        __pending_request_item_list = NULL;
+    }
+}
+
+void process_pending_request(rpc_port_proxy_AutofillSvcPort_h svc_rpc_h)
+{
+    autofill_request_item_s *req_item;
+    GList *iter;
+
+    LOGD("");
+
+    iter = __pending_request_item_list;
+    while (iter) {
+        req_item = iter->data;
+
+        iter = g_list_next(iter);
+
+        if (!req_item) {
+            LOGW("Warning: value is NULL");
+            continue;
+        }
+
+        LOGD("type : %d", req_item->req_type);
+
+        rpc_port_autofill_svc_view_info_h svi = req_item->req_data;
+
+        switch (req_item->req_type) {
+            case AUTH_INFO_REQUEST:
+                LOGD("auth info request. context id : %d", req_item->context_id);
+                rpc_port_proxy_AutofillSvcPort_invoke_request_auth_info(svc_rpc_h, req_item->context_id, svi);
+                break;
+            case FILL_REQUEST:
+                LOGD("fill request. context id : %d", req_item->context_id);
+                rpc_port_proxy_AutofillSvcPort_invoke_send_fill_request(svc_rpc_h, req_item->context_id, svi);
+                break;
+            case CANCEL_FILL_REQUEST:
+                LOGD("cancel fill request. context id : %d", req_item->context_id);
+                rpc_port_proxy_AutofillSvcPort_invoke_cancel_fill_request(svc_rpc_h, req_item->context_id, svi);
+                break;
+            default:
+                break;
+        }
+    }
+
+    remove_all_pending_request_item_list();
+}
diff --git a/src/autofill_request_list.h b/src/autofill_request_list.h
new file mode 100644 (file)
index 0000000..53995d5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * 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 __AUTOFILL_REQUEST_LIST_H__
+#define __AUTOFILL_REQUEST_LIST_H__
+
+#include "autofill_request_item.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+void add_request_item(autofill_request_type type, int context_id, void *req_data);
+void remove_all_pending_request_item_list();
+void process_pending_request(rpc_port_proxy_AutofillSvcPort_h svc_rpc_h);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUTOFILL_REQUEST_LIST_H__ */