Check whether dbus name is acquired normally. 82/135182/1
authorDeokhyun Kim <dukan.kim@samsung.com>
Wed, 21 Jun 2017 06:27:45 +0000 (15:27 +0900)
committerDeokhyun Kim <dukan.kim@samsung.com>
Wed, 21 Jun 2017 06:29:07 +0000 (15:29 +0900)
  bt-service is terminated before dbus method is called,
  because dbus own_name is too delayed when system is busy.

Change-Id: Ifee0c6dd6aebfa385d1cd2b81c67753cfe28b891
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
bt-service/bt-request-handler.c
bt-service/bt-service-main.c
bt-service/include/bt-request-handler.h [changed mode: 0755->0644]

index 2726bfb..61d038a 100644 (file)
@@ -73,6 +73,7 @@ static const gchar bt_service_introspection_xml[] =
 "</node>";
 
 GDBusNodeInfo *node_info = NULL;
+static gboolean name_acquired = FALSE;
 
 static char *current_sender_playing = NULL;
 
@@ -3306,39 +3307,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)
+{
+       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);
+       node_info = NULL;
+
+       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 9b06359..4605d1f 100644 (file)
@@ -132,6 +132,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);
old mode 100755 (executable)
new mode 100644 (file)
index 2d769f4..a984c14
@@ -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);