Просмотр исходного кода

Create skeleton of folders and move tcp defines

Jose Cabral лет назад: 7
Родитель
Сommit
57b342a889

+ 3 - 0
CMakeLists.txt

@@ -69,6 +69,9 @@ GET_PROPERTY(architectures GLOBAL PROPERTY UA_ARCHITECTURES)
 list(SORT architectures)
 set_property(CACHE UA_ARCHITECTURE PROPERTY STRINGS None ${architectures})
 
+GET_PROPERTY(directoriesToInclude GLOBAL PROPERTY UA_INCLUDE_DIRECTORIES)
+include_directories(${directoriesToInclude})
+
 # Encryption Options
 option(UA_ENABLE_ENCRYPTION "Enable encryption support (uses mbedTLS)" OFF)
 

+ 2 - 0
plugins/arch/CMakeLists.txt

@@ -1,3 +1,5 @@
 SET(SOURCE_GROUP ${SOURCE_GROUP}\\arch)
 
+add_subdirectory(posix)
+add_subdirectory(win32)
 add_subdirectory(arduino)

+ 9 - 0
plugins/arch/posix/CMakeLists.txt

@@ -0,0 +1,9 @@
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\posix)
+
+ua_add_architecture("posix")
+
+if("${UA_ARCHITECTURE}" STREQUAL "posix")
+
+ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+endif()

+ 113 - 0
plugins/arch/posix/ua_architecture.h

