Add a flag to check initialization 70/269870/3
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 21 Jan 2022 04:54:49 +0000 (13:54 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Fri, 21 Jan 2022 04:58:54 +0000 (13:58 +0900)
If autofill_service_initialize() is already called, the function returns 0.

Change-Id: I353be90f95a83bd519cf9ce2f81ab8781a23bf02
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
service_lib/autofill_service.c

index 54be707..45ecc6a 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -62,6 +63,7 @@ typedef struct {
 } autofill_svc_s;
 
 static GList *__client_list = NULL;
+static bool __initialized;
 
 //LCOV_EXCL_START
 static bool __autofill_item_cb(rpc_port_stub_autofill_svc_item_h items, void *user_data)
@@ -465,6 +467,9 @@ EXPORT_API int autofill_service_initialize(void)
 {
     LOGI("autofill service initialize");
 
+    if (__initialized)
+        return AUTOFILL_ERROR_NONE;
+
     int ret;
 
     rpc_port_stub_AutofillSvcPort_callback_s callback = {
@@ -480,10 +485,12 @@ EXPORT_API int autofill_service_initialize(void)
     };
 
     ret = rpc_port_stub_AutofillSvcPort_register(&callback, NULL);
-    if (ret != 0)
+    if (ret != 0) {
         LOGW("Failed to register message");
-    else
+    } else {
         LOGI("Succeeded to register message");
+        __initialized = true;
+    }
 
     return ret;
 }
@@ -492,12 +499,16 @@ EXPORT_API int autofill_service_deinitialize(void)
 {
     LOGI("autofill service deinitialize");
 
+    if (!__initialized)
+        return AUTOFILL_ERROR_NONE;
+
     if (__client_list) {
         g_list_free_full(__client_list, __destroy_client);
         __client_list = NULL;
     }
 
     rpc_port_stub_AutofillSvcPort_unregister();
+    __initialized = false;
 
     return AUTOFILL_ERROR_NONE;
 }