From f61d1c3908c79fb6e4c40e756faafdebc80904f7 Mon Sep 17 00:00:00 2001 From: Davide Gerhard Date: Mon, 27 May 2019 16:51:15 +0200 Subject: [PATCH] add gettimeofday() compatibility function for windows plugins that need that: - remotesink - remotesource --- CMakeLists.txt | 4 ++ custom/windows/windows_time.h | 44 +++++++++++++++++++ fcdhid/CMakeLists.txt | 2 +- fcdhid/hid-libusb.c | 4 +- plugins/channelrx/remotesink/CMakeLists.txt | 1 + plugins/channelrx/remotesink/remotesink.cpp | 5 +++ plugins/channeltx/remotesource/CMakeLists.txt | 1 + .../channeltx/remotesource/remotesource.cpp | 5 +++ qrtplib/rtptimeutilities.h | 2 +- 9 files changed, 63 insertions(+), 5 deletions(-) create mode 100644 custom/windows/windows_time.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b90e48c5..a9c774a8f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -145,6 +145,10 @@ set(INSTALL_PLUGINS_DIR "${INSTALL_LIB_DIR}/plugins") set(INSTALL_PLUGINSSRV_DIR "${INSTALL_LIB_DIR}/pluginssrv") set(EXTERNAL_BUILD_LIBRARIES "${CMAKE_BINARY_DIR}/external") +# custom libraries +set(CUSTOM_APPLE_INCLUDE "${CMAKE_SOURCE_DIR}/custom/apple" CACHE INTERNAL "") +set(CUSTOM_WINDOWS_INCLUDE "${CMAKE_SOURCE_DIR}/custom/windows" CACHE INTERNAL "") + if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux") set(LINUX TRUE) # populate distribution name diff --git a/custom/windows/windows_time.h b/custom/windows/windows_time.h new file mode 100644 index 000000000..c839e93c1 --- /dev/null +++ b/custom/windows/windows_time.h @@ -0,0 +1,44 @@ +#if (defined _WIN32_) || (defined _MSC_VER) + +/* + * missing gettimeofday implementation + * for windows; based on postgresql + */ + +#ifndef CUSTOM_WINDOWS_TIME_H_ +#define CUSTOM_WINDOWS_TIME_H_ + +#define _WINSOCKAPI_ // stops windows.h including winsock.h; timeval redefine +#include +#include // portable: uint64_t MSVC: __int64 + +// MSVC defines this in winsock2.h!? +typedef struct timeval { + long tv_sec; + long tv_usec; +} timeval; + +int gettimeofday(struct timeval * tp, struct timezone * tzp) +{ + // Note: some broken versions only have 8 trailing zero's, the correct epoch has 9 trailing zero's + // This magic number is the number of 100 nanosecond intervals since January 1, 1601 (UTC) + // until 00:00:00 January 1, 1970 + static const uint64_t EPOCH = ((uint64_t) 116444736000000000ULL); + + SYSTEMTIME system_time; + FILETIME file_time; + uint64_t time; + + GetSystemTime( &system_time ); + SystemTimeToFileTime( &system_time, &file_time ); + time = ((uint64_t)file_time.dwLowDateTime ) ; + time += ((uint64_t)file_time.dwHighDateTime) << 32; + + tp->tv_sec = (long) ((time - EPOCH) / 10000000L); + tp->tv_usec = (long) (system_time.wMilliseconds * 1000); + return 0; +} + + +#endif // CUSTOM_WINDOWS_TIME_H_ +#endif // _WIN32_ diff --git a/fcdhid/CMakeLists.txt b/fcdhid/CMakeLists.txt index d83660139..5e7ca2eb3 100644 --- a/fcdhid/CMakeLists.txt +++ b/fcdhid/CMakeLists.txt @@ -7,7 +7,6 @@ set(fcdhid_SOURCES ) set(fcdhid_HEADERS - ../custom/apple/apple_compat.h fcdhid.h hid-libusb.h hidapi.h @@ -16,6 +15,7 @@ set(fcdhid_HEADERS include_directories( ${LIBUSB_INCLUDE_DIR} ${ICONV_INCLUDE_DIR} + ${CUSTOM_APPLE_INCLUDE} ) add_library(fcdhid SHARED diff --git a/fcdhid/hid-libusb.c b/fcdhid/hid-libusb.c index 4addfd553..c45de4a40 100644 --- a/fcdhid/hid-libusb.c +++ b/fcdhid/hid-libusb.c @@ -69,9 +69,7 @@ extern "C" { * MacOS does not implement POSIX Thread Barriers */ #ifdef __APPLE__ - -#include "../custom/apple/apple_compat.h" - +#include "apple_compat.h" #endif /* Uncomment to enable the retrieval of Usage and Usage Page in diff --git a/plugins/channelrx/remotesink/CMakeLists.txt b/plugins/channelrx/remotesink/CMakeLists.txt index 1f8414d88..98e5ba82b 100644 --- a/plugins/channelrx/remotesink/CMakeLists.txt +++ b/plugins/channelrx/remotesink/CMakeLists.txt @@ -27,6 +27,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client ${Boost_INCLUDE_DIRS} ${CM256CC_INCLUDE_DIR} + ${CUSTOM_WINDOWS_INCLUDE} ) if(NOT SERVER_MODE) diff --git a/plugins/channelrx/remotesink/remotesink.cpp b/plugins/channelrx/remotesink/remotesink.cpp index 63cba4814..3259a69fb 100644 --- a/plugins/channelrx/remotesink/remotesink.cpp +++ b/plugins/channelrx/remotesink/remotesink.cpp @@ -23,8 +23,13 @@ #include "remotesink.h" +#if (defined _WIN32_) || (defined _MSC_VER) +#include "windows_time.h" +#include +#else #include #include +#endif #include #include diff --git a/plugins/channeltx/remotesource/CMakeLists.txt b/plugins/channeltx/remotesource/CMakeLists.txt index 1069bf3a8..3007c7b64 100644 --- a/plugins/channeltx/remotesource/CMakeLists.txt +++ b/plugins/channeltx/remotesource/CMakeLists.txt @@ -27,6 +27,7 @@ include_directories( ${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client ${Boost_INCLUDE_DIRS} ${CM256CC_INCLUDE_DIR} + ${CUSTOM_WINDOWS_INCLUDE} ) if(NOT SERVER_MODE) diff --git a/plugins/channeltx/remotesource/remotesource.cpp b/plugins/channeltx/remotesource/remotesource.cpp index 4409d12aa..cab97a2ff 100644 --- a/plugins/channeltx/remotesource/remotesource.cpp +++ b/plugins/channeltx/remotesource/remotesource.cpp @@ -17,8 +17,13 @@ #include "remotesource.h" +#if (defined _WIN32_) || (defined _MSC_VER) +#include "windows_time.h" +#include +#else #include #include +#endif #include #include diff --git a/qrtplib/rtptimeutilities.h b/qrtplib/rtptimeutilities.h index 8b460f659..1b5ba7c46 100644 --- a/qrtplib/rtptimeutilities.h +++ b/qrtplib/rtptimeutilities.h @@ -61,7 +61,7 @@ #endif // RTP_HAVE_VSUINT64SUFFIX #ifdef __APPLE__ -#include "../custom/apple/apple_compat.h" +#include "../custom/apple/apple_compat.h" #endif namespace qrtplib