ua_architecture_functions.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* This work is licensed under a Creative Commons CCZero 1.0 Universal License.
  2. * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  3. *
  4. * Copyright 2018 (c) Jose Cabral, fortiss GmbH
  5. */
  6. /*
  7. * This header has all the functions that are architecture dependent. The declaration is behind a ifndef since
  8. * they can be previously defined in the ua_architecture.h which include this files at the end
  9. */
  10. #ifndef PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_
  11. #define PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_
  12. #include <open62541/config.h>
  13. _UA_BEGIN_DECLS
  14. /*
  15. * Allocation functions
  16. */
  17. #ifndef UA_malloc
  18. void* UA_malloc(size_t size); //allocate memory in the heap with size bytes
  19. #endif
  20. #ifndef UA_calloc
  21. void* UA_calloc(size_t num, size_t size); //allocate memory in the heap with size*num bytes and set the memory to zero
  22. #endif
  23. #ifndef UA_realloc
  24. void* UA_realloc(void *ptr, size_t new_size);//re-allocate memory in the heap with new_size bytes from previously allocated memory ptr
  25. #endif
  26. #ifndef UA_free
  27. void UA_free(void* ptr); //de-allocate memory previously allocated with UA_malloc, UA_calloc or UA_realloc
  28. #endif
  29. #ifndef UA_alloca
  30. # if defined(__GNUC__) || defined(__clang__)
  31. # define UA_alloca(size) __builtin_alloca (size)
  32. # elif defined(_WIN32)
  33. # define UA_alloca(SIZE) _alloca(SIZE)
  34. # else
  35. # include <alloca.h>
  36. # define UA_alloca(SIZE) alloca(SIZE)
  37. # endif
  38. #endif
  39. #ifndef UA_STACKARRAY
  40. /* Stack-allocation of memory. Use C99 variable-length arrays if possible.
  41. * Otherwise revert to alloca. Note that alloca is not supported on some
  42. * plattforms. */
  43. # if defined(__GNUC__) || defined(__clang__)
  44. # define UA_STACKARRAY(TYPE, NAME, SIZE) TYPE NAME[SIZE]
  45. # else
  46. # define UA_STACKARRAY(TYPE, NAME, SIZE) \
  47. TYPE *NAME = (TYPE*)UA_alloca(sizeof(TYPE) * SIZE)
  48. # endif
  49. #endif
  50. /*
  51. * Sleep function
  52. */
  53. #ifndef UA_sleep_ms
  54. int UA_sleep_ms(unsigned int miliSeconds); //suspend the thread for a certain amount of mili seconds
  55. #endif
  56. /*
  57. * Socket functions
  58. */
  59. #ifndef UA_send
  60. ssize_t UA_send(UA_SOCKET sockfd, const void *buf, size_t len, int flags); //equivalent to posix send implementation
  61. #endif
  62. #ifndef UA_sendto
  63. ssize_t sendto(UA_SOCKET sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); //equivalent to posix sendto implementation
  64. #endif
  65. #ifndef UA_select
  66. int UA_select(UA_SOCKET nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); //equivalent to posix select implementation
  67. #endif
  68. #ifndef UA_recv
  69. ssize_t UA_recv(UA_SOCKET sockfd, void *buf, size_t len, int flags); //equivalent to posix recv implementation
  70. #endif
  71. #ifndef UA_recvfrom
  72. ssize_t recvfrom(UA_SOCKET sockfd, void *buf, size_t len, int flags, struct sockaddr *src_addr, socklen_t *addrlen);
  73. #endif
  74. #ifndef UA_shutdown
  75. int UA_shutdown(UA_SOCKET sockfd, int how); //equivalent to posix shutdown implementation
  76. #endif
  77. #ifndef UA_socket
  78. UA_SOCKET UA_socket(int domain, int type, int protocol);//equivalent to posix socket implementation
  79. #endif
  80. #ifndef UA_bind
  81. int UA_bind(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);//equivalent to posix bind implementation
  82. #endif
  83. #ifndef UA_listen
  84. int UA_listen(UA_SOCKET sockfd, int backlog);//equivalent to posix listen implementation
  85. #endif
  86. #ifndef UA_accept
  87. int UA_accept(UA_SOCKET sockfd, struct sockaddr *addr, socklen_t *addrlen);//equivalent to posix accept implementation
  88. #endif
  89. #ifndef UA_close
  90. int UA_close(UA_SOCKET sockfd);//equivalent to posix close implementation
  91. #endif
  92. #ifndef UA_connect
  93. int UA_connect(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);//equivalent to posix connect implementation
  94. #endif
  95. #ifndef UA_fd_set
  96. void UA_fd_set(UA_SOCKET fd, fd_set *set); //equivalent to posix FD_SET implementation
  97. #endif
  98. #ifndef UA_fd_isset
  99. int UA_fd_isset(UA_SOCKET fd, fd_set *set);//equivalent to posix FD_ISSET implementation
  100. #endif
  101. #ifndef UA_getaddrinfo
  102. int UA_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);//equivalent to posix getaddrinfo implementation
  103. #endif
  104. #ifndef UA_htonl
  105. uint32_t UA_htonl(uint32_t hostlong);//equivalent to posix UA_htonl implementation
  106. #endif
  107. #ifndef UA_ntohl
  108. uint32_t UA_ntohl(uint32_t netlong);//equivalent to posix ntohl implementation
  109. #endif
  110. #ifndef UA_inet_pton
  111. int UA_inet_pton(int af, const char *src, void *dst);//equivalent to ANSI inet_pton implementation
  112. #endif
  113. #if UA_IPV6
  114. # ifndef UA_if_nametoindex
  115. unsigned int UA_if_nametoindex(const char *ifname);//equivalent to posix if_nametoindex implementation
  116. # endif
  117. #endif
  118. #ifndef UA_socket_set_blocking
  119. unsigned int UA_socket_set_blocking(UA_SOCKET sockfd);//set a socket as blocking. Returns 0 if OK, other value otherwise
  120. #endif
  121. #ifndef UA_socket_set_nonblocking
  122. unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd);//set a socket as non-blocking. Returns 0 if OK, other value otherwise
  123. #endif
  124. #ifndef UA_getsockopt
  125. int UA_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); //equivalent to posix getsockopt implementation. Only in non windows architectures
  126. #endif
  127. #ifndef UA_setsockopt
  128. int UA_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);//equivalent to posix setsockopt implementation
  129. #endif
  130. #ifndef UA_freeaddrinfo
  131. void UA_freeaddrinfo(struct addrinfo *res);//equivalent to posix freeaddrinfo implementatio
  132. #endif
  133. #ifndef UA_gethostname
  134. int UA_gethostname(char *name, size_t len);//equivalent to posix gethostname implementatio
  135. #endif
  136. #ifndef UA_initialize_architecture_network
  137. void UA_initialize_architecture_network(void);//initializes all needed for using the network interfaces
  138. #endif
  139. #ifndef UA_deinitialize_architecture_network
  140. void UA_deinitialize_architecture_network(void);//de-initializes the network interfaces
  141. #endif
  142. /*
  143. * Print function
  144. */
  145. #ifndef UA_snprintf
  146. int UA_snprintf(char* pa_stream, size_t pa_size, const char* pa_format, ...); //prints text to output
  147. #endif
  148. /*
  149. * Access to file function
  150. */
  151. #ifndef UA_access
  152. int UA_access(const char *pathname, int mode); //equivalent implementation of https://linux.die.net/man/2/access
  153. #endif
  154. #ifndef UA_fileExists
  155. #define UA_fileExists(X) ( UA_access(X, 0) == 0)
  156. #endif
  157. #include "ua_architecture_definitions.h"
  158. _UA_END_DECLS
  159. #endif /* PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_ */