From: Andrzej Popowski Date: Fri, 7 Aug 2015 08:54:33 +0000 (+0200) Subject: [Bluetooth] - BLE device connect function fixed X-Git-Tag: accepted/tizen/mobile/20151026.233336^2^2~208^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=95bcc38032ecc58e4b9240f974330881c6564123;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Bluetooth] - BLE device connect function fixed Change-Id: Ia0e171b4a8f914bc26a10b6f6b5669a5d73cac49 Signed-off-by: Andrzej Popowski --- diff --git a/src/bluetooth/bluetooth_le_device.cc b/src/bluetooth/bluetooth_le_device.cc index bcc22c4..641ba0e 100755 --- a/src/bluetooth/bluetooth_le_device.cc +++ b/src/bluetooth/bluetooth_le_device.cc @@ -294,15 +294,27 @@ void BluetoothLEDevice::Connect(const picojson::value& data, const auto& address = common::FromJson(args, "address"); - int ret = bt_gatt_connect(address.c_str(), true); + bool connected = false; + int ret = bt_device_is_profile_connected(address.c_str(), BT_PROFILE_GATT, &connected); if (BT_ERROR_NONE != ret) { - instance_.AsyncResponse( - callback_handle, - PlatformResult(util::GetBluetoothError(ret, "Failed to connect."))); + instance_.AsyncResponse(callback_handle, + PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to disconnect.")); return; } - connecting_[address] = callback_handle; + if (connected) { + instance_.AsyncResponse(callback_handle, + PlatformResult(ErrorCode::NO_ERROR)); + } else { // not connected yet + ret = bt_gatt_connect(address.c_str(), true); + if (BT_ERROR_NONE != ret) { + instance_.AsyncResponse( + callback_handle, + PlatformResult(ErrorCode::UNKNOWN_ERR, "Failed to connect.")); + return; + } + connecting_[address] = callback_handle; + } ReportSuccess(out); }