ua_config.h.in 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /*
  2. * Copyright (C) 2013-2015 the contributors as stated in the AUTHORS file
  3. *
  4. * This file is part of open62541. open62541 is free software: you can
  5. * redistribute it and/or modify it under the terms of the GNU Lesser General
  6. * Public License, version 3 (as published by the Free Software Foundation) with
  7. * a static linking exception as stated in the LICENSE file provided with
  8. * open62541.
  9. *
  10. * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
  11. * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  13. * details.
  14. */
  15. #ifndef UA_CONFIG_H_
  16. #define UA_CONFIG_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * Library Version
  22. * --------------- */
  23. #define UA_GIT_COMMIT_ID "${GIT_COMMIT_ID}"
  24. /**
  25. * Options
  26. * ------- */
  27. #define UA_LOGLEVEL ${UA_LOGLEVEL}
  28. #cmakedefine UA_ENABLE_METHODCALLS
  29. #cmakedefine UA_ENABLE_NODEMANAGEMENT
  30. #cmakedefine UA_ENABLE_SUBSCRIPTIONS
  31. #cmakedefine UA_ENABLE_DISCOVERY
  32. #cmakedefine UA_ENABLE_MULTITHREADING
  33. /**
  34. * Advanced Options
  35. * ---------------- */
  36. #cmakedefine UA_ENABLE_STATUSCODE_DESCRIPTIONS
  37. #cmakedefine UA_ENABLE_TYPENAMES
  38. #cmakedefine UA_ENABLE_EMBEDDED_LIBC
  39. #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
  40. #cmakedefine UA_ENABLE_EXTERNAL_NAMESPACES
  41. #cmakedefine UA_ENABLE_NONSTANDARD_STATELESS
  42. #cmakedefine UA_ENABLE_NONSTANDARD_UDP
  43. /**
  44. * Standard Includes
  45. * ----------------- */
  46. #ifndef _XOPEN_SOURCE
  47. # define _XOPEN_SOURCE 500
  48. #endif
  49. #ifndef _DEFAULT_SOURCE
  50. # define _DEFAULT_SOURCE
  51. #endif
  52. #include <stddef.h>
  53. #include <stdint.h>
  54. /**
  55. * Function Export
  56. * ---------------
  57. * On Win32: Define ``UA_DYNAMIC_LINKING`` and ``UA_DYNAMIC_LINKING_EXPORT`` in
  58. * order to export symbols for a DLL. Define ``UA_DYNAMIC_LINKING`` only to
  59. * import symbols from a DLL.*/
  60. #cmakedefine UA_DYNAMIC_LINKING
  61. #if defined(_WIN32) && defined(UA_DYNAMIC_LINKING)
  62. # ifdef UA_DYNAMIC_LINKING_EXPORT /* export dll */
  63. # ifdef __GNUC__
  64. # define UA_EXPORT __attribute__ ((dllexport))
  65. # else
  66. # define UA_EXPORT __declspec(dllexport)
  67. # endif
  68. # else /* import dll */
  69. # ifdef __GNUC__
  70. # define UA_EXPORT __attribute__ ((dllimport))
  71. # else
  72. # define UA_EXPORT __declspec(dllimport)
  73. # endif
  74. # endif
  75. #else /* non win32 */
  76. # if __GNUC__ || __clang__
  77. # define UA_EXPORT __attribute__ ((visibility ("default")))
  78. # endif
  79. #endif
  80. #ifndef UA_EXPORT
  81. # define UA_EXPORT /* fallback to default */
  82. #endif
  83. /**
  84. * Inline Functions
  85. * ---------------- */
  86. #ifdef _MSC_VER
  87. # define UA_INLINE __inline
  88. #else
  89. # define UA_INLINE inline
  90. #endif
  91. /**
  92. * Non-aliasing pointers
  93. * -------------------- */
  94. #ifdef _MSC_VER
  95. # define UA_RESTRICT __restrict
  96. #elif defined(__GNUC__)
  97. # define UA_RESTRICT __restrict__
  98. #else
  99. # define UA_RESTRICT restrict
  100. #endif
  101. /**
  102. * Function attributes
  103. * ------------------- */
  104. #ifdef __GNUC__
  105. # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
  106. # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
  107. # define UA_FUNC_ATTR_CONST __attribute__((const))
  108. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
  109. #else
  110. # define UA_FUNC_ATTR_MALLOC
  111. # define UA_FUNC_ATTR_PURE
  112. # define UA_FUNC_ATTR_CONST
  113. # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
  114. #endif
  115. /**
  116. * Memory Management
  117. * -----------------
  118. * Replace the macros for custom memory allocators if necessary */
  119. #include <stdlib.h>
  120. #ifdef _WIN32
  121. # ifndef __clang__
  122. # include <malloc.h>
  123. # endif
  124. #endif
  125. #define UA_free(ptr) free(ptr)
  126. #define UA_malloc(size) malloc(size)
  127. #define UA_calloc(num, size) calloc(num, size)
  128. #define UA_realloc(ptr, size) realloc(ptr, size)
  129. #ifndef NO_ALLOCA
  130. # if defined(__GNUC__) || defined(__clang__)
  131. # define UA_alloca(size) __builtin_alloca (size)
  132. # elif defined(_WIN32)
  133. # define UA_alloca(SIZE) _alloca(SIZE)
  134. # else
  135. # include <alloca.h>
  136. # define UA_alloca(SIZE) alloca(SIZE)
  137. # endif
  138. #endif
  139. /**
  140. * Atomic Operations
  141. * -----------------
  142. * Atomic operations that synchronize across processor cores (for
  143. * multithreading). Only the inline-functions defined next are used. Replace
  144. * with architecture-specific operations if necessary. */
  145. #ifndef UA_ENABLE_MULTITHREADING
  146. # define UA_atomic_sync()
  147. #else
  148. # ifdef _MSC_VER /* Visual Studio */
  149. # define UA_atomic_sync() _ReadWriteBarrier()
  150. # else /* GCC/Clang */
  151. # define UA_atomic_sync() __sync_synchronize()
  152. # endif
  153. #endif
  154. static UA_INLINE void *
  155. UA_atomic_xchg(void * volatile * addr, void *newptr) {
  156. #ifndef UA_ENABLE_MULTITHREADING
  157. void *old = *addr;
  158. *addr = newptr;
  159. return old;
  160. #else
  161. # ifdef _MSC_VER /* Visual Studio */
  162. return _InterlockedExchangePointer(addr, newptr);
  163. # else /* GCC/Clang */
  164. return __sync_lock_test_and_set(addr, newptr);
  165. # endif
  166. #endif
  167. }
  168. static UA_INLINE void *
  169. UA_atomic_cmpxchg(void * volatile * addr, void *expected, void *newptr) {
  170. #ifndef UA_ENABLE_MULTITHREADING
  171. void *old = *addr;
  172. if(old == expected) {
  173. *addr = newptr;
  174. }
  175. return old;
  176. #else
  177. # ifdef _MSC_VER /* Visual Studio */
  178. return _InterlockedCompareExchangePointer(addr, expected, newptr);
  179. # else /* GCC/Clang */
  180. return __sync_val_compare_and_swap(addr, expected, newptr);
  181. # endif
  182. #endif
  183. }
  184. static UA_INLINE uint32_t
  185. UA_atomic_add(volatile uint32_t *addr, uint32_t increase) {
  186. #ifndef UA_ENABLE_MULTITHREADING
  187. *addr += increase;
  188. return *addr;
  189. #else
  190. # ifdef _MSC_VER /* Visual Studio */
  191. return _InterlockedExchangeAdd(addr, increase) + increase;
  192. # else /* GCC/Clang */
  193. return __sync_add_and_fetch(addr, increase);
  194. # endif
  195. #endif
  196. }
  197. /**
  198. * Binary Encoding Overlays
  199. * ------------------------
  200. * Integers and floating point numbers are transmitted in little-endian (IEE 754
  201. * for floating point) encoding. If the target architecture uses the same
  202. * format, numeral datatypes can be memcpy'd (overlayed) on the binary stream.
  203. * This speeds up encoding.
  204. *
  205. * Integer Endianness
  206. * ^^^^^^^^^^^^^^^^^^ */
  207. #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  208. (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) /* little endian detected */
  209. # define UA_BINARY_OVERLAYABLE_INTEGER true
  210. #elif defined(__ANDROID__) /* Andoid */
  211. # include <endian.h>
  212. # if __BYTE_ORDER == __LITTLE_ENDIAN
  213. # define UA_BINARY_OVERLAYABLE_INTEGER true
  214. # endif
  215. #elif defined(__linux__) /* Linux */
  216. # include <endian.h>
  217. # if __BYTE_ORDER == __LITTLE_ENDIAN
  218. # define UA_BINARY_OVERLAYABLE_INTEGER true
  219. # endif
  220. # if __FLOAT_BYTE_ORDER == __LITTLE_ENDIAN
  221. # define UA_BINARY_OVERLAYABLE_FLOAT true
  222. # endif
  223. #elif defined(__OpenBSD__) /* OpenBSD */
  224. # include <sys/endian.h>
  225. # if BYTE_ORDER == LITTLE_ENDIAN
  226. # define UA_BINARY_OVERLAYABLE_INTEGER true
  227. # endif
  228. #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
  229. # include <sys/endian.h>
  230. # if _BYTE_ORDER == _LITTLE_ENDIAN
  231. # define UA_BINARY_OVERLAYABLE_INTEGER true
  232. # endif
  233. #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
  234. # include <libkern/OSByteOrder.h>
  235. # if defined(__LITTLE_ENDIAN__)
  236. # define UA_BINARY_OVERLAYABLE_INTEGER true
  237. # endif
  238. #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
  239. # include <gulliver.h>
  240. # if defined(__LITTLEENDIAN__)
  241. # define UA_BINARY_OVERLAYABLE_INTEGER true
  242. # endif
  243. #endif
  244. #ifndef UA_BINARY_OVERLAYABLE_INTEGER
  245. # define UA_BINARY_OVERLAYABLE_INTEGER false
  246. #endif
  247. /**
  248. * Float Endianness
  249. * ^^^^^^^^^^^^^^^^ */
  250. #if defined(_WIN32)
  251. # define UA_BINARY_OVERLAYABLE_FLOAT true
  252. #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
  253. (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
  254. # define UA_BINARY_OVERLAYABLE_FLOAT true
  255. #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
  256. (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
  257. # define UA_BINARY_OVERLAYABLE_FLOAT true
  258. #endif
  259. #ifndef UA_BINARY_OVERLAYABLE_FLOAT
  260. # define UA_BINARY_OVERLAYABLE_FLOAT false
  261. #endif
  262. /**
  263. * Embed unavailable libc functions
  264. * -------------------------------- */
  265. #ifdef UA_ENABLE_EMBEDDED_LIBC
  266. void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
  267. void *memset(void *dest, int c, size_t n);
  268. size_t strlen(const char *s);
  269. int memcmp(const void *vl, const void *vr, size_t n);
  270. #else
  271. # include <string.h>
  272. #endif
  273. #ifdef __cplusplus
  274. } // extern "C"
  275. #endif
  276. #endif /* UA_CONFIG_H_ */