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 e42bcde1b96b2f0cd01812a946b8dfc587ee1709 Mon Sep 17 00:00:00 2001
From: Claudiu Olteanu <olteanu.clau...@ymail.com>
Date: Sat, 27 Jun 2015 15:34:09 +0300
Subject: [PATCH 10/10] Update the QtBluetooth serial implementation to work
 with the the dc_serial_t structure

This is a temporary patch.

The patch updates the message that is displayed when the local Bluetooth
device cannot be accessed, fixes the return check from qt_serial_open
method and uses the new dc_serial_t structure.

Signed-off-by: Claudiu Olteanu <olteanu.clau...@ymail.com>
---
 qt-ui/btdeviceselectiondialog.cpp |  3 ++-
 qtserialbluetooth.cpp             | 36 +++++++++++++++++-------------------
 2 files changed, 19 insertions(+), 20 deletions(-)

diff --git a/qt-ui/btdeviceselectiondialog.cpp b/qt-ui/btdeviceselectiondialog.cpp
index 49f8f58..e0daa45 100644
--- a/qt-ui/btdeviceselectiondialog.cpp
+++ b/qt-ui/btdeviceselectiondialog.cpp
@@ -14,7 +14,8 @@ BtDeviceSelectionDialog::BtDeviceSelectionDialog(QWidget *parent) :
 	/* Check if Bluetooth is available on this device */
 	if (!localDevice->isValid()) {
 		QMessageBox::warning(this, tr("Warning"),
-				     "Your local Bluetooth device cannot be accessed. Please check if you have installed qtconnectivity library.");
+				     "This should never happen, please contact the Subsurface developers "
+				     "and tell them that the Bluetooth download mode doesn't work.");
 		return;
 	}
 
diff --git a/qtserialbluetooth.cpp b/qtserialbluetooth.cpp
index 5a2b3be..9c3bf5d 100644
--- a/qtserialbluetooth.cpp
+++ b/qtserialbluetooth.cpp
@@ -23,33 +23,33 @@ static int qt_serial_open(serial_t **out, dc_context_t *context, const char* dev
 		return DC_STATUS_INVALIDARGS;
 
 	// Allocate memory.
-	serial_t *device = (serial_t *) malloc (sizeof (serial_t));
-	if (device == NULL) {
+	serial_t *serial_port = (serial_t *) malloc (sizeof (serial_t));
+	if (serial_port == NULL) {
 		return DC_STATUS_NOMEMORY;
 	}
 
 	// Library context.
-	device->context = context;
+	serial_port->context = context;
 
 	// Default to blocking reads.
-	device->timeout = -1;
+	serial_port->timeout = -1;
 
 	// Create a RFCOMM socket
-	device->socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
+	serial_port->socket = new QBluetoothSocket(QBluetoothServiceInfo::RfcommProtocol);
 
 	// Wait until the connection succeeds or until an error occurs
 	QEventLoop loop;
-	loop.connect(device->socket, SIGNAL(connected()), SLOT(quit()));
-	loop.connect(device->socket, SIGNAL(error(QBluetoothSocket::SocketError)), SLOT(quit()));
+	loop.connect(serial_port->socket, SIGNAL(connected()), SLOT(quit()));
+	loop.connect(serial_port->socket, SIGNAL(error(QBluetoothSocket::SocketError)), SLOT(quit()));
 	// Try to connect to the Serial Port Profile service
-	device->socket->connectToService(QBluetoothAddress(devaddr), QBluetoothUuid::SerialPort);
+	serial_port->socket->connectToService(QBluetoothAddress(devaddr), QBluetoothUuid::SerialPort);
 	loop.exec();
 
-	if (device->socket->socketDescriptor() == -1) {
-		free (device);
+	if (serial_port->socket->socketDescriptor() == -1) {
+		free (serial_port);
 
 		// Get the latest error and try to match it with one from libdivecomputer
-		QBluetoothSocket::SocketError err = device->socket->error();
+		QBluetoothSocket::SocketError err = serial_port->socket->error();
 		switch(err) {
 		case QBluetoothSocket::HostNotFoundError:
 		case QBluetoothSocket::ServiceNotFoundError:
@@ -65,7 +65,7 @@ static int qt_serial_open(serial_t **out, dc_context_t *context, const char* dev
 		}
 	}
 
-	*out = device;
+	*out = serial_port;
 
 	return DC_STATUS_SUCCESS;
 }
@@ -193,18 +193,16 @@ dc_status_t dc_serial_qt_open(dc_serial_t **out, dc_context_t *context, const ch
 		return DC_STATUS_NOMEMORY;
 	}
 
-	serial_t *port;
+	// Initialize data and function pointers
+	dc_serial_init(serial_device, NULL, &qt_serial_ops);
 
 	// Open the serial device.
-	int rc = qt_serial_open (&port, context, devaddr);
-	if (rc == -1) {
+	dc_status_t rc = (dc_status_t)qt_serial_open (&serial_device->port, context, devaddr);
+	if (rc != DC_STATUS_SUCCESS) {
 		free (serial_device);
-		return DC_STATUS_IO;
+		return rc;
 	}
 
-	// Initialize data and function pointers
-	dc_serial_init(serial_device, (void*)port, &qt_serial_ops);
-
 	// Set the type of the device
 	serial_device->type = DC_TRANSPORT_BLUETOOTH;
 
-- 
2.1.4

_______________________________________________
subsurface mailing list
subsurface@subsurface-divelog.org
http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface

Reply via email to