diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2020-01-26 12:42:57 -0800 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-01-27 09:51:31 -0800 |
commit | 9543f53150dec964d86be12af41491ded923c458 (patch) | |
tree | 11397c1400bd3f4384691152595fd6c293642341 /core/qtserialbluetooth.cpp | |
parent | 5b81997459810f777148e543a8b20b9bb8c486df (diff) | |
download | subsurface-9543f53150dec964d86be12af41491ded923c458.tar.gz |
Update to new libdivecomputer version
Jef has changed the libdivecomputer iostream layer and extended it in
two different ways:
- iostram's now have a 'poll()' method, which does what the name
implies: waits for data to be available with a timeout.
- iostreams now have a 'ioctl()' method, which can be used to implement
miscellaneous operations. Right now the two ones that you can do are
"set latency" (this replaces the old 'set_latency()' method) and "get
BLE name" (this replaces our 'get_name()' method that was never part
of the upstream libdivecomputer interfaces)
Neither of these is all that complicated, and the transition is fairly
obvious.
HOWEVER.
I have absolutely no idea how to do 'poll()' on Windows sockets, and I
have no intention of figuring it out. We use a direct socket interface
to implement the (non-BLE) RFCOMM bluetooth serial protocol, and I'm not
sure why Windows is so special here. I suspect - but cannot test - that
we should just switch the Windows RFCOMM implementation over to the use
the same QtBluetooth code that we use on other platforms.
I assume that the Windows Bluetooth support was originally not
sufficiently good for that, but these days we depend on Qt doing BLE for
us even on Windows, so presumably FRCOMM works too.
That would be a nice cleanup, and would make 'poll()' work on RFCOMM
under Windows too. However, since I can't test it, I've not done that,
but instead just made the Windows RFCOMM 'poll()' method always return
success. That may or may not get the thing limping along.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'core/qtserialbluetooth.cpp')
-rw-r--r-- | core/qtserialbluetooth.cpp | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/core/qtserialbluetooth.cpp b/core/qtserialbluetooth.cpp index ae4069f33..abb69284d 100644 --- a/core/qtserialbluetooth.cpp +++ b/core/qtserialbluetooth.cpp @@ -12,6 +12,7 @@ #include <libdivecomputer/version.h> #include <libdivecomputer/context.h> #include <libdivecomputer/custom.h> +#include <libdivecomputer/serial.h> #if defined(Q_OS_WIN) #include <winsock2.h> @@ -302,6 +303,33 @@ static dc_status_t qt_serial_write(void *io, const void* data, size_t size, size return DC_STATUS_SUCCESS; } +static dc_status_t qt_serial_poll(void *io, int timeout) +{ + qt_serial_t *device = (qt_serial_t*) io; + + if (!device) + return DC_STATUS_INVALIDARGS; + +#if defined(Q_OS_WIN) + // FIXME FIXME FIXME!! But how ? + // I have no idea about windows socket programming - Linus + // We'll just pretend it's always readable, and hope for the best + // Why is the windows side not using QBluetoothSocket? + return DC_STATUS_SUCCESS; +#else + if (!device->socket) + return DC_STATUS_INVALIDARGS; + if (device->socket->waitForReadyRead(timeout)) + return DC_STATUS_SUCCESS; + return DC_STATUS_TIMEOUT; +#endif +} + +static dc_status_t qt_serial_ioctl(void *io, unsigned int request, void *data, size_t size) +{ + return DC_STATUS_UNSUPPORTED; +} + static dc_status_t qt_serial_purge(void *io, dc_direction_t) { qt_serial_t *device = (qt_serial_t*) io; @@ -385,20 +413,20 @@ ble_packet_open(dc_iostream_t **iostream, dc_context_t *context, const char* dev static const dc_custom_cbs_t callbacks = { qt_ble_set_timeout, /* set_timeout */ - NULL, /* set_latency */ NULL, /* set_break */ NULL, /* set_dtr */ NULL, /* set_rts */ NULL, /* get_lines */ NULL, /* get_received */ NULL, /* configure */ + qt_ble_poll, /* poll */ qt_ble_read, /* read */ qt_ble_write, /* write */ + qt_ble_ioctl, /* ioctl */ NULL, /* flush */ NULL, /* purge */ qt_custom_sleep, /* sleep */ qt_ble_close, /* close */ - qt_ble_get_name, /* get_name */ }; rc = qt_ble_open(&io, context, devaddr, (dc_user_device_t *) userdata); @@ -419,15 +447,16 @@ rfcomm_stream_open(dc_iostream_t **iostream, dc_context_t *context, const char* static const dc_custom_cbs_t callbacks = { qt_serial_set_timeout, /* set_timeout */ - NULL, /* set_latency */ NULL, /* set_break */ NULL, /* set_dtr */ NULL, /* set_rts */ NULL, /* get_lines */ qt_serial_get_available, /* get_received */ NULL, /* configure */ + qt_serial_poll, /* poll */ qt_serial_read, /* read */ qt_serial_write, /* write */ + qt_serial_ioctl, /* ioctl */ NULL, /* flush */ qt_serial_purge, /* purge */ qt_custom_sleep, /* sleep */ |