Proceed HID connection procedure when it's already connected.
[platform/core/connectivity/bluetooth-frwk.git] / 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);