ua_architecture_functions.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /**
  32. * Memory Management
  33. * -----------------
  34. * The default is to use the malloc implementation from ``stdlib.h``. Override
  35. * if required. Changing the settings has no effect on a pre-compiled
  36. * library. */
  37. #ifndef UA_alloca
  38. # if defined(__GNUC__) || defined(__clang__)
  39. # define UA_alloca(size) __builtin_alloca (size)
  40. # elif defined(_WIN32)
  41. # define UA_alloca(SIZE) _alloca(SIZE)
  42. # else
  43. # include <alloca.h>
  44. # define UA_alloca(SIZE) alloca(SIZE)
  45. # endif
  46. #endif
  47. #ifndef UA_STACKARRAY
  48. /* Stack-allocation of memory. Use C99 variable-length arrays if possible.
  49. * Otherwise revert to alloca. Note that alloca is not supported on some
  50. * plattforms. */
  51. # if defined(__GNUC__) || defined(__clang__)
  52. # define UA_STACKARRAY(TYPE, NAME, SIZE) TYPE NAME[SIZE]
  53. # else
  54. # define UA_STACKARRAY(TYPE, NAME, SIZE) \
  55. TYPE *NAME = (TYPE*)UA_alloca(sizeof(TYPE) * SIZE)
  56. # endif
  57. #endif
  58. /*
  59. * Sleep function
  60. */
  61. #ifndef UA_sleep_ms
  62. int UA_sleep_ms(unsigned int miliSeconds); //suspend the thread for a certain amount of mili seconds
  63. #endif
  64. /*
  65. * Socket functions
  66. */
  67. #ifndef UA_send
  68. ssize_t UA_send(UA_SOCKET sockfd, const void *buf, size_t len, int flags); //equivalent to posix send implementation
  69. #endif
  70. #ifndef UA_select
  71. int UA_select(UA_SOCKET nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); //equivalent to posix select implementation
  72. #endif
  73. #ifndef UA_recv
  74. ssize_t UA_recv(UA_SOCKET sockfd, void *buf, size_t len, int flags); //equivalent to posix recv implementation
  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_socket_set_blocking
  107. unsigned int UA_socket_set_blocking(UA_SOCKET sockfd);//set a socket as blocking. Returns 0 if OK, other value otherwise
  108. #endif
  109. #ifndef UA_socket_set_nonblocking
  110. unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd);//set a socket as non-blocking. Returns 0 if OK, other value otherwise
  111. #endif
  112. #ifndef UA_getsockopt
  113. int UA_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); //equivalent to posix getsockopt implementation. Only in non windows architectures
  114. #endif
  115. #ifndef UA_setsockopt
  116. int UA_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);//equivalent to posix setsockopt implementation
  117. #endif
  118. #ifndef UA_freeaddrinfo
  119. void UA_freeaddrinfo(struct addrinfo *res);//equivalent to posix freeaddrinfo implementatio
  120. #endif
  121. #ifndef UA_gethostname
  122. int UA_gethostname(char *name, size_t len);//equivalent to posix gethostname implementatio
  123. #endif
  124. #ifndef UA_initialize_architecture_network
  125. void UA_initialize_architecture_network(void);//initializes all needed for using the network interfaces
  126. #endif
  127. #ifndef UA_deinitialize_architecture_network
  128. void UA_deinitialize_architecture_network(void);//de-initializes the network interfaces
  129. #endif
  130. /*
  131. * Print function
  132. */
  133. #ifndef UA_snprintf
  134. int UA_snprintf(char* pa_stream, size_t pa_size, const char* pa_format, ...); //prints text to output
  135. #endif
  136. /*
  137. * Access to file function
  138. */
  139. #ifndef UA_access
  140. int UA_access(const char *pathname, int mode); //equivalent implementation of https://linux.die.net/man/2/access
  141. #endif
  142. #ifdef __cplusplus
  143. }
  144. #endif
  145. #endif /* PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_ */