From: Biman Paul Date: Thu, 7 Sep 2017 11:18:39 +0000 (+0530) Subject: Use FindDevice to get device object path X-Git-Tag: accepted/tizen/4.0/unified/20170920.081520^0 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fconnectivity%2Fbluetooth-frwk.git;a=commitdiff_plain;h=30314c18fea269785f2c25d6f7dcd765008ad7a7 Use FindDevice to get device object path [Problem] Reduce dbus overhead to get device object path. [Cause & Measure] GetManagedObjects returns exhaustive list of iterfaces and their properties recursively which is redundant. Measure: Use FindDevice method to get device object path. [Checking Method] NA Change-Id: I5125f5baa8ea283ba374541eef57a858301a1476 Signed-off-by: injun.yang Signed-off-by: DoHyun Pyun --- diff --git a/bt-service/bt-service-common.c b/bt-service/bt-service-common.c index 8dc9985..b171012 100644 --- a/bt-service/bt-service-common.c +++ b/bt-service/bt-service-common.c @@ -660,57 +660,30 @@ int _bt_set_non_blocking_tty(int sk) return BLUETOOTH_ERROR_NONE; } -static char *__bt_extract_device_path(GVariantIter *iter, char *address) -{ - char *object_path = NULL; - char device_address[BT_ADDRESS_STRING_SIZE] = { 0 }; - - /* Parse the signature: oa{sa{sv}}} */ - while (g_variant_iter_loop(iter, "{&oa{sa{sv}}}", &object_path, - NULL)) { - if (!object_path) { - BT_ERR("Unable to get object path"); - return NULL; - } - _bt_convert_device_path_to_address(object_path, device_address); - if (g_strcmp0(address, device_address) == 0) - return g_strdup(object_path); - - } - - BT_ERR("Unable to get object path"); - return NULL; -} - char *_bt_get_device_object_path(char *address) { char *object_path = NULL; - GDBusConnection *conn; - GDBusProxy *manager_proxy; GVariant *result = NULL; - GVariantIter *iter = NULL; - - conn = _bt_gdbus_get_system_gconn(); - retv_if(conn == NULL, NULL); + GDBusProxy *proxy; + GError *error = NULL; - manager_proxy = _bt_get_manager_proxy(); - retv_if(manager_proxy == NULL, NULL); + proxy = _bt_get_adapter_proxy(); + retv_if(proxy == NULL, NULL); - result = g_dbus_proxy_call_sync(manager_proxy, "GetManagedObjects", - NULL, + result = g_dbus_proxy_call_sync(proxy, "FindDevice", + g_variant_new("(s)", address), G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL); - if (!result) { - BT_ERR("Can't get managed objects"); + -1, NULL, &error); + if (result == NULL) { + if (error) { + BT_ERR("FindDevice Fail: %s", error->message); + g_clear_error(&error); + } return NULL; } - /* signature of GetManagedObjects: a{oa{sa{sv}}} */ - g_variant_get(result, "(a{oa{sa{sv}}})", &iter); - object_path = __bt_extract_device_path(iter, address); - g_variant_iter_free(iter); + g_variant_get(result, "(o)", &object_path); + g_variant_unref(result); return object_path; } diff --git a/bt-service/bt-service-device.c b/bt-service/bt-service-device.c index d2f939c..32297fc 100644 --- a/bt-service/bt-service-device.c +++ b/bt-service/bt-service-device.c @@ -674,18 +674,7 @@ static int __bt_remove_and_bond(void) adapter_proxy = _bt_get_adapter_proxy(); retv_if(adapter_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); - result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice", - g_variant_new("(s)", bonding_info->addr), - G_DBUS_CALL_FLAGS_NONE, - -1, - NULL, - NULL); - if (result == NULL) - return BLUETOOTH_ERROR_INTERNAL; - - g_variant_get(result , "(o)", &device_path); - g_variant_unref(result); - + device_path = _bt_get_device_object_path(bonding_info->addr); retv_if(device_path == NULL, BLUETOOTH_ERROR_INTERNAL); result = g_dbus_proxy_call_sync(adapter_proxy, "UnpairDevice", @@ -695,12 +684,15 @@ static int __bt_remove_and_bond(void) NULL, &err); g_free(device_path); - if (err != NULL) { - BT_ERR("UnpairDevice Fail: %s", err->message); - g_error_free(err); + if (result == NULL) { + if (err != NULL) { + BT_ERR("UnpairDevice Fail: %s", err->message); + g_error_free(err); + } return BLUETOOTH_ERROR_INTERNAL; } + g_variant_unref(result); return __bt_retry_bond(); } diff --git a/bt-service/bt-service-network.c b/bt-service/bt-service-network.c index 439218d..00140da 100644 --- a/bt-service/bt-service-network.c +++ b/bt-service/bt-service-network.c @@ -354,15 +354,13 @@ int _bt_network_deactivate(void) int _bt_network_connect(int request_id, int role, bluetooth_device_address_t *device_address) { - const gchar *device_path = NULL; + gchar *device_path = NULL; char address[BT_ADDRESS_STRING_SIZE] = { 0 }; char remote_role[BLUETOOTH_UUID_STRING_MAX] = { 0 }; bt_function_data_t *func_data; GDBusProxy *adapter_proxy; GDBusProxy *profile_proxy; GDBusConnection *conn; - GVariant *result = NULL; - GError*err = NULL; BT_CHECK_PARAMETER(device_address, return); @@ -391,23 +389,9 @@ int _bt_network_connect(int request_id, int role, _bt_convert_addr_type_to_string(address, device_address->addr); - result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice", - g_variant_new("(s)", address), - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &err); - if (result == NULL) { - BT_ERR("Error occurred in call to FindDevice"); - if (err) { - BT_ERR("Error: %s", err->message); - g_clear_error(&err); - } - return BLUETOOTH_ERROR_INTERNAL; - } - - device_path = g_variant_get_string(result, NULL); + device_path = _bt_get_device_object_path(address); if (device_path == NULL) { BT_ERR("No paired device"); - g_variant_unref(result); return BLUETOOTH_ERROR_NOT_PAIRED; } @@ -415,7 +399,7 @@ int _bt_network_connect(int request_id, int role, NULL, BT_BLUEZ_NAME, device_path, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL); - g_variant_unref(result); + g_free(device_path); retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); func_data = g_malloc0(sizeof(bt_function_data_t)); func_data->address = g_strdup(address); @@ -435,14 +419,12 @@ int _bt_network_connect(int request_id, int role, int _bt_network_disconnect(int request_id, bluetooth_device_address_t *device_address) { - const gchar *device_path = NULL; + gchar *device_path = NULL; char address[BT_ADDRESS_STRING_SIZE] = { 0 }; bt_function_data_t *func_data; GDBusProxy *adapter_proxy; GDBusProxy *profile_proxy; GDBusConnection *conn; - GVariant *result = NULL; - GError*err = NULL; BT_CHECK_PARAMETER(device_address, return); @@ -454,23 +436,9 @@ int _bt_network_disconnect(int request_id, _bt_convert_addr_type_to_string(address, device_address->addr); - result = g_dbus_proxy_call_sync(adapter_proxy, "FindDevice", - g_variant_new("(s)", address), - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &err); - if (result == NULL) { - BT_ERR("Error occurred in call to FindDevice"); - if (err) { - BT_ERR("Error: %s", err->message); - g_clear_error(&err); - } - return BLUETOOTH_ERROR_INTERNAL; - } - - device_path = g_variant_get_string(result, NULL); + device_path = _bt_get_device_object_path(address); if (device_path == NULL) { BT_ERR("No paired device"); - g_variant_unref(result); return BLUETOOTH_ERROR_NOT_PAIRED; } @@ -478,7 +446,7 @@ int _bt_network_disconnect(int request_id, NULL, BT_BLUEZ_NAME, device_path, BT_NETWORK_CLIENT_INTERFACE, NULL, NULL); - g_variant_unref(result); + g_free(device_path); retv_if(profile_proxy == NULL, BLUETOOTH_ERROR_INTERNAL); func_data = g_malloc0(sizeof(bt_function_data_t)); func_data->address = g_strdup(address);