From 404cea7417ebe7ee642da736ef70f45125d2a0ca Mon Sep 17 00:00:00 2001 From: Jef Driesen Date: Mon, 24 Apr 2017 20:18:26 +0200 Subject: [PATCH] Move the dummy IrDA implementation The dummy IrDA implementation is integrated in the main file. The appropriate implementation is selected using conditional compilation based on the features detect by the autotools build system. --- configure.ac | 10 +---- msvc/libdivecomputer.vcproj | 4 +- src/Makefile.am | 9 +---- src/descriptor.c | 12 +++++- src/irda.c | 48 +++++++++++++++++++++++ src/irda_dummy.c | 78 ------------------------------------- 6 files changed, 64 insertions(+), 97 deletions(-) delete mode 100644 src/irda_dummy.c diff --git a/configure.ac b/configure.ac index 0164677..8aee86d 100644 --- a/configure.ac +++ b/configure.ac @@ -114,13 +114,13 @@ AS_IF([test "x$with_hidapi" != "xno"], [ AC_SUBST([DEPENDENCIES]) # Checks for IrDA support. -AC_CHECK_HEADERS([winsock2.h af_irda.h], [irda_win32=yes], [irda_win32=no], [ +AC_CHECK_HEADERS([winsock2.h af_irda.h], , , [ #if HAVE_WINSOCK2_H # include # endif ]) -AC_CHECK_HEADERS([sys/socket.h linux/types.h linux/irda.h], [irda_linux=yes], [irda_linux=no], [ +AC_CHECK_HEADERS([sys/socket.h linux/types.h linux/irda.h], , , [ #if HAVE_SYS_SOCKET_H # include # endif @@ -129,12 +129,6 @@ AC_CHECK_HEADERS([sys/socket.h linux/types.h linux/irda.h], [irda_linux=yes], [i # endif ]) -if test "$irda_win32" = "yes" || test "$irda_linux" = "yes"; then - AC_DEFINE([HAVE_IRDA], [1], [IrDA support]) -fi - -AM_CONDITIONAL([IRDA], [test "$irda_win32" = "yes" || test "$irda_linux" = "yes"]) - # Checks for header files. AC_CHECK_HEADERS([linux/serial.h]) AC_CHECK_HEADERS([IOKit/serial/ioss.h]) diff --git a/msvc/libdivecomputer.vcproj b/msvc/libdivecomputer.vcproj index 260ecbf..738dd12 100644 --- a/msvc/libdivecomputer.vcproj +++ b/msvc/libdivecomputer.vcproj @@ -42,7 +42,7 @@ Name="VCCLCompilerTool" Optimization="0" AdditionalIncludeDirectories="..\include" - PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_IRDA" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_AF_IRDA_H" MinimalRebuild="true" BasicRuntimeChecks="3" RuntimeLibrary="3" @@ -119,7 +119,7 @@ Optimization="2" EnableIntrinsicFunctions="true" AdditionalIncludeDirectories="..\include" - PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_IRDA" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBDIVECOMPUTER_EXPORTS;ENABLE_LOGGING;HAVE_AF_IRDA_H" RuntimeLibrary="2" EnableFunctionLevelLinking="true" UsePrecompiledHeader="0" diff --git a/src/Makefile.am b/src/Makefile.am index b98e57e..966bf94 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -10,6 +10,7 @@ libdivecomputer_la_LDFLAGS = \ -export-symbols libdivecomputer.exp if OS_WIN32 +libdivecomputer_la_LIBADD += -lws2_32 libdivecomputer_la_LDFLAGS += -Wc,-static-libgcc endif @@ -74,15 +75,7 @@ else libdivecomputer_la_SOURCES += serial.h serial_posix.c endif -if IRDA -if OS_WIN32 -libdivecomputer_la_LIBADD += -lws2_32 -endif libdivecomputer_la_SOURCES += irda.h irda.c -else -libdivecomputer_la_SOURCES += irda.h irda_dummy.c -endif - libdivecomputer_la_SOURCES += usbhid.h usbhid.c if OS_WIN32 diff --git a/src/descriptor.c b/src/descriptor.c index 70b51d4..e019172 100644 --- a/src/descriptor.c +++ b/src/descriptor.c @@ -29,6 +29,16 @@ #define USBHID #endif +#ifdef _WIN32 +#ifdef HAVE_AF_IRDA_H +#define IRDA +#endif +#else +#ifdef HAVE_LINUX_IRDA_H +#define IRDA +#endif +#endif + #include #include @@ -100,7 +110,7 @@ static const dc_descriptor_t g_descriptors[] = { /* Uwatec Memomouse */ {"Uwatec", "Memomouse", DC_FAMILY_UWATEC_MEMOMOUSE, 0}, /* Uwatec Smart */ -#ifdef HAVE_IRDA +#ifdef IRDA {"Uwatec", "Smart Pro", DC_FAMILY_UWATEC_SMART, 0x10}, {"Uwatec", "Galileo Sol", DC_FAMILY_UWATEC_SMART, 0x11}, {"Uwatec", "Galileo Luna", DC_FAMILY_UWATEC_SMART, 0x11}, diff --git a/src/irda.c b/src/irda.c index 2271a69..0f20970 100644 --- a/src/irda.c +++ b/src/irda.c @@ -19,21 +19,31 @@ * MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include // malloc, free #include // snprintf #ifdef _WIN32 #define NOGDI #include #include + #ifdef HAVE_AF_IRDA_H + #define IRDA #include + #endif #else #include // strerror #include // errno #include // close #include // socket, getsockopt #include // socket, getsockopt + #ifdef HAVE_LINUX_IRDA_H + #define IRDA #include // irda #include // irda + #endif #include // select #include // ioctl #include @@ -86,6 +96,7 @@ struct dc_irda_t { int timeout; }; +#ifdef IRDA static dc_status_t syserror(s_errcode_t errcode) { @@ -102,10 +113,12 @@ syserror(s_errcode_t errcode) return DC_STATUS_IO; } } +#endif dc_status_t dc_irda_open (dc_irda_t **out, dc_context_t *context) { +#ifdef IRDA dc_status_t status = DC_STATUS_SUCCESS; dc_irda_t *device = NULL; @@ -167,11 +180,15 @@ error_free: #endif free (device); return status; +#else + return DC_STATUS_UNSUPPORTED; +#endif } dc_status_t dc_irda_close (dc_irda_t *device) { +#ifdef IRDA dc_status_t status = DC_STATUS_SUCCESS; if (device == NULL) @@ -200,11 +217,15 @@ dc_irda_close (dc_irda_t *device) free (device); return status; +#else + return DC_STATUS_UNSUPPORTED; +#endif } dc_status_t dc_irda_set_timeout (dc_irda_t *device, int timeout) { +#ifdef IRDA if (device == NULL) return DC_STATUS_INVALIDARGS; @@ -213,6 +234,9 @@ dc_irda_set_timeout (dc_irda_t *device, int timeout) device->timeout = timeout; return DC_STATUS_SUCCESS; +#else + return DC_STATUS_UNSUPPORTED; +#endif } @@ -230,6 +254,7 @@ dc_irda_set_timeout (dc_irda_t *device, int timeout) dc_status_t dc_irda_discover (dc_irda_t *device, dc_irda_callback_t callback, void *userdata) { +#ifdef IRDA if (device == NULL) return DC_STATUS_INVALIDARGS; @@ -303,11 +328,15 @@ dc_irda_discover (dc_irda_t *device, dc_irda_callback_t callback, void *userdata } return DC_STATUS_SUCCESS; +#else + return DC_STATUS_UNSUPPORTED; +#endif } dc_status_t dc_irda_connect_name (dc_irda_t *device, unsigned int address, const char *name) { +#ifdef IRDA if (device == NULL) return DC_STATUS_INVALIDARGS; @@ -341,11 +370,15 @@ dc_irda_connect_name (dc_irda_t *device, unsigned int address, const char *name) } return DC_STATUS_SUCCESS; +#else + return DC_STATUS_UNSUPPORTED; +#endif } dc_status_t dc_irda_connect_lsap (dc_irda_t *device, unsigned int address, unsigned int lsap) { +#ifdef IRDA if (device == NULL) return DC_STATUS_INVALIDARGS; @@ -374,11 +407,15 @@ dc_irda_connect_lsap (dc_irda_t *device, unsigned int address, unsigned int lsap } return DC_STATUS_SUCCESS; +#else + return DC_STATUS_UNSUPPORTED; +#endif } dc_status_t dc_irda_get_available (dc_irda_t *device, size_t *value) { +#ifdef IRDA if (device == NULL) return DC_STATUS_INVALIDARGS; @@ -398,11 +435,15 @@ dc_irda_get_available (dc_irda_t *device, size_t *value) *value = bytes; return DC_STATUS_SUCCESS; +#else + return DC_STATUS_UNSUPPORTED; +#endif } dc_status_t dc_irda_read (dc_irda_t *device, void *data, size_t size, size_t *actual) { +#ifdef IRDA dc_status_t status = DC_STATUS_SUCCESS; size_t nbytes = 0; @@ -463,11 +504,15 @@ out_invalidargs: *actual = nbytes; return status; +#else + return DC_STATUS_UNSUPPORTED; +#endif } dc_status_t dc_irda_write (dc_irda_t *device, const void *data, size_t size, size_t *actual) { +#ifdef IRDA dc_status_t status = DC_STATUS_SUCCESS; size_t nbytes = 0; @@ -520,4 +565,7 @@ out_invalidargs: *actual = nbytes; return status; +#else + return DC_STATUS_UNSUPPORTED; +#endif } diff --git a/src/irda_dummy.c b/src/irda_dummy.c deleted file mode 100644 index 7579324..0000000 --- a/src/irda_dummy.c +++ /dev/null @@ -1,78 +0,0 @@ -/* - * libdivecomputer - * - * Copyright (C) 2010 Jef Driesen - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ - -#include - -#include "irda.h" - -dc_status_t -dc_irda_open (dc_irda_t **out, dc_context_t *context) -{ - return DC_STATUS_UNSUPPORTED; -} - -dc_status_t -dc_irda_close (dc_irda_t *device) -{ - return DC_STATUS_UNSUPPORTED; -} - -dc_status_t -dc_irda_set_timeout (dc_irda_t *device, int timeout) -{ - return DC_STATUS_UNSUPPORTED; -} - -dc_status_t -dc_irda_discover (dc_irda_t *device, dc_irda_callback_t callback, void *userdata) -{ - return DC_STATUS_UNSUPPORTED; -} - -dc_status_t -dc_irda_connect_name (dc_irda_t *device, unsigned int address, const char *name) -{ - return DC_STATUS_UNSUPPORTED; -} - -dc_status_t -dc_irda_connect_lsap (dc_irda_t *device, unsigned int address, unsigned int lsap) -{ - return DC_STATUS_UNSUPPORTED; -} - -dc_status_t -dc_irda_get_available (dc_irda_t *device, size_t *value) -{ - return DC_STATUS_UNSUPPORTED; -} - -dc_status_t -dc_irda_read (dc_irda_t *device, void *data, size_t size, size_t *actual) -{ - return DC_STATUS_UNSUPPORTED; -} - -dc_status_t -dc_irda_write (dc_irda_t *device, const void *data, size_t size, size_t *actual) -{ - return DC_STATUS_UNSUPPORTED; -}