@@ -0,0 +1,113 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
+ *    Copyright 2017 (c) Stefan Profanter, fortiss GmbH
+ */
+
+#ifndef PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
+#define PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_
+
+/* Enable POSIX features */
+#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
+# define _XOPEN_SOURCE 600
+#endif
+#ifndef _DEFAULT_SOURCE
+# define _DEFAULT_SOURCE
+#endif
+/* On older systems we need to define _BSD_SOURCE.
+ * _DEFAULT_SOURCE is an alias for that. */
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE
+#endif
+
+#if !defined(UA_FREERTOS)
+# include <errno.h>
+#else
+# define AI_PASSIVE 0x01
+# define TRUE 1
+# define FALSE 0
+# define ioctl ioctlsocket
+#endif
+
+# if defined(UA_FREERTOS)
+#  define UA_FREERTOS_HOSTNAME "10.200.4.114"
+static inline int gethostname_freertos(char* name, size_t len){
+  if(strlen(UA_FREERTOS_HOSTNAME) > (len))
+    return -1;
+  strcpy(name, UA_FREERTOS_HOSTNAME);
+  return 0;
+}
+#define gethostname gethostname_freertos
+#  include <lwip/tcpip.h>
+#  include <lwip/netdb.h>
+#  define CLOSESOCKET(S) lwip_close(S)
+#  define sockaddr_storage sockaddr
+#  ifdef BYTE_ORDER
+#   undef BYTE_ORDER
+#  endif
+#  define UA_sleep_ms(X) vTaskDelay(pdMS_TO_TICKS(X))
+# else /* Not freeRTOS */
+#  define CLOSESOCKET(S) close(S)
+#  include <arpa/inet.h>
+#  include <netinet/in.h>
+#  include <netdb.h>
+#  include <sys/ioctl.h>
+#  if defined(_WRS_KERNEL)
+#   include <hostLib.h>
+#   include <selectLib.h>
+#   define UA_sleep_ms(X)                            \
+    {                                                \
+    struct timespec timeToSleep;                     \
+      timeToSleep.tv_sec = X / 1000;                 \
+      timeToSleep.tv_nsec = 1000000 * (X % 1000);    \
+      nanosleep(&timeToSleep, NULL);                 \
+    }
+#  else /* defined(_WRS_KERNEL) */
+#   include <sys/select.h>
+#   define UA_sleep_ms(X) usleep(X * 1000)
+#  endif /* defined(_WRS_KERNEL) */
+# endif /* Not freeRTOS */
+
+# define SOCKET int
+# define WIN32_INT
+# define OPTVAL_TYPE int
+# define ERR_CONNECTION_PROGRESS EINPROGRESS
+
+
+# include <fcntl.h>
+# include <unistd.h> // read, write, close
+
+# ifdef __QNX__
+#  include <sys/socket.h>
+# endif
+# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
+#  include <sys/param.h>
+#  if defined(BSD)
+#   include<sys/socket.h>
+#  endif
+# endif
+# if !defined(__CYGWIN__) && !defined(UA_FREERTOS)
+#  include <netinet/tcp.h>
+# endif
+
+/* unsigned int for windows and workaround to a glibc bug */
+/* Additionally if GNU_LIBRARY is not defined, it may be using
+ * musl libc (e.g. Docker Alpine) */
+#if defined(_WIN32) || defined(__OpenBSD__) || \
+    (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
+     (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
+    !defined(__GNU_LIBRARY__))
+# define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
+# define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
+#else
+# define UA_fd_set(fd, fds) FD_SET(fd, fds)
+# define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
+#endif
+
+# define errno__ errno
+# define INTERRUPTED EINTR
+# define WOULDBLOCK EWOULDBLOCK
+# define AGAIN EAGAIN
+
+#endif /* PLUGINS_ARCH_POSIX_UA_ARCHITECTURE_H_ */

+ 9 - 0
plugins/arch/win32/CMakeLists.txt

@@ -0,0 +1,9 @@
+SET(SOURCE_GROUP ${SOURCE_GROUP}\\win32)
+
+ua_add_architecture("win32")
+
+if("${UA_ARCHITECTURE}" STREQUAL "win32")
+
+ua_include_directories(${CMAKE_CURRENT_SOURCE_DIR})
+
+endif()

+ 63 - 0
plugins/arch/win32/ua_architecture.h

@@ -0,0 +1,63 @@
+/* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
+ * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
+ *
+ *    Copyright 2016-2017 (c) Julius Pfrommer, Fraunhofer IOSB
+ *    Copyright 2017 (c) Stefan Profanter, fortiss GmbH
+ */
+
+#ifndef PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
+#define PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_
+
+#ifndef _BSD_SOURCE
+# define _BSD_SOURCE
+#endif
+
+/* Disable some security warnings on MSVC */
+#ifdef _MSC_VER
+# define _CRT_SECURE_NO_WARNINGS
+#endif
+
+/* Assume that Windows versions are newer than Windows XP */
+#if defined(__MINGW32__) && (!defined(WINVER) || WINVER < 0x501)
+# undef WINVER
+# undef _WIN32_WINDOWS
+# undef _WIN32_WINNT
+# define WINVER 0x0501
+# define _WIN32_WINDOWS 0x0501
+# define _WIN32_WINNT 0x0501
+#endif
+
+# include <errno.h>
+# include <winsock2.h>
+# include <ws2tcpip.h>
+# define CLOSESOCKET(S) closesocket((SOCKET)S)
+# define ssize_t int
+# define WIN32_INT (int)
+# define OPTVAL_TYPE char
+# define ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
+# define UA_sleep_ms(X) Sleep(X)
+
+/* unsigned int for windows and workaround to a glibc bug */
+/* Additionally if GNU_LIBRARY is not defined, it may be using
+ * musl libc (e.g. Docker Alpine) */
+#if defined(_WIN32) || defined(__OpenBSD__) || \
+    (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
+     (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
+    !defined(__GNU_LIBRARY__))
+# define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
+# define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
+#else
+# define UA_fd_set(fd, fds) FD_SET(fd, fds)
+# define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
+#endif
+
+#ifdef UNDER_CE
+# define errno WSAGetLastError()
+#endif
+
+# define errno__ WSAGetLastError()
+# define INTERRUPTED WSAEINTR
+# define WOULDBLOCK WSAEWOULDBLOCK
+# define AGAIN WSAEWOULDBLOCK
+
+#endif /* PLUGINS_ARCH_WIN32_UA_ARCHITECTURE_H_ */

+ 1 - 155
plugins/ua_network_tcp.c

@@ -8,33 +8,8 @@
  *    Copyright 2017 (c) Thomas Stalder, Blue Time Concept SA
  */
 
-/* Enable POSIX features */
-#if !defined(_XOPEN_SOURCE) && !defined(_WRS_KERNEL)
-# define _XOPEN_SOURCE 600
-#endif
-#ifndef _DEFAULT_SOURCE
-# define _DEFAULT_SOURCE
-#endif
-/* On older systems we need to define _BSD_SOURCE.
- * _DEFAULT_SOURCE is an alias for that. */
-#ifndef _BSD_SOURCE
-# define _BSD_SOURCE
-#endif
 
-/* Disable some security warnings on MSVC */
-#ifdef _MSC_VER
-# define _CRT_SECURE_NO_WARNINGS
-#endif
-
-/* Assume that Windows versions are newer than Windows XP */
-#if defined(__MINGW32__) && (!defined(WINVER) || WINVER < 0x501)
-# undef WINVER
-# undef _WIN32_WINDOWS
-# undef _WIN32_WINNT
-# define WINVER 0x0501
-# define _WIN32_WINDOWS 0x0501
-# define _WIN32_WINNT 0x0501
-#endif
+#include <ua_architecture.h>
 
 #include "ua_network_tcp.h"
 #include "ua_log_stdout.h"
@@ -43,135 +18,6 @@
 #include <stdio.h> // snprintf
 #include <string.h> // memset
 
-#if !defined(UA_FREERTOS)
-# include <errno.h>
-#else
-# define AI_PASSIVE 0x01
-# define TRUE 1
-# define FALSE 0
-# define ioctl ioctlsocket
-#endif
-
-#ifdef _WIN32
-# include <winsock2.h>
-# include <ws2tcpip.h>
-# define CLOSESOCKET(S) closesocket((SOCKET)S)
-# define ssize_t int
-# define WIN32_INT (int)
-# define OPTVAL_TYPE char
-# define ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK
-#else /* _WIN32 */
-# if defined(UA_FREERTOS)
-#  define UA_FREERTOS_HOSTNAME "10.200.4.114"
-static inline int gethostname_freertos(char* name, size_t len){
-  if(strlen(UA_FREERTOS_HOSTNAME) > (len))
-    return -1;
-  strcpy(name, UA_FREERTOS_HOSTNAME);
-  return 0;
-}
-#define gethostname gethostname_freertos
-#  include <lwip/tcpip.h>
-#  include <lwip/netdb.h>
-#  define CLOSESOCKET(S) lwip_close(S)
-#  define sockaddr_storage sockaddr
-#  ifdef BYTE_ORDER
-#   undef BYTE_ORDER
-#  endif
-# else /* Not freeRTOS */
-#  define CLOSESOCKET(S) close(S)
-#  include <arpa/inet.h>
-#  include <netinet/in.h>
-#  include <netdb.h>
-#  include <sys/ioctl.h>
-#  if defined(_WRS_KERNEL)
-#   include <hostLib.h>
-#   include <selectLib.h>
-#  else /* defined(_WRS_KERNEL) */
-#   include <sys/select.h>
-#  endif /* defined(_WRS_KERNEL) */
-# endif /* Not freeRTOS */
-
-# define SOCKET int
-# define WIN32_INT
-# define OPTVAL_TYPE int
-# define ERR_CONNECTION_PROGRESS EINPROGRESS
-
-
-# include <fcntl.h>
-# include <unistd.h> // read, write, close
-
-# ifdef __QNX__
-#  include <sys/socket.h>
-# endif
-# if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
-#  include <sys/param.h>
-#  if defined(BSD)
-#   include<sys/socket.h>
-#  endif
-# endif
-# if !defined(__CYGWIN__) && !defined(UA_FREERTOS)
-#  include <netinet/tcp.h>
-# endif
-#endif /* _WIN32 */
-
-#ifndef UA_sleep_ms
-# ifdef _WIN32
-#  define UA_sleep_ms(X) Sleep(X)
-# else /* _WIN32 */
-#  if defined(UA_FREERTOS)
-#   define UA_sleep_ms(X) vTaskDelay(pdMS_TO_TICKS(X))
-#  else /* Not freeRTOS */
-#   if defined(_WRS_KERNEL)
-#    include <hostLib.h>
-#    include <selectLib.h>
-#    define UA_sleep_ms(X)                            \
-     {                                                \
-     struct timespec timeToSleep;                     \
-       timeToSleep.tv_sec = X / 1000;                 \
-       timeToSleep.tv_nsec = 1000000 * (X % 1000);    \
-       nanosleep(&timeToSleep, NULL);                 \
-     }
-#   else /* defined(_WRS_KERNEL) */
-#    define UA_sleep_ms(X) usleep(X * 1000)
-#   endif /* defined(_WRS_KERNEL) */
-#  endif /* Not freeRTOS */
-# endif /* _WIN32 */
-#else /* UA_sleep_ms */
-/* With this one can define its own UA_sleep_ms using a preprocessor define.
-E.g. see unit tests. */
-void UA_sleep_ms(size_t);
-#endif
-
-/* unsigned int for windows and workaround to a glibc bug */
-/* Additionally if GNU_LIBRARY is not defined, it may be using
- * musl libc (e.g. Docker Alpine) */
-#if defined(_WIN32) || defined(__OpenBSD__) || \
-    (defined(__GNU_LIBRARY__) && (__GNU_LIBRARY__ <= 6) && \
-     (__GLIBC__ <= 2) && (__GLIBC_MINOR__ < 16) || \
-    !defined(__GNU_LIBRARY__))
-# define UA_fd_set(fd, fds) FD_SET((unsigned int)fd, fds)
-# define UA_fd_isset(fd, fds) FD_ISSET((unsigned int)fd, fds)
-#else
-# define UA_fd_set(fd, fds) FD_SET(fd, fds)
-# define UA_fd_isset(fd, fds) FD_ISSET(fd, fds)
-#endif
-
-#ifdef UNDER_CE
-# define errno WSAGetLastError()
-#endif
-
-#ifdef _WIN32
-# define errno__ WSAGetLastError()
-# define INTERRUPTED WSAEINTR
-# define WOULDBLOCK WSAEWOULDBLOCK
-# define AGAIN WSAEWOULDBLOCK
-#else
-# define errno__ errno
-# define INTERRUPTED EINTR
-# define WOULDBLOCK EWOULDBLOCK
-# define AGAIN EAGAIN
-#endif
-
 #include "ua_log_socket_error.h"
 
 /****************************/

+ 7 - 1
tools/cmake/macros.cmake

@@ -2,4 +2,10 @@ FUNCTION(ua_add_architecture)
     FOREACH(ARG ${ARGV})
         set_property(GLOBAL APPEND PROPERTY UA_ARCHITECTURES ${ARG})
     ENDFOREACH(ARG)
-ENDFUNCTION(ua_add_architecture)
+ENDFUNCTION(ua_add_architecture)
+
+FUNCTION(ua_include_directories)
+    FOREACH(ARG ${ARGV})
+        set_property(GLOBAL APPEND PROPERTY UA_INCLUDE_DIRECTORIES ${ARG})
+    ENDFOREACH(ARG)
+ENDFUNCTION(ua_include_directories)