Use FindDevice to get device object path 49/150549/2 accepted/tizen/4.0/unified/20170920.081520 submit/tizen_4.0/20170918.085143
authorBiman Paul <biman.paul@samsung.com>
Thu, 7 Sep 2017 11:18:39 +0000 (16:48 +0530)
committerDoHyun Pyun <dh79.pyun@samsung.com>
Mon, 18 Sep 2017 02:48:29 +0000 (11:48 +0900)
[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 <injun.yang@samsung.com>
Signed-off-by: DoHyun Pyun <dh79.pyun@samsung.com>
bt-service/bt-service-common.c
bt-service/bt-service-device.c
bt-service/bt-service-network.c

index 8dc9985..b171012 100644 (file)
@@ -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;
 }
index d2f939c..32297fc 100644 (file)
@@ -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();
 }
 
index 439218d..00140da 100644 (file)
@@ -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);