make app2sd more robust on some failure cases. 60/93360/5 accepted/tizen/3.0/ivi/20161028.123021 accepted/tizen/3.0/mobile/20161028.122323 accepted/tizen/3.0/tv/20161028.122613 accepted/tizen/3.0/wearable/20161028.122827 accepted/tizen/common/20161024.135234 accepted/tizen/ivi/20161024.234110 accepted/tizen/mobile/20161024.234016 accepted/tizen/tv/20161024.234036 accepted/tizen/wearable/20161024.234052 submit/tizen/20161024.111622 submit/tizen_3.0/20161028.062323 submit/tizen_3.0/20161028.082323 submit/tizen_3.0_common/20161104.104000
authorjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 24 Oct 2016 01:56:16 +0000 (10:56 +0900)
committerjongmyeongko <jongmyeong.ko@samsung.com>
Mon, 24 Oct 2016 06:42:45 +0000 (15:42 +0900)
- ensure a given waiting time before app2sd-server is terminated
- apply retrial logic for client api

Change-Id: I733bf20313f72ccd7350aeea5ef35c9395be2527
Signed-off-by: jongmyeongko <jongmyeong.ko@samsung.com>
plugin/app2sd/src/app2sd_client_interface.c
plugin/app2sd/src/app2sd_server.c

index 427d58e..0e34756 100644 (file)
@@ -32,6 +32,9 @@
 #include "app2sd_client_interface.h"
 #include "app2ext_utils.h"
 
+#define CONNECTION_RETRY_MAX 5
+#define CONNECTION_WAIT_USEC (1000000 / 2) /* 0.5 sec */
+
 static int app2sd_gdbus_shared_connection(GDBusConnection **connection)
 {
        GError *error = NULL;
@@ -58,6 +61,7 @@ static int __app2sd_call_server_method(const gchar *method_name,
 {
        int ret = APP2EXT_SUCCESS;
        int result = 0;
+       int retry_cnt = 0;
        GDBusConnection *conn = NULL;
        GDBusProxy *proxy = NULL;
        GError *error = NULL;
@@ -71,34 +75,44 @@ static int __app2sd_call_server_method(const gchar *method_name,
        }
 
        /* method call */
-       proxy = g_dbus_proxy_new_sync(conn,
-               G_DBUS_PROXY_FLAGS_NONE, NULL,
-               APP2SD_BUS_NAME, APP2SD_OBJECT_PATH, APP2SD_INTERFACE_NAME,
-               NULL, &error);
-       if (proxy == NULL) {
-               _E("failed to create new proxy, error(%s)", error->message);
-               g_error_free(error);
-               ret = APP2EXT_ERROR_DBUS_FAILED;
-               goto out;
-       }
+       do {
+               proxy = g_dbus_proxy_new_sync(conn,
+                       G_DBUS_PROXY_FLAGS_NONE, NULL,
+                       APP2SD_BUS_NAME, APP2SD_OBJECT_PATH,
+                       APP2SD_INTERFACE_NAME,
+                       NULL, &error);
+               if (proxy == NULL) {
+                       _E("failed to create new proxy, error(%s)",
+                               error->message);
+                       g_error_free(error);
+                       ret = APP2EXT_ERROR_DBUS_FAILED;
+                       retry_cnt++;
+                       usleep(CONNECTION_WAIT_USEC);
+                       continue;
+               }
 
-       value = g_dbus_proxy_call_sync(proxy, method_name, param,
-               G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &error);
-       if (error != NULL) {
-               _E("proxy call sync error(%s)", error->message);
-               g_error_free(error);
-               ret = APP2EXT_ERROR_DBUS_FAILED;
-               goto out;
-       }
+               value = g_dbus_proxy_call_sync(proxy, method_name, param,
+                       G_DBUS_CALL_FLAGS_NONE, G_MAXINT, NULL, &error);
+               g_object_unref(proxy);
+               if (error != NULL) {
+                       _E("proxy call sync error(%s)", error->message);
+                       g_error_free(error);
+                       ret = APP2EXT_ERROR_DBUS_FAILED;
+                       retry_cnt++;
+                       usleep(CONNECTION_WAIT_USEC);
+                       continue;
+               }
+
+               g_variant_get(value, "(i)", &result);
+               g_variant_unref(value);
 
-       g_variant_get(value, "(i)", &result);
-       g_variant_unref(value);
+               _D("result(%d)", result);
+               if (result)
+                       ret = result;
 
-       _D("result(%d)", result);
-       if (result)
-               ret = result;
+               break;
+       } while (retry_cnt <= CONNECTION_RETRY_MAX);
 
-out:
        if (conn)
                g_object_unref(conn);
 
index 04afa1e..cd863af 100644 (file)
@@ -24,6 +24,7 @@
 #define APPFW_UID 301
 
 int processing_busy_cnt;
+guint source_id;
 
 GMainLoop *app2sd_mainloop = NULL;
 
@@ -766,7 +767,9 @@ static void handle_method_call(GDBusConnection *connection,
                        parameters, invocation, sender_uid);
        }
 
-       g_timeout_add_seconds(5, __exit_app2sd_server, NULL);
+       if (source_id)
+               g_source_remove(source_id);
+       source_id = g_timeout_add_seconds(5, __exit_app2sd_server, NULL);
        processing_busy_cnt--;
 }