This patch sets a timer for the connecting step.

If the connection doesn't succeed after five seconds or
no error occurs then stop the opening step and exit with failure.

On Sat, Jun 27, 2015 at 4:09 PM, Claudiu Olteanu <
[email protected]> wrote:

> In order to make our custom serial implementation to work with the
> new dc_serial_t custom design you have to apply the attached patch.
>
> In the end I will create some new patches in order to have a clean branch.
>
> Best wishes,
> Claudiu
>
>
From faccea72faaa47de119bb4cef7bf0b98f2eed853 Mon Sep 17 00:00:00 2001
From: Claudiu Olteanu <[email protected]>
Date: Sun, 28 Jun 2015 15:55:15 +0300
Subject: [PATCH 11/11] Add a timer for Bluetooth connecting step

Create a timer for the QEventLoop used in the qt serial bluetooth
openning method. If the connection doesn't succeed after five seconds or
no error occurs then stop the opening step and exit with failure.

Signed-off-by: Claudiu Olteanu <[email protected]>
---
 qtserialbluetooth.cpp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/qtserialbluetooth.cpp b/qtserialbluetooth.cpp
index 9c3bf5d..329907b 100644
--- a/qtserialbluetooth.cpp
+++ b/qtserialbluetooth.cpp
@@ -3,6 +3,7 @@
 #include <QtBluetooth/QBluetoothAddress>
 #include <QtBluetooth/QBluetoothSocket>
 #include <QEventLoop>
+#include <QTimer>
 
 #include <libdivecomputer/custom_serial.h>
 
@@ -41,11 +42,18 @@ static int qt_serial_open(serial_t **out, dc_context_t *context, const char* dev
 	QEventLoop loop;
 	loop.connect(serial_port->socket, SIGNAL(connected()), SLOT(quit()));
 	loop.connect(serial_port->socket, SIGNAL(error(QBluetoothSocket::SocketError)), SLOT(quit()));
+
+	// Create a timer. If the connection doesn't succeed after five seconds or no error occurs then stop the opening step
+	QTimer timer;
+	timer.setSingleShot(true);
+	loop.connect(&timer, SIGNAL(timeout()), SLOT(quit()));
+
 	// Try to connect to the Serial Port Profile service
 	serial_port->socket->connectToService(QBluetoothAddress(devaddr), QBluetoothUuid::SerialPort);
+	timer.start(5000);
 	loop.exec();
 
-	if (serial_port->socket->socketDescriptor() == -1) {
+	if (serial_port->socket->socketDescriptor() == -1 || serial_port->socket->state() != QBluetoothSocket::ConnectedState) {
 		free (serial_port);
 
 		// Get the latest error and try to match it with one from libdivecomputer
-- 
2.1.4

_______________________________________________
subsurface mailing list
[email protected]
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to