Переглянути джерело

Closes #186 Move platform-dependent networkhandler.h to platform folder

The header for platform dependent networkhandler functions is moved to ports
folder, to reduce the amount of duplicated code and documentation.
Updates documentation on GetMilliSeconds and GetMicroSeconds

Signed-off-by: Martin Melik-Merkumians <melik-merkumians@acin.tuwien.ac.at>
Martin Melik-Merkumians 6 роки тому
батько
коміт
67e5013621

+ 2 - 0
source/src/cip/cipconnectionobject.c

@@ -4,6 +4,8 @@
  *
  ******************************************************************************/
 
+#include <string.h>
+
 #include "cipconnectionobject.h"
 
 #include "endianconv.h"

+ 1 - 1
source/src/enet_encap/cpf.c

@@ -23,7 +23,7 @@ const size_t sequenced_address_item_length = 8;
 
 CipCommonPacketFormatData g_common_packet_format_data_item; /**< CPF global data items */
 
-int NotifyCommonPacketFormat(EncapsulationData *const received_data,
+int NotifyCommonPacketFormat(const EncapsulationData *const received_data,
                              const struct sockaddr *const originator_address,
                              ENIPMessage *const outgoing_message) {
   int return_value = kEipStatusError;

+ 1 - 1
source/src/enet_encap/cpf.h

@@ -80,7 +80,7 @@ typedef struct {
  * @param outgoing_message The outgoing ENIP message struct
  * @return number of bytes to be sent back. < 0 if nothing should be sent
  */
-int NotifyCommonPacketFormat(EncapsulationData *const received_data,
+int NotifyCommonPacketFormat(const EncapsulationData *const received_data,
                              const struct sockaddr *const originator_address,
                              ENIPMessage *const outgoing_message);
 

+ 0 - 43
source/src/ports/MINGW/networkhandler.h

@@ -1,43 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, Rockwell Automation, Inc.
- * All rights reserved.
- *
- ******************************************************************************/
-#ifndef NETWORKHANDLER_H_
-#define NETWORKHANDLER_H_
-
-#include "winsock2.h"
-#include "typedefs.h"
-#include <Ws2tcpip.h>
-
-#define OPENER_SOCKET_WOULD_BLOCK WSAEWOULDBLOCK
-
-// THis type is defined in Ws2tcpip.h!
-//typedef unsigned long socklen_t;
-
-EipStatus NetworkHandlerInitializePlatform(void);
-
-/** @brief Platform dependent code to close a socket
- *
- *  @param socket_handle The socket handle to be closed
- */
-void CloseSocketPlatform(int socket_handle);
-
-int SetSocketToNonBlocking(int socket_handle);
-
-/** @brief This function shall return the current time in microseconds relative to epoch, and shall be implemented in a port specific networkhandler
- *
- *  @return Current time relative to epoch as MicroSeconds
- */
-MicroSeconds GetMicroSeconds(void);
-
-/** @brief This function shall return the current time in milliseconds relative to epoch, and shall be implemented in a port specific networkhandler
- *
- *  @return Current time relative to epoch as MilliSeconds
- */
-MilliSeconds GetMilliSeconds(void);
-
-int SetQosOnSocket(int socket,
-                   CipUsint qos_value);
-
-#endif /*NETWORKHANDLER_H_*/

+ 8 - 0
source/src/ports/MINGW/platform_network_includes.h

@@ -0,0 +1,8 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+#include <winsock2.h>
+#include <ws2tcpip.h>

+ 4 - 0
source/src/ports/POSIX/networkhandler.c

@@ -7,6 +7,10 @@
 #include <sys/time.h>
 #include <time.h>
 #include <fcntl.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
 
 #include "networkhandler.h"
 

+ 0 - 47
source/src/ports/POSIX/networkhandler.h

@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, Rockwell Automation, Inc.
- * All rights reserved.
- *
- ******************************************************************************/
-#ifndef OPENER_NETWORKHANDLER_H_
-#define OPENER_NETWORKHANDLER_H_
-
-#include <string.h>
-#include <sys/socket.h>
-#include <sys/types.h>
-#include <netinet/in.h>
-
-#include "typedefs.h"
-
-#define OPENER_SOCKET_WOULD_BLOCK EWOULDBLOCK
-
-/** @brief Executes platform dependent network handler initialization code
- *
- *      @return EipStatusOk if initialization was successful, otherwise EipStatusError
- */
-EipStatus NetworkHandlerInitializePlatform(void);
-
-/** @brief Platform dependent code to close a socket
- *
- *  @param socket_handle The socket handle to be closed
- */
-void CloseSocketPlatform(int socket_handle);
-
-int SetSocketToNonBlocking(int socket_handle);
-
-/** @brief This function shall return the current time in microseconds relative to epoch, and shall be implemented in a port specific networkhandler
- *
- *  @return Current time relative to epoch as MicroSeconds
- */
-MicroSeconds GetMicroSeconds(void);
-
-/** @brief This function shall return the current time in milliseconds relative to epoch, and shall be implemented in a port specific networkhandler
- *
- *  @return Current time relative to epoch as MilliSeconds
- */
-MilliSeconds GetMilliSeconds(void);
-
-int SetQosOnSocket(const int socket,
-                   CipUsint qos_value);
-
-#endif /* OPENER_NETWORKHANDLER_H_ */

+ 6 - 0
source/src/ports/POSIX/platform_network_includes.h

@@ -0,0 +1,6 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+

+ 0 - 38
source/src/ports/WIN32/networkhandler.h

@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009, Rockwell Automation, Inc.
- * All rights reserved.
- *
- ******************************************************************************/
-#ifndef NETWORKHANDLER_H_
-#define NETWORKHANDLER_H_
-
-#include "typedefs.h"
-
-#define OPENER_SOCKET_WOULD_BLOCK WSAEWOULDBLOCK
-
-EipStatus NetworkHandlerInitializePlatform(void);
-
-/** @brief Platform dependent code to close a socket
- *
- *  @param socket_handle The socket handle to be closed
- */
-void CloseSocketPlatform(int socket_handle);
-
-int SetSocketToNonBlocking(int socket_handle);
-
-/** @brief This function shall return the current time in microseconds relative to epoch, and shall be implemented in a port specific networkhandler
- *
- *  @return Current time relative to epoch as MicroSeconds
- */
-MicroSeconds GetMicroSeconds(void);
-
-/** @brief This function shall return the current time in milliseconds relative to epoch, and shall be implemented in a port specific networkhandler
- *
- *  @return Current time relative to epoch as MilliSeconds
- */
-MilliSeconds GetMilliSeconds(void);
-
-int SetQosOnSocket(int socket,
-                   CipUsint qos_value);
-
-#endif /*NETWORKHANDLER_H_*/

+ 8 - 0
source/src/ports/WIN32/platform_network_includes.h

@@ -0,0 +1,8 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+
+#include <winsock2.h>
+#include <ws2tcpip.h>

+ 68 - 0
source/src/ports/networkhandler.h

@@ -0,0 +1,68 @@
+/*******************************************************************************
+ * Copyright (c) 2009, Rockwell Automation, Inc.
+ * All rights reserved.
+ *
+ ******************************************************************************/
+#ifndef OPENER_NETWORKHANDLER_H_
+#define OPENER_NETWORKHANDLER_H_
+
+#include "typedefs.h"
+
+#define OPENER_SOCKET_WOULD_BLOCK EWOULDBLOCK
+
+/** @brief Executes platform dependent network handler initialization code
+ *
+ *  @return EipStatusOk if initialization was successful, otherwise EipStatusError
+ */
+EipStatus NetworkHandlerInitializePlatform(void);
+
+/** @brief Platform dependent code to close a socket
+ *
+ *  @param socket_handle The socket handle to be closed
+ */
+void CloseSocketPlatform(int socket_handle);
+
+/** @brief Tries to set socket to non blocking behavior
+ *
+ * @param socket_handle The socket handle to be set
+ *
+ * @return platform specific result code
+ */
+int SetSocketToNonBlocking(int socket_handle);
+
+/** @brief Returns current time in microseconds from monotonic time base, please note
+ *  that this does not represent a real absolute time, but measured from an arbitrary starting point
+ *
+ * This function returns the current time relative to an arbitrary starting point from a monotonic time source.
+ * As monotonic clocks and clock functions in general are platform dependent, this has to be implemented for each platform
+ * (see ports subfolders)
+ *
+ *  @return Current time relative to monotonic clock starting point as MicroSeconds
+ */
+MicroSeconds GetMicroSeconds(void);
+
+/** @brief Returns current time in milliseconds from monotonic time base, please note
+ *  that this does not represent a real absolute time, but measured from an arbitrary starting point
+ *
+ * This function returns the current time relative to an arbitrary starting point from a monotonic time source.
+ * As monotonic clocks and clock functions in general are platform dependent, this has to be implemented for each platform
+ * (see ports subfolders)
+ *
+ *  @return Current time relative to monotonic clock starting point as MilliSeconds
+ */
+MilliSeconds GetMilliSeconds(void);
+
+/** @brief Sets QoS on socket
+ *
+ * A wrapper function - needs a platform dependent implementation to set QoS on a socket
+ *
+ * @param socket The socket which QoS shall be set
+ * @param qos_value The desired QoS value, as specified in ENIP Vol.2 QoS Object
+ *
+ * @return platform dependent result code
+ *
+ */
+int SetQosOnSocket(const int socket,
+                   CipUsint qos_value);
+
+#endif /* OPENER_NETWORKHANDLER_H_ */

+ 2 - 0
source/src/typedefs.h

@@ -10,6 +10,8 @@
 #include <stddef.h>
 #include <stdbool.h>
 
+#include "platform_network_includes.h"
+
 /** @file typedefs.h
    Do not use interface types for internal variables, such as "int i;", which is
    commonly used for loop counters or counting things.

+ 9 - 0
source/tests/CMakeLists.txt

@@ -7,8 +7,17 @@
 #######################################
 add_test_includes()
 
+
+#######################################
+# Add common includes                 #
+#######################################
 opener_common_includes()
 
+#######################################
+# Add platform-specific includes      #
+#######################################
+opener_platform_support("INCLUDES")
+
 ###################################################
 # Copy custom test output file to binary location #
 ###################################################

+ 1 - 0
source/tests/enet_encap/CMakeLists.txt

@@ -1,4 +1,5 @@
 #######################################
+#######################################
 # Add common includes                 #
 #######################################
 opener_common_includes()

+ 8 - 0
source/tests/ports/CMakeLists.txt

@@ -1,6 +1,14 @@
 
+#######################################
+# Add common includes                 #
+#######################################
 opener_common_includes()
 
+#######################################
+# Add platform-specific includes      #
+#######################################
+opener_platform_support("INCLUDES")
+
 set( PortsTestSrc socket_timer_tests.cpp )
 
 include_directories( ${SRC_DIR}/ports )