Handle the pending dbus calls before termination 46/219646/5 accepted/tizen/unified/20191211.121108 submit/tizen/20191211.023729
authorDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 9 Dec 2019 04:07:35 +0000 (13:07 +0900)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Tue, 10 Dec 2019 02:24:11 +0000 (11:24 +0900)
Change-Id: I2a10aeb9a344d8c935ece42ab9ada5f876db9808
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-service-adaptation/services/bt-request-handler.c
bt-service-adaptation/services/bt-service-main.c
bt-service-adaptation/services/include/bt-request-handler.h

index d1d1203..752f5de 100644 (file)
@@ -4269,6 +4269,19 @@ gboolean _is_name_acquired(void)
        return name_acquired;
 }
 
+void _bt_service_unref_connection(void)
+{
+       BT_INFO("+");
+
+       if (bt_service_conn) {
+               g_dbus_connection_flush_sync(bt_service_conn, NULL, NULL);
+               g_object_unref(bt_service_conn);
+               bt_service_conn = NULL;
+       }
+
+       BT_INFO("-");
+}
+
 int _bt_service_register(void)
 {
        GDBusConnection *conn;
@@ -4318,15 +4331,12 @@ void _bt_service_unregister(void)
                        owner_sig_id = 0;
                }
 
-               __bt_service_register_object(bt_service_conn, NULL, FALSE);
-               if (bt_service_conn) {
-                       g_object_unref(bt_service_conn);
-                       bt_service_conn = NULL;
-               }
                if (owner_id > 0) {
                        g_bus_unown_name(owner_id);
                        owner_id = 0;
                }
+
+               __bt_service_register_object(bt_service_conn, NULL, FALSE);
        }
 }
 
index b8cb267..c941296 100644 (file)
@@ -104,7 +104,7 @@ gboolean _bt_terminate_service(gpointer user_data)
        return FALSE;
 }
 
-gboolean _bt_reliable_terminate_service(gpointer user_data)
+static gboolean __bt_main_loop_quit_idle_cb(gpointer user_data)
 {
        _bt_deinit_proxys();
 
@@ -114,16 +114,27 @@ gboolean _bt_reliable_terminate_service(gpointer user_data)
 
        _bt_deinit_service_event_sender();
 
-       _bt_service_unregister();
-
        terminated = TRUE;
 
-       BT_INFO_C("### Terminating the bt-service daemon");
+       BT_INFO_C("Terminating the bt-service daemon");
 
-       if (main_loop != NULL)
+       if (main_loop != NULL) {
                g_main_loop_quit(main_loop);
-       else
+       } else {
+               BT_ERR("main_loop == NULL");
                exit(0);
+       }
+
+       return FALSE;
+}
+
+gboolean _bt_reliable_terminate_service(gpointer user_data)
+{
+       _bt_service_unregister();
+
+       /* Handle remaining pending requests finally by using g_idle_add()
+          again without well-known name. */
+       g_idle_add((GSourceFunc)__bt_main_loop_quit_idle_cb, NULL);
 
        return FALSE;
 }
@@ -330,6 +341,8 @@ int main(void)
 
        bluetooth_plugin_deinit();
 
+       _bt_service_unref_connection();
+
        if (main_loop != NULL)
                g_main_loop_unref(main_loop);
 
index df8928f..fa3a83b 100755 (executable)
@@ -50,6 +50,8 @@ void _bt_save_invocation_context(GDBusMethodInvocation *invocation, int result,
 
 void _bt_free_info_from_invocation_list(invocation_info_t *req_info);
 
+void _bt_service_unref_connection(void);
+
 int _bt_service_register(void);
 
 void _bt_service_unregister(void);