ua_architecture_functions.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_select
  65. int UA_select(UA_SOCKET nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); //equivalent to posix select implementation
  66. #endif
  67. #ifndef UA_recv
  68. ssize_t UA_recv(UA_SOCKET sockfd, void *buf, size_t len, int flags); //equivalent to posix recv implementation
  69. #endif
  70. #ifndef UA_shutdown
  71. int UA_shutdown(UA_SOCKET sockfd, int how); //equivalent to posix shutdown implementation
  72. #endif
  73. #ifndef UA_socket
  74. UA_SOCKET UA_socket(int domain, int type, int protocol);//equivalent to posix socket implementation
  75. #endif
  76. #ifndef UA_bind
  77. int UA_bind(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);//equivalent to posix bind implementation
  78. #endif
  79. #ifndef UA_listen
  80. int UA_listen(UA_SOCKET sockfd, int backlog);//equivalent to posix listen implementation
  81. #endif
  82. #ifndef UA_accept
  83. int UA_accept(UA_SOCKET sockfd, struct sockaddr *addr, socklen_t *addrlen);//equivalent to posix accept implementation
  84. #endif
  85. #ifndef UA_close
  86. int UA_close(UA_SOCKET sockfd);//equivalent to posix close implementation
  87. #endif
  88. #ifndef UA_connect
  89. int UA_connect(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);//equivalent to posix connect implementation
  90. #endif
  91. #ifndef UA_fd_set
  92. void UA_fd_set(UA_SOCKET fd, fd_set *set); //equivalent to posix FD_SET implementation
  93. #endif
  94. #ifndef UA_fd_isset
  95. int UA_fd_isset(UA_SOCKET fd, fd_set *set);//equivalent to posix FD_ISSET implementation
  96. #endif
  97. #ifndef UA_getaddrinfo
  98. int UA_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);//equivalent to posix getaddrinfo implementation
  99. #endif
  100. #ifndef UA_socket_set_blocking
  101. unsigned int UA_socket_set_blocking(UA_SOCKET sockfd);//set a socket as blocking. Returns 0 if OK, other value otherwise
  102. #endif
  103. #ifndef UA_socket_set_nonblocking
  104. unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd);//set a socket as non-blocking. Returns 0 if OK, other value otherwise
  105. #endif
  106. #ifndef UA_getsockopt
  107. int UA_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); //equivalent to posix getsockopt implementation. Only in non windows architectures
  108. #endif
  109. #ifndef UA_setsockopt
  110. int UA_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);//equivalent to posix setsockopt implementation
  111. #endif
  112. #ifndef UA_freeaddrinfo
  113. void UA_freeaddrinfo(struct addrinfo *res);//equivalent to posix freeaddrinfo implementatio
  114. #endif
  115. #ifndef UA_gethostname
  116. int UA_gethostname(char *name, size_t len);//equivalent to posix gethostname implementatio
  117. #endif
  118. #ifndef UA_initialize_architecture_network
  119. void UA_initialize_architecture_network(void);//initializes all needed for using the network interfaces
  120. #endif
  121. #ifndef UA_deinitialize_architecture_network
  122. void UA_deinitialize_architecture_network(void);//de-initializes the network interfaces
  123. #endif
  124. /*
  125. * Print function
  126. */
  127. #ifndef UA_snprintf
  128. int UA_snprintf(char* pa_stream, size_t pa_size, const char* pa_format, ...); //prints text to output
  129. #endif
  130. /*
  131. * Access to file function
  132. */
  133. #ifndef UA_access
  134. int UA_access(const char *pathname, int mode); //equivalent implementation of https://linux.die.net/man/2/access
  135. #endif
  136. #ifdef __cplusplus
  137. }
  138. #endif
  139. #endif /* PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_ */