ua_architecture_functions.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. * Sleep function
  33. */
  34. #ifndef UA_sleep_ms
  35. int UA_sleep_ms(unsigned int miliSeconds); //suspend the thread for a certain amount of mili seconds
  36. #endif
  37. /*
  38. * Socket functions
  39. */
  40. #ifndef UA_send
  41. ssize_t UA_send(UA_SOCKET sockfd, const void *buf, size_t len, int flags); //equivalent to posix send implementation
  42. #endif
  43. #ifndef UA_select
  44. int UA_select(UA_SOCKET nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); //equivalent to posix select implementation
  45. #endif
  46. #ifndef UA_recv
  47. ssize_t UA_recv(UA_SOCKET sockfd, void *buf, size_t len, int flags); //equivalent to posix recv implementation
  48. #endif
  49. #ifndef UA_shutdown
  50. int UA_shutdown(UA_SOCKET sockfd, int how); //equivalent to posix shutdown implementation
  51. #endif
  52. #ifndef UA_socket
  53. UA_SOCKET UA_socket(int domain, int type, int protocol);//equivalent to posix socket implementation
  54. #endif
  55. #ifndef UA_bind
  56. int UA_bind(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);//equivalent to posix bind implementation
  57. #endif
  58. #ifndef UA_listen
  59. int UA_listen(UA_SOCKET sockfd, int backlog);//equivalent to posix listen implementation
  60. #endif
  61. #ifndef UA_accept
  62. int UA_accept(UA_SOCKET sockfd, struct sockaddr *addr, socklen_t *addrlen);//equivalent to posix accept implementation
  63. #endif
  64. #ifndef UA_close
  65. int UA_close(UA_SOCKET sockfd);//equivalent to posix close implementation
  66. #endif
  67. #ifndef UA_connect
  68. int UA_connect(UA_SOCKET sockfd, const struct sockaddr *addr, socklen_t addrlen);//equivalent to posix connect implementation
  69. #endif
  70. #ifndef UA_fd_set
  71. void UA_fd_set(UA_SOCKET fd, fd_set *set); //equivalent to posix FD_SET implementation
  72. #endif
  73. #ifndef UA_fd_isset
  74. int UA_fd_isset(UA_SOCKET fd, fd_set *set);//equivalent to posix FD_ISSET implementation
  75. #endif
  76. #ifndef UA_getaddrinfo
  77. int UA_getaddrinfo(const char *node, const char *service, const struct addrinfo *hints, struct addrinfo **res);//equivalent to posix getaddrinfo implementation
  78. #endif
  79. #ifndef UA_socket_set_blocking
  80. unsigned int UA_socket_set_blocking(UA_SOCKET sockfd);//set a socket as blocking. Returns 0 if OK, other value otherwise
  81. #endif
  82. #ifndef UA_socket_set_nonblocking
  83. unsigned int UA_socket_set_nonblocking(UA_SOCKET sockfd);//set a socket as non-blocking. Returns 0 if OK, other value otherwise
  84. #endif
  85. #ifndef UA_getsockopt
  86. int UA_getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); //equivalent to posix getsockopt implementation. Only in non windows architectures
  87. #endif
  88. #ifndef UA_setsockopt
  89. int UA_setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);//equivalent to posix setsockopt implementation
  90. #endif
  91. #ifndef UA_freeaddrinfo
  92. void UA_freeaddrinfo(struct addrinfo *res);//equivalent to posix freeaddrinfo implementatio
  93. #endif
  94. #ifndef UA_gethostname
  95. int UA_gethostname(char *name, size_t len);//equivalent to posix gethostname implementatio
  96. #endif
  97. #ifndef UA_initialize_architecture_network
  98. void UA_initialize_architecture_network(void);//initializes all needed for using the network interfaces
  99. #endif
  100. #ifndef UA_deinitialize_architecture_network
  101. void UA_deinitialize_architecture_network(void);//de-initializes the network interfaces
  102. #endif
  103. /*
  104. * Print function
  105. */
  106. #ifndef UA_snprintf
  107. int UA_snprintf(char* pa_stream, size_t pa_size, const char* pa_format, ...); //prints text to output
  108. #endif
  109. /*
  110. * Access to file function
  111. */
  112. #ifndef UA_access
  113. int UA_access(const char *pathname, int mode); //equivalent implementation of https://linux.die.net/man/2/access
  114. #endif
  115. #ifdef __cplusplus
  116. }
  117. #endif
  118. #endif /* PLUGINS_ARCH_UA_ARCHITECTURE_FUNCTIONS_H_ */