From 38b1b7d951d3586f16761964aee6f2876e80b117 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Mon, 13 Nov 2017 23:41:11 +0100 Subject: Better error message on BLE connection timeout On BLE connection timeout a weird error-message was shown, because the controller was still in connecting state and no error string was set. Therefore, handle the timeout case with a special case label. Moreover, remove three unnecessary calls to disconnectFromDevice(), which is called in the destructor of the controller anyway (verified by looking at Qt source). Signed-off-by: Berthold Stoeger --- core/qt-ble.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'core') diff --git a/core/qt-ble.cpp b/core/qt-ble.cpp index 678296b29..2e92345dc 100644 --- a/core/qt-ble.cpp +++ b/core/qt-ble.cpp @@ -326,10 +326,14 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d case QLowEnergyController::ConnectedState: qDebug() << "connected to the controller for device" << devaddr; break; + case QLowEnergyController::ConnectingState: + qDebug() << "timeout while trying to connect to the controller " << devaddr; + report_error("Timeout while trying to connect to %s", devaddr); + delete controller; + return DC_STATUS_IO; default: qDebug() << "failed to connect to the controller " << devaddr << "with error" << controller->errorString(); report_error("Failed to connect to %s: '%s'", devaddr, controller->errorString().toUtf8().data()); - controller->disconnectFromDevice(); delete controller; return DC_STATUS_IO; } @@ -354,7 +358,6 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d if (ble->preferredService() == nullptr) { qDebug() << "failed to find suitable service on" << devaddr; report_error("Failed to find suitable service on '%s'", devaddr); - controller->disconnectFromDevice(); delete ble; return DC_STATUS_IO; } @@ -369,7 +372,6 @@ dc_status_t qt_ble_open(dc_custom_io_t *io, dc_context_t *context, const char *d if (ble->preferredService()->state() != QLowEnergyService::ServiceDiscovered) { qDebug() << "failed to find suitable service on" << devaddr; report_error("Failed to find suitable service on '%s'", devaddr); - controller->disconnectFromDevice(); delete ble; return DC_STATUS_IO; } -- cgit v1.2.3-70-g09d2