Change the dbus call method for 'unregister application' 86/144786/2 accepted/tizen/4.0/unified/20170828.223235 accepted/tizen/unified/20170822.113001 submit/tizen/20170818.052446 submit/tizen_4.0/20170828.100003
authorDoHyun Pyun <dh79.pyun@samsung.com>
Fri, 18 Aug 2017 02:36:29 +0000 (11:36 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Fri, 18 Aug 2017 04:05:38 +0000 (13:05 +0900)
The previous async calling method occurs the crash when TC calls
'gatt deinit' function frequently. Even if bluez provides
the dbus method as async, we can call it using dbus sync call.
It will reduce some timing issue.

Change-Id: Iaa9cb17016180b09291ec7620f1cacb2609a29d3
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-api/bt-gatt-service.c

index 7cb8ee8..c3bfc49 100644 (file)
@@ -37,6 +37,8 @@ static int serv_id = 1;
 static int register_pending_cnt = 0;
 static bool is_server_started = false;
 
+GCancellable *register_cancel;
+
 /* Introspection data for the service we are exporting */
 static const gchar service_introspection_xml[] =
 "<node name='/'>"
@@ -1519,30 +1521,10 @@ void register_application_cb(GObject *object, GAsyncResult *res, gpointer user_d
 
        register_pending_cnt = 0;
 
-       result = g_dbus_proxy_call_finish(G_DBUS_PROXY(object), res, &error);
-
-       if (result == NULL) {
-               /* dBUS-RPC is failed */
-               BT_ERR("Dbus-RPC is failed\n");
-
-               if (error != NULL) {
-               /* dBUS gives error cause */
-                       BT_ERR("D-Bus API failure: errCode[%x], message[%s]\n",
-                                               error->code, error->message);
-                       g_clear_error(&error);
-               }
-       } else {
-               g_variant_unref(result);
+       if (register_cancel) {
+               g_object_unref(register_cancel);
+               register_cancel = NULL;
        }
-}
-
-void unregister_application_cb(GObject *object, GAsyncResult *res,
-               gpointer user_data)
-{
-       BT_INFO("UnregisterApplication is completed");
-
-       GError *error = NULL;
-       GVariant *result;
 
        result = g_dbus_proxy_call_finish(G_DBUS_PROXY(object), res, &error);
 
@@ -1551,9 +1533,9 @@ void unregister_application_cb(GObject *object, GAsyncResult *res,
                BT_ERR("Dbus-RPC is failed\n");
 
                if (error != NULL) {
-                       /* dBUS gives error cause */
+               /* dBUS gives error cause */
                        BT_ERR("D-Bus API failure: errCode[%x], message[%s]\n",
-                                       error->code, error->message);
+                                               error->code, error->message);
                        g_clear_error(&error);
                }
        } else {
@@ -1576,6 +1558,9 @@ BT_EXPORT_API int bluetooth_gatt_unregister_application(void)
        GDBusProxy *proxy = NULL;
 
        if (is_server_started) {
+               GVariant *ret;
+               GError *err = NULL;
+
                proxy = __bt_gatt_gdbus_get_manager_proxy("org.bluez",
                                "/org/bluez/hci0", GATT_MNGR_INTERFACE);
 
@@ -1584,17 +1569,32 @@ BT_EXPORT_API int bluetooth_gatt_unregister_application(void)
 
                BT_INFO("UnregisterApplication");
 
+               is_server_started = false;
+
                /* Async Call to Unregister Service */
-               g_dbus_proxy_call(proxy,
+               ret = g_dbus_proxy_call_sync(proxy,
                                "UnregisterApplication",
                                g_variant_new("(o)",
                                        app_path),
                                G_DBUS_CALL_FLAGS_NONE, -1,
-                               NULL,
-                               (GAsyncReadyCallback) unregister_application_cb,
-                               NULL);
+                               NULL, &err);
+
+               if (ret == NULL) {
+                       /* dBUS-RPC is failed */
+                       BT_ERR("dBUS-RPC is failed");
+                       if (err != NULL) {
+                               /* dBUS gives error cause */
+                               BT_ERR("D-Bus API failure: errCode[%x], message[%s]",
+                               err->code, err->message);
+
+                               g_clear_error(&err);
+                       }
+                       return BLUETOOTH_ERROR_INTERNAL;
+               }
+               g_variant_unref(ret);
+
+               BT_INFO("UnregisterApplication is completed");
 
-               is_server_started = false;
                return BLUETOOTH_ERROR_NONE;
        }
 
@@ -1731,6 +1731,13 @@ failed:
 BT_EXPORT_API int bluetooth_gatt_deinit()
 {
        int ret = BLUETOOTH_ERROR_NONE;
+
+       if (register_cancel) {
+               g_cancellable_cancel(register_cancel);
+               g_object_unref(register_cancel);
+               register_cancel = NULL;
+       }
+
        /* Unown gdbus bus */
        if (owner_id) {
                /* remove/unregister all services */
@@ -2305,12 +2312,19 @@ BT_EXPORT_API int bluetooth_gatt_register_application(void)
 
                BT_INFO("RegisterApplication");
 
+               if (register_cancel) {
+                       g_cancellable_cancel(register_cancel);
+                       g_object_unref(register_cancel);
+               }
+
+               register_cancel = g_cancellable_new();
+
                g_dbus_proxy_call(proxy,
                                "RegisterApplication",
                                g_variant_new("(oa{sv})",
                                        app_path, NULL),
                                G_DBUS_CALL_FLAGS_NONE, -1,
-                               NULL,
+                               register_cancel,
                                (GAsyncReadyCallback) register_application_cb,
                                NULL);