Proceed HID connection procedure when it's already connected. 84/159184/1
authorDeokhyun Kim <dukan.kim@samsung.com>
Tue, 7 Nov 2017 09:49:21 +0000 (18:49 +0900)
committerDeokhyun Kim <dukan.kim@samsung.com>
Tue, 7 Nov 2017 09:49:21 +0000 (18:49 +0900)
  - Application can use fd of HID channel even though it's already connected.

Change-Id: Ic44f9730df35984b1c07eff244510fe9749782b0
Signed-off-by: Deokhyun Kim <dukan.kim@samsung.com>
bt-api/bt-hid-device.c

index 21a7da0..93cd4fd 100644 (file)
@@ -164,11 +164,6 @@ static void __hid_connect_response_cb(GDBusProxy *proxy, GAsyncResult *res,
                g_dbus_error_strip_remote_error(error);
                BT_ERR("Error : %s \n", error->message);
 
-               if (g_strcmp0(error->message, "In Progress") == 0)
-                       result = BLUETOOTH_ERROR_DEVICE_BUSY;
-               else
-                       result = BLUETOOTH_ERROR_INTERNAL;
-
                info.ctrl_fd = -1;
                info.intr_fd = -1;
 
@@ -177,10 +172,27 @@ static void __hid_connect_response_cb(GDBusProxy *proxy, GAsyncResult *res,
                path = g_dbus_proxy_get_object_path(proxy);
                _bt_convert_device_path_to_address(path, info.address);
 
-               __hid_connected_cb(&info, result);
+               if (g_strcmp0(error->message, "Already Connected") == 0) {
+                       bluetooth_device_address_t dev_address = { {0} };
+                       int ctrl = -1, intr = -1;
 
-               g_free(info.address);
+                       _bt_convert_addr_string_to_type(dev_address.addr,
+                                                       info.address);
+                       _bt_hid_device_get_fd(info.address, &ctrl, &intr);
+                       if (ctrl != -1 && intr != -1)
+                               _bt_hid_new_connection(&dev_address, ctrl, intr);
+                       else
+                               BT_ERR("fd is invalid.(ctrl=%d, intr=%d)", ctrl, intr);
+               } else {
+                       if (g_strcmp0(error->message, "In Progress") == 0)
+                               result = BLUETOOTH_ERROR_IN_PROGRESS;
+                       else
+                               result = BLUETOOTH_ERROR_INTERNAL;
+
+                       __hid_connected_cb(&info, result);
+               }
 
+               g_free(info.address);
                g_error_free(error);
        } else {
                g_variant_unref(ret);