From aee59a33bea1fe66a8ff8e8ac63bb045392ab28c Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Tue, 29 Aug 2017 20:25:55 +0200 Subject: [PATCH] Add support for querying the available built-in transports Because the list of supported built-in transports depends on the availability of external libraries (libusb, hidapi) and the operating system, the application needs some mechanism to retrieve this information at runtime. Therefore, a new dc_context_get_transports() function is added, which returns a bitmask with all the available built-in transports. --- include/libdivecomputer/context.h | 3 +++ src/context.c | 36 +++++++++++++++++++++++++++++++ src/libdivecomputer.symbols | 1 + 3 files changed, 40 insertions(+) diff --git a/include/libdivecomputer/context.h b/include/libdivecomputer/context.h index 861dbeb..824b67b 100644 --- a/include/libdivecomputer/context.h +++ b/include/libdivecomputer/context.h @@ -53,6 +53,9 @@ dc_context_set_loglevel (dc_context_t *context, dc_loglevel_t loglevel); dc_status_t dc_context_set_logfunc (dc_context_t *context, dc_logfunc_t logfunc, void *userdata); +unsigned int +dc_context_get_transports (dc_context_t *context); + #ifdef __cplusplus } #endif /* __cplusplus */ diff --git a/src/context.c b/src/context.c index 181fef1..8c73aca 100644 --- a/src/context.c +++ b/src/context.c @@ -19,6 +19,10 @@ * MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -313,3 +317,35 @@ dc_context_hexdump (dc_context_t *context, dc_loglevel_t loglevel, const char *f return DC_STATUS_SUCCESS; } + +unsigned int +dc_context_get_transports (dc_context_t *context) +{ + UNUSED(context); + + return DC_TRANSPORT_SERIAL +#if defined(HAVE_LIBUSB) + | DC_TRANSPORT_USB +#endif +#if defined(HAVE_HIDAPI) + | DC_TRANSPORT_USBHID +#elif defined(HAVE_LIBUSB) && !defined(__APPLE__) + | DC_TRANSPORT_USBHID +#endif +#ifdef _WIN32 +#ifdef HAVE_AF_IRDA_H + | DC_TRANSPORT_IRDA +#endif +#ifdef HAVE_WS2BTH_H + | DC_TRANSPORT_BLUETOOTH +#endif +#else /* _WIN32 */ +#ifdef HAVE_LINUX_IRDA_H + | DC_TRANSPORT_IRDA +#endif +#ifdef HAVE_BLUEZ + | DC_TRANSPORT_BLUETOOTH +#endif +#endif /* _WIN32 */ + ; +} diff --git a/src/libdivecomputer.symbols b/src/libdivecomputer.symbols index 6f95948..4433a68 100644 --- a/src/libdivecomputer.symbols +++ b/src/libdivecomputer.symbols @@ -21,6 +21,7 @@ dc_context_new dc_context_free dc_context_set_loglevel dc_context_set_logfunc +dc_context_get_transports dc_iterator_next dc_iterator_free