Handle the pending dbus calls before termination
[platform/core/connectivity/bluetooth-frwk.git] / bt-service-adaptation / services / bt-service-main.c
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);