From c51f794701663be620a81efb9455cbf1f0f23519 Mon Sep 17 00:00:00 2001 From: Deokhyun Kim Date: Wed, 21 Jun 2017 15:27:45 +0900 Subject: [PATCH] Check whether dbus name is acquired normally. 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 --- 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(-) mode change 100755 => 100644 bt-service/include/bt-request-handler.h diff --git a/bt-service/bt-request-handler.c b/bt-service/bt-request-handler.c index 2726bfb..61d038a 100644 --- a/bt-service/bt-request-handler.c +++ b/bt-service/bt-request-handler.c @@ -73,6 +73,7 @@ static const gchar bt_service_introspection_xml[] = ""; 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: diff --git a/bt-service/bt-service-main.c b/bt-service/bt-service-main.c index 9b06359..4605d1f 100644 --- a/bt-service/bt-service-main.c +++ b/bt-service/bt-service-main.c @@ -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); diff --git a/bt-service/include/bt-request-handler.h b/bt-service/include/bt-request-handler.h old mode 100755 new mode 100644 index 2d769f4..a984c14 --- 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