Split autofill client code 54/244154/5
authorJihoon Kim <jihoon48.kim@samsung.com>
Tue, 15 Sep 2020 08:57:21 +0000 (17:57 +0900)
committerJihoon Kim <jihoon48.kim@samsung.com>
Tue, 15 Sep 2020 10:24:34 +0000 (19:24 +0900)
Change-Id: Ibbb13d6b90eb5b62f227b495faed53294f150c7b
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
CMakeLists.txt
src/autofill-daemon.c
src/autofill_client.c [new file with mode: 0644]
src/autofill_client.h [new file with mode: 0644]
src/autofill_client_list.c [new file with mode: 0644]
src/autofill_client_list.h [new file with mode: 0644]

index 96baa4a..4ffcd2f 100644 (file)
@@ -5,6 +5,8 @@ SET(SRCS
     src/autofill-daemon.c
     src/autofill_config.c
     src/autofill_request_list.c
+    src/autofill_client.c
+    src/autofill_client_list.c
     src/autofill_stub.c
     src/autofill_manager_stub.c
     src/autofill_service_proxy.c
index 8ff8cee..31a1858 100644 (file)
@@ -27,6 +27,7 @@
 #include "autofill_stub.h"
 #include "autofill_service_proxy.h"
 #include "autofill_manager_stub.h"
+#include "autofill_client_list.h"
 #include "autofill_config.h"
 #include "autofill_request_item.h"
 #include "autofill_request_list.h"
@@ -38,133 +39,12 @@ static rpc_port_AutofillSvcPort_autofill_svc_fill_response_cb_h fill_response_re
 static rpc_port_AutofillSvcPort_autofill_svc_auth_info_cb_h auth_info_cb_h = NULL;
 static rpc_port_AutofillSvcPort_autofill_svc_send_error_cb_h error_info_cb_h = NULL;
 
-typedef struct {
-    char *app_id;
-    int context_id;
-
-    rpc_port_AutofillAppPort_autofill_auth_info_received_cb_h auth_info_cb;
-    rpc_port_AutofillAppPort_autofill_fill_response_received_cb_h fill_response_received_cb;
-    rpc_port_AutofillAppPort_autofill_error_info_received_cb_h error_info_cb;
-} autofill_client_s;
-
-static GList *__client_list = NULL;
 static Ecore_Timer *g_connect_timer = NULL;
 static bool g_autofill_service_connected = false;
 
 static bool connect_service();
 static void terminate_autofill_service();
 
-static autofill_client_s *
-get_autofill_client(const char *app_id, int context_id)
-{
-    GList *iter;
-    autofill_client_s *client;
-
-    iter = __client_list;
-    while (iter) {
-        client = iter->data;
-
-        iter = g_list_next(iter);
-
-        if (!client) {
-            LOGW("Warning: value is NULL");
-            continue;
-        }
-
-        if ((client->context_id == context_id) &&
-            client->app_id && strcmp(client->app_id, app_id) == 0) {
-            return client;
-        }
-    }
-
-    return NULL;
-}
-
-static autofill_client_s *__create_client(const char *app_id, int context_id,
-        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_h auth_info_cb,
-        rpc_port_AutofillAppPort_autofill_fill_response_received_cb_h fill_response_received_cb,
-        rpc_port_AutofillAppPort_autofill_error_info_received_cb_h error_info_cb)
-{
-    LOGD("");
-    autofill_client_s *handle;
-
-    handle = calloc(1, sizeof(autofill_client_s));
-    if (!handle) {
-        LOGE("Out of memory");
-        return NULL;
-    }
-
-    handle->app_id = strdup(app_id);
-    if (!handle->app_id) {
-        LOGE("Out of memory");
-        free(handle);
-        return NULL;
-    }
-
-    handle->context_id = context_id;
-
-    rpc_port_AutofillAppPort_autofill_auth_info_received_cb_clone(auth_info_cb, &handle->auth_info_cb);
-    if (!handle->auth_info_cb) {
-        LOGE("Out of memory");
-        free(handle->app_id);
-        free(handle);
-        return NULL;
-    }
-
-    rpc_port_AutofillAppPort_autofill_fill_response_received_cb_clone(fill_response_received_cb, &handle->fill_response_received_cb);
-
-    if (!handle->fill_response_received_cb) {
-        LOGE("Out of memory");
-        free(handle->app_id);
-        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_destroy(handle->auth_info_cb);
-        free(handle);
-        return NULL;
-    }
-
-    rpc_port_AutofillAppPort_autofill_error_info_received_cb_clone(error_info_cb, &handle->error_info_cb);
-    if (!handle->error_info_cb) {
-        LOGE("Out of memory");
-        free(handle->app_id);
-        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_destroy(handle->auth_info_cb);
-        rpc_port_AutofillAppPort_autofill_fill_response_received_cb_destroy(handle->fill_response_received_cb);
-        free(handle);
-        return NULL;
-    }
-
-    return handle;
-}
-
-static void __destroy_client(gpointer data)
-{
-    LOGD("");
-    autofill_client_s *handle = data;
-
-    if (!handle)
-        return;
-
-    if (handle->auth_info_cb) {
-        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_destroy(handle->auth_info_cb);
-        handle->auth_info_cb = NULL;
-    }
-
-    if (handle->fill_response_received_cb) {
-        rpc_port_AutofillAppPort_autofill_fill_response_received_cb_destroy(handle->fill_response_received_cb);
-        handle->fill_response_received_cb = NULL;
-    }
-
-    if (handle->error_info_cb) {
-        rpc_port_AutofillAppPort_autofill_error_info_received_cb_destroy(handle->error_info_cb);
-        handle->error_info_cb = NULL;
-    }
-
-    if (handle->app_id) {
-        free(handle->app_id);
-        handle->app_id = NULL;
-    }
-
-    free(handle);
-}
-
 static void __remove_client(rpc_port_stub_AutofillAppPort_context_h context)
 {
     autofill_client_s *client = NULL;
@@ -176,10 +56,10 @@ static void __remove_client(rpc_port_stub_AutofillAppPort_context_h context)
 
     LOGI("name(%s)", client->app_id);
 
-    __client_list = g_list_remove(__client_list, client);
-    __destroy_client(client);
+    guint client_list_size = remove_autofill_client_list(client);
+    destroy_autofill_client(client);
 
-    if (g_list_length(__client_list) == 0) {
+    if (client_list_size == 0) {
         terminate_autofill_service();
 
         LOGI("terminate autofill daemon");
@@ -234,13 +114,13 @@ static int __client_register(rpc_port_stub_AutofillAppPort_context_h context,
 
     LOGD("sender(%s)", sender);
 
-    client = __create_client(sender, context_id, auth_info_cb, fill_response_received_cb, error_info_cb);
+    client = create_autofill_client(sender, context_id, auth_info_cb, fill_response_received_cb, error_info_cb);
     free(sender);
 
     if (!client)
         return -1;
 
-    __client_list = g_list_append(__client_list, client);
+    add_autofill_client_list(client);
 
     rpc_port_stub_AutofillAppPort_context_set_tag(context, client);
 
@@ -1042,10 +922,7 @@ void service_app_terminate(void *data)
     // Todo: add your code here.
     LOGD("");
 
-    if (__client_list) {
-        g_list_free_full(__client_list, __destroy_client);
-        __client_list = NULL;
-    }
+    remove_all_client_list();
 
     remove_all_pending_request_item_list();
 
diff --git a/src/autofill_client.c b/src/autofill_client.c
new file mode 100644 (file)
index 0000000..4fea7cd
--- /dev/null
@@ -0,0 +1,109 @@
+ /*
+  * 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_stub.h"
+#include "autofill_client.h"
+
+autofill_client_s *create_autofill_client(const char *app_id, int context_id,
+        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_h auth_info_cb,
+        rpc_port_AutofillAppPort_autofill_fill_response_received_cb_h fill_response_received_cb,
+        rpc_port_AutofillAppPort_autofill_error_info_received_cb_h error_info_cb)
+{
+    LOGD("");
+    autofill_client_s *ac;
+
+    ac = calloc(1, sizeof(autofill_client_s));
+    if (!ac) {
+        LOGE("Out of memory");
+        return NULL;
+    }
+
+    ac->app_id = strdup(app_id);
+    if (!ac->app_id) {
+        LOGE("Out of memory");
+        free(ac);
+        return NULL;
+    }
+
+    ac->context_id = context_id;
+
+    rpc_port_AutofillAppPort_autofill_auth_info_received_cb_clone(auth_info_cb, &ac->auth_info_cb);
+    if (!ac->auth_info_cb) {
+        LOGE("Out of memory");
+        free(ac->app_id);
+        free(ac);
+        return NULL;
+    }
+
+    rpc_port_AutofillAppPort_autofill_fill_response_received_cb_clone(fill_response_received_cb, &ac->fill_response_received_cb);
+
+    if (!ac->fill_response_received_cb) {
+        LOGE("Out of memory");
+        free(ac->app_id);
+        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_destroy(ac->auth_info_cb);
+        free(ac);
+        return NULL;
+    }
+
+    rpc_port_AutofillAppPort_autofill_error_info_received_cb_clone(error_info_cb, &ac->error_info_cb);
+    if (!ac->error_info_cb) {
+        LOGE("Out of memory");
+        free(ac->app_id);
+        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_destroy(ac->auth_info_cb);
+        rpc_port_AutofillAppPort_autofill_fill_response_received_cb_destroy(ac->fill_response_received_cb);
+        free(ac);
+        return NULL;
+    }
+
+    return ac;
+}
+
+void destroy_autofill_client(autofill_client_s *ac)
+{
+    LOGD("");
+
+    if (!ac)
+        return;
+
+    if (ac->auth_info_cb) {
+        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_destroy(ac->auth_info_cb);
+        ac->auth_info_cb = NULL;
+    }
+
+    if (ac->fill_response_received_cb) {
+        rpc_port_AutofillAppPort_autofill_fill_response_received_cb_destroy(ac->fill_response_received_cb);
+        ac->fill_response_received_cb = NULL;
+    }
+
+    if (ac->error_info_cb) {
+        rpc_port_AutofillAppPort_autofill_error_info_received_cb_destroy(ac->error_info_cb);
+        ac->error_info_cb = NULL;
+    }
+
+    if (ac->app_id) {
+        free(ac->app_id);
+        ac->app_id = NULL;
+    }
+
+    free(ac);
+}
diff --git a/src/autofill_client.h b/src/autofill_client.h
new file mode 100644 (file)
index 0000000..a738b02
--- /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_CLIENT_H__
+#define __AUTOFILL_CLIENT_H__
+
+#include "autofill_stub.h"
+
+typedef struct {
+    char *app_id;
+    int context_id;
+
+    rpc_port_AutofillAppPort_autofill_auth_info_received_cb_h auth_info_cb;
+    rpc_port_AutofillAppPort_autofill_fill_response_received_cb_h fill_response_received_cb;
+    rpc_port_AutofillAppPort_autofill_error_info_received_cb_h error_info_cb;
+} autofill_client_s;
+
+autofill_client_s *create_autofill_client(const char *app_id, int context_id,
+        rpc_port_AutofillAppPort_autofill_auth_info_received_cb_h auth_info_cb,
+        rpc_port_AutofillAppPort_autofill_fill_response_received_cb_h fill_response_received_cb,
+        rpc_port_AutofillAppPort_autofill_error_info_received_cb_h error_info_cb);
+
+void destroy_autofill_client(autofill_client_s *ac);
+
+#endif /* __AUTOFILL_CLIENT_H__ */
diff --git a/src/autofill_client_list.c b/src/autofill_client_list.c
new file mode 100644 (file)
index 0000000..628cdcd
--- /dev/null
@@ -0,0 +1,77 @@
+ /*
+  * 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_client.h"
+
+static GList *__client_list = NULL;
+
+guint add_autofill_client_list(autofill_client_s *ac)
+{
+    __client_list = g_list_append(__client_list, ac);
+    return g_list_length(__client_list);
+}
+
+guint remove_autofill_client_list(autofill_client_s *ac)
+{
+    __client_list = g_list_remove(__client_list, ac);
+    return g_list_length(__client_list);
+}
+
+static void destroy_each_client(gpointer data)
+{
+    destroy_autofill_client((autofill_client_s *)data);
+}
+
+void remove_all_client_list()
+{
+    if (__client_list) {
+        g_list_free_full(__client_list, destroy_each_client);
+        __client_list = NULL;
+    }
+}
+
+autofill_client_s *
+get_autofill_client(const char *app_id, int context_id)
+{
+    GList *iter;
+    autofill_client_s *client;
+
+    iter = __client_list;
+    while (iter) {
+        client = iter->data;
+
+        iter = g_list_next(iter);
+
+        if (!client) {
+            LOGW("Warning: value is NULL");
+            continue;
+        }
+
+        if ((client->context_id == context_id) &&
+            client->app_id && strcmp(client->app_id, app_id) == 0) {
+            return client;
+        }
+    }
+
+    return NULL;
+}
\ No newline at end of file
diff --git a/src/autofill_client_list.h b/src/autofill_client_list.h
new file mode 100644 (file)
index 0000000..bc72be1
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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_CLIENT_LIST_H__
+#define __AUTOFILL_CLIENT_LIST_H__
+
+#include <glib.h>
+#include "autofill_stub.h"
+#include "autofill_client.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+guint add_autofill_client_list(autofill_client_s *ac);
+guint remove_autofill_client_list(autofill_client_s *ac);
+
+void remove_all_client_list();
+autofill_client_s *get_autofill_client(const char *app_id, int context_id);
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUTOFILL_CLIENT_LIST_H__ */