Check whether dbus name is acquired normally. 06/183506/1
authorDeokhyun Kim <dukan.kim@samsung.com>
Fri, 6 Jul 2018 05:52:43 +0000 (14:52 +0900)
committerinjun.yang <injun.yang@samsung.com>
Fri, 6 Jul 2018 05:52:43 +0000 (14:52 +0900)
[Problem] bt-service is terminated before dbus method is called.
[Cause & Measure] dbus own_name is too delayed when system is busy.
  Call g_bus_own_name with callback functions. And then terminate bt-service
  after checking bus_name acquired.
[Checking Method] Repeat to on/off BT

Change-Id: I63b2d8d0714217f21d72d77b7d6f2afb8a75ea1d

bt-service/bt-request-handler.c
bt-service/bt-service-main.c
bt-service/include/bt-request-handler.h

index bac10a3..ca63020 100644 (file)
@@ -71,6 +71,7 @@ static const gchar bt_service_introspection_xml[] =
 "</node>";
 
 GDBusNodeInfo *node_info = NULL;
+static gboolean name_acquired = FALSE;
 
 static char *current_sender_playing = NULL;
 
@@ -3012,39 +3013,64 @@ int __bt_service_register_object(GDBusConnection *conn,
        return 0;
 }
 
+static void __bt_service_bus_acquired_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       GDBusNodeInfo *node_info = NULL;
+
+       BT_INFO("bus acquired");
+
+       ret_if(connection == NULL);
+
+       node_info = __bt_service_create_method_node_info(
+                       bt_service_introspection_xml);
+       ret_if(node_info == NULL);
+
+       __bt_service_register_object(connection, node_info, TRUE);
+       g_dbus_node_info_unref(node_info);
+
+       bt_service_conn = connection;
+}
+
+static void __bt_service_name_acquired_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       BT_INFO("name acquired");
+       name_acquired = TRUE;
+}
+
+static void __bt_service_name_lost_handler(GDBusConnection *connection,
+               const gchar *name, gpointer user_data)
+{
+       BT_INFO("name lost");
+       name_acquired = FALSE;
+}
+
+gboolean _is_name_acquired(void)
+{
+       return name_acquired;
+}
+
 int _bt_service_register(void)
 {
        GDBusConnection *conn;
        GError *err = NULL;
-       int result;
 
        conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err);
        retv_if(conn == NULL, BLUETOOTH_ERROR_INTERNAL);
+       bt_service_conn = conn;
 
        owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
                                BT_SERVICE_NAME,
                                G_BUS_NAME_OWNER_FLAGS_NONE,
-                               NULL, NULL, NULL,
+                               __bt_service_bus_acquired_handler,
+                               __bt_service_name_acquired_handler,
+                               __bt_service_name_lost_handler,
                                NULL, NULL);
        BT_DBG("owner_id is [%d]", owner_id);
        if (owner_id == 0)
                goto fail;
 
-       node_info = __bt_service_create_method_node_info(
-                       bt_service_introspection_xml);
-
-       if (node_info == NULL)
-               goto fail;
-
-       result = __bt_service_register_object(conn, node_info, TRUE);
-       g_dbus_node_info_unref(node_info);
-       node_info = NULL;
-
-       if (result != BLUETOOTH_ERROR_NONE)
-               goto fail;
-
-       bt_service_conn = conn;
-
        return BLUETOOTH_ERROR_NONE;
 
 fail:
index 46f7940..e77ffbd 100644 (file)
@@ -133,6 +133,11 @@ static gboolean __bt_check_bt_service(void *data)
                int ps_mode_deactivation = 0;
 #endif
 
+               if (_is_name_acquired() == FALSE) {
+                       BT_ERR("dbus name is NOT acquired yet");
+                       return TRUE;
+               }
+
                status = _bt_adapter_get_status();
                le_status = _bt_adapter_get_le_status();
                BT_DBG("State: %d, LE State: %d", status, le_status);
index 2d769f4..a984c14 100755 (executable)
@@ -32,6 +32,8 @@ extern "C" {
 #define BT_SERVICE_NAME "org.projectx.bt"
 #define BT_SERVICE_PATH "/org/projectx/bt_service"
 
+gboolean _is_name_acquired(void);
+
 int _bt_service_register(void);
 
 void _bt_service_unregister(void);