Rename 'custom_serial' as 'custom_io' across the board
The custom IO handlers will be extended to not just do serial line emulation (generally over Bluetooth rfcomm), but do BLE too. BLE does not look like a serial protocol at all, it's packet-based, and we may have to add specific routines to indicate which GATT endpoints to use etc. But like the traditional custom serial code, we want to do the actual IO not from within libdivecomputer, but from the user of the library (because the BLE support will require things like the Qt Connectivity layer - and we do not want libdivecomputer to have to link against something like Qt). So this renames 'custom_serial' to 'custom_io', and instead names the individual member function pointers 'serial_*' to make it clear that those members are for serial communication. It also adds new placeholders for packet_open/close/read/write. Note that while these may look similar to the serial counter-parts, they are not the same or even necessarily mutually exclusive. It is possible the the caller fills in one or the other (or both), and they would be used independently. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
e9754bac64
commit
60efc308d2
@ -3,7 +3,7 @@ libdivecomputer_HEADERS = \
|
||||
version.h \
|
||||
common.h \
|
||||
context.h \
|
||||
custom_serial.h \
|
||||
custom_io.h \
|
||||
buffer.h \
|
||||
descriptor.h \
|
||||
iterator.h \
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
#define DC_CONTEXT_H
|
||||
|
||||
#include "common.h"
|
||||
#include "custom_serial.h"
|
||||
#include "custom_io.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -49,7 +49,7 @@ dc_status_t
|
||||
dc_context_free (dc_context_t *context);
|
||||
|
||||
dc_status_t
|
||||
dc_context_set_custom_serial (dc_context_t *context, dc_custom_serial_t *custom_serial);
|
||||
dc_context_set_custom_io (dc_context_t *context, dc_custom_io_t *custom_io);
|
||||
|
||||
dc_status_t
|
||||
dc_context_set_loglevel (dc_context_t *context, dc_loglevel_t loglevel);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#ifndef CUSTOM_SERIAL_H
|
||||
#define CUSTOM_SERIAL_H
|
||||
#ifndef CUSTOM_IO_H
|
||||
#define CUSTOM_IO_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@ -62,29 +62,40 @@ typedef enum dc_line_t {
|
||||
|
||||
#endif /* __SERIAL_TYPES__ */
|
||||
|
||||
typedef struct dc_custom_serial_t
|
||||
struct dc_context_t;
|
||||
|
||||
typedef struct dc_custom_io_t
|
||||
{
|
||||
void *userdata;
|
||||
dc_status_t (*open) (void **userdata, const char *name);
|
||||
dc_status_t (*close) (void **userdata);
|
||||
dc_status_t (*read) (void **userdata, void* data, size_t size, size_t *actual);
|
||||
dc_status_t (*write) (void **userdata, const void* data, size_t size, size_t *actual);
|
||||
dc_status_t (*purge) (void **userdata, dc_direction_t);
|
||||
dc_status_t (*get_available) (void **userdata, size_t *value);
|
||||
dc_status_t (*set_timeout) (void **userdata, long timeout);
|
||||
dc_status_t (*configure) (void **userdata, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol);
|
||||
dc_status_t (*set_dtr) (void **userdata, int level);
|
||||
dc_status_t (*set_rts) (void **userdata, int level);
|
||||
dc_status_t (*set_halfduplex) (void **userdata, unsigned int value);
|
||||
dc_status_t (*set_break) (void **userdata, unsigned int level);
|
||||
|
||||
// Custom serial (generally BT rfcomm)
|
||||
dc_status_t (*serial_open) (void **userdata, const char *name);
|
||||
dc_status_t (*serial_close) (void **userdata);
|
||||
dc_status_t (*serial_read) (void **userdata, void* data, size_t size, size_t *actual);
|
||||
dc_status_t (*serial_write) (void **userdata, const void* data, size_t size, size_t *actual);
|
||||
dc_status_t (*serial_purge) (void **userdata, dc_direction_t);
|
||||
dc_status_t (*serial_get_available) (void **userdata, size_t *value);
|
||||
dc_status_t (*serial_set_timeout) (void **userdata, long timeout);
|
||||
dc_status_t (*serial_configure) (void **userdata, unsigned int baudrate, unsigned int databits, dc_parity_t parity, dc_stopbits_t stopbits, dc_flowcontrol_t flowcontrol);
|
||||
dc_status_t (*serial_set_dtr) (void **userdata, int level);
|
||||
dc_status_t (*serial_set_rts) (void **userdata, int level);
|
||||
dc_status_t (*serial_set_halfduplex) (void **userdata, unsigned int value);
|
||||
dc_status_t (*serial_set_break) (void **userdata, unsigned int level);
|
||||
//dc_serial_set_latency (dc_serial_t *device, unsigned int milliseconds) - Unused
|
||||
//dc_serial_get_lines (dc_serial_t *device, unsigned int *value) - Unused
|
||||
//dc_serial_flush (dc_serial_t *device) - No device interaction
|
||||
//dc_serial_sleep (dc_serial_t *device, unsigned int timeout) - No device interaction
|
||||
} dc_custom_serial_t;
|
||||
|
||||
// Custom packet transfer (generally BLE GATT)
|
||||
int packet_size;
|
||||
dc_status_t (*packet_open) (struct dc_custom_io_t *, struct dc_context_t *, const char *);
|
||||
dc_status_t (*packet_close) (struct dc_custom_io_t *);
|
||||
dc_status_t (*packet_read) (struct dc_custom_io_t *, void* data, size_t size, size_t *actual);
|
||||
dc_status_t (*packet_write) (struct dc_custom_io_t *, const void* data, size_t size, size_t *actual);
|
||||
} dc_custom_io_t;
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif /* __cplusplus */
|
||||
#endif /* CUSTOM_SERIAL_H */
|
||||
#endif /* CUSTOM_IO_H */
|
||||
@ -28,7 +28,7 @@ extern "C" {
|
||||
|
||||
/* use these defines to detect Subsurface specific features */
|
||||
#define SSRF_LIBDC_VERSION 1
|
||||
#define SSRF_CUSTOM_SERIAL 1
|
||||
#define SSRF_CUSTOM_IO 1
|
||||
|
||||
#define DC_VERSION "@DC_VERSION@"
|
||||
#define DC_VERSION_MAJOR @DC_VERSION_MAJOR@
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
#endif
|
||||
|
||||
#include <libdivecomputer/context.h>
|
||||
#include <libdivecomputer/custom_serial.h>
|
||||
#include <libdivecomputer/custom_io.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -72,16 +72,16 @@ dc_context_syserror (dc_context_t *context, dc_loglevel_t loglevel, const char *
|
||||
dc_status_t
|
||||
dc_context_hexdump (dc_context_t *context, dc_loglevel_t loglevel, const char *file, unsigned int line, const char *function, const char *prefix, const unsigned char data[], unsigned int size);
|
||||
|
||||
dc_custom_serial_t*
|
||||
_dc_context_custom_serial (dc_context_t *context);
|
||||
dc_custom_io_t*
|
||||
_dc_context_custom_io (dc_context_t *context);
|
||||
|
||||
#define RETURN_IF_CUSTOM_SERIAL(context, block, function, ...) \
|
||||
do { \
|
||||
dc_custom_serial_t *c = _dc_context_custom_serial(context); \
|
||||
dc_custom_io_t *c = _dc_context_custom_io(context); \
|
||||
dc_status_t _rc; \
|
||||
if (c) { \
|
||||
if (c->function) \
|
||||
_rc = c->function(&c->userdata, ##__VA_ARGS__); \
|
||||
if (c->serial_##function) \
|
||||
_rc = c->serial_##function(&c->userdata, ##__VA_ARGS__); \
|
||||
else \
|
||||
_rc = DC_STATUS_SUCCESS; \
|
||||
block ;\
|
||||
|
||||
@ -32,7 +32,7 @@
|
||||
#endif
|
||||
|
||||
#include "context-private.h"
|
||||
#include <libdivecomputer/custom_serial.h>
|
||||
#include <libdivecomputer/custom_io.h>
|
||||
|
||||
struct dc_context_t {
|
||||
dc_loglevel_t loglevel;
|
||||
@ -46,7 +46,7 @@ struct dc_context_t {
|
||||
struct timeval timestamp;
|
||||
#endif
|
||||
#endif
|
||||
dc_custom_serial_t *custom_serial;
|
||||
dc_custom_io_t *custom_io;
|
||||
};
|
||||
|
||||
#ifdef ENABLE_LOGGING
|
||||
@ -197,7 +197,7 @@ dc_context_new (dc_context_t **out)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
context->custom_serial = NULL;
|
||||
context->custom_io = NULL;
|
||||
|
||||
*out = context;
|
||||
|
||||
@ -213,20 +213,20 @@ dc_context_free (dc_context_t *context)
|
||||
}
|
||||
|
||||
dc_status_t
|
||||
dc_context_set_custom_serial (dc_context_t *context, dc_custom_serial_t *custom_serial)
|
||||
dc_context_set_custom_io (dc_context_t *context, dc_custom_io_t *custom_io)
|
||||
{
|
||||
if (context == NULL)
|
||||
return DC_STATUS_INVALIDARGS;
|
||||
|
||||
context->custom_serial = custom_serial;
|
||||
context->custom_io = custom_io;
|
||||
|
||||
return DC_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
dc_custom_serial_t*
|
||||
_dc_context_custom_serial (dc_context_t *context)
|
||||
dc_custom_io_t*
|
||||
_dc_context_custom_io (dc_context_t *context)
|
||||
{
|
||||
return context->custom_serial;
|
||||
return context->custom_io;
|
||||
}
|
||||
|
||||
dc_status_t
|
||||
|
||||
@ -21,7 +21,7 @@ dc_context_new
|
||||
dc_context_free
|
||||
dc_context_set_loglevel
|
||||
dc_context_set_logfunc
|
||||
dc_context_set_custom_serial
|
||||
dc_context_set_custom_io
|
||||
|
||||
dc_iterator_next
|
||||
dc_iterator_free
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user