ua_config.h.in 8.1 KB

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