From bd54a9eab645f52272c53a49e269cbf310a5ec8d Mon Sep 17 00:00:00 2001 From: Deokhyun Kim Date: Fri, 6 Jul 2018 14:52:43 +0900 Subject: [PATCH] Check whether dbus name is acquired normally. [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 | 60 +++++++++++++++++++++++---------- bt-service/bt-service-main.c | 5 +++ bt-service/include/bt-request-handler.h | 2 ++ 3 files changed, 50 insertions(+), 17 deletions(-) diff --git a/bt-service/bt-request-handler.c b/bt-service/bt-request-handler.c index bac10a3..ca63020 100644 --- a/bt-service/bt-request-handler.c +++ b/bt-service/bt-request-handler.c @@ -71,6 +71,7 @@ static const gchar bt_service_introspection_xml[] = ""; 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: diff --git a/bt-service/bt-service-main.c b/bt-service/bt-service-main.c index 46f7940..e77ffbd 100644 --- a/bt-service/bt-service-main.c +++ b/bt-service/bt-service-main.c @@ -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); diff --git a/bt-service/include/bt-request-handler.h b/bt-service/include/bt-request-handler.h index 2d769f4..a984c14 100755 --- a/bt-service/include/bt-request-handler.h +++ b/bt-service/include/bt-request-handler.h @@ -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); -- 2.7.4