ua_architecture_functions.h 6.3 KB

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