123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- /*
- * Copyright (C) 2013-2015 the contributors as stated in the AUTHORS file
- *
- * This file is part of open62541. open62541 is free software: you can
- * redistribute it and/or modify it under the terms of the GNU Lesser General
- * Public License, version 3 (as published by the Free Software Foundation) with
- * a static linking exception as stated in the LICENSE file provided with
- * open62541.
- *
- * open62541 is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
- * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
- * details.
- */
- #ifndef UA_CONFIG_H_
- #define UA_CONFIG_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
- /**
- * Library Version
- * --------------- */
- #define UA_GIT_COMMIT_ID "${GIT_COMMIT_ID}"
- /**
- * Options
- * ------- */
- #define UA_LOGLEVEL ${UA_LOGLEVEL}
- #cmakedefine UA_ENABLE_METHODCALLS
- #cmakedefine UA_ENABLE_NODEMANAGEMENT
- #cmakedefine UA_ENABLE_SUBSCRIPTIONS
- #cmakedefine UA_ENABLE_MULTITHREADING
- /**
- * Advanced Options
- * ---------------- */
- #cmakedefine UA_ENABLE_STATUSCODE_DESCRIPTIONS
- #cmakedefine UA_ENABLE_TYPENAMES
- #cmakedefine UA_ENABLE_EMBEDDED_LIBC
- #cmakedefine UA_ENABLE_GENERATE_NAMESPACE0
- #cmakedefine UA_ENABLE_EXTERNAL_NAMESPACES
- #cmakedefine UA_ENABLE_NONSTANDARD_STATELESS
- #cmakedefine UA_ENABLE_NONSTANDARD_UDP
- /**
- * Standard Includes
- * ----------------- */
- #ifndef _XOPEN_SOURCE
- # define _XOPEN_SOURCE 500
- #endif
- #ifndef _DEFAULT_SOURCE
- # define _DEFAULT_SOURCE
- #endif
- #include <stddef.h>
- #include <stdint.h>
- /**
- * Function Export
- * ---------------
- * On Win32: Define ``UA_DYNAMIC_LINKING`` and ``UA_DYNAMIC_LINKING_EXPORT`` in
- * order to export symbols for a DLL. Define ``UA_DYNAMIC_LINKING`` only to
- * import symbols from a DLL.*/
- #cmakedefine UA_DYNAMIC_LINKING
- #if defined(_WIN32) && defined(UA_DYNAMIC_LINKING)
- # ifdef UA_DYNAMIC_LINKING_EXPORT /* export dll */
- # ifdef __GNUC__
- # define UA_EXPORT __attribute__ ((dllexport))
- # else
- # define UA_EXPORT __declspec(dllexport)
- # endif
- # else /* import dll */
- # ifdef __GNUC__
- # define UA_EXPORT __attribute__ ((dllimport))
- # else
- # define UA_EXPORT __declspec(dllimport)
- # endif
- # endif
- #else /* non win32 */
- # if __GNUC__ || __clang__
- # define UA_EXPORT __attribute__ ((visibility ("default")))
- # endif
- #endif
- #ifndef UA_EXPORT
- # define UA_EXPORT /* fallback to default */
- #endif
- /**
- * Inline Functions
- * ---------------- */
- #ifdef _MSC_VER
- # define UA_INLINE __inline
- #else
- # define UA_INLINE inline
- #endif
- /**
- * Non-aliasing pointers
- * -------------------- */
- #ifdef _MSC_VER
- # define UA_RESTRICT __restrict
- #elif defined(__GNUC__)
- # define UA_RESTRICT __restrict__
- #else
- # define UA_RESTRICT restrict
- #endif
- /**
- * Function attributes
- * ------------------- */
- #ifdef __GNUC__
- # define UA_FUNC_ATTR_MALLOC __attribute__((malloc))
- # define UA_FUNC_ATTR_PURE __attribute__ ((pure))
- # define UA_FUNC_ATTR_CONST __attribute__((const))
- # define UA_FUNC_ATTR_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
- #else
- # define UA_FUNC_ATTR_MALLOC
- # define UA_FUNC_ATTR_PURE
- # define UA_FUNC_ATTR_CONST
- # define UA_FUNC_ATTR_WARN_UNUSED_RESULT
- #endif
- /**
- * Memory Management
- * -----------------
- * Replace the macros for custom memory allocators if necessary */
- #include <stdlib.h>
- #ifdef _WIN32
- # ifndef __clang__
- # include <malloc.h>
- # endif
- #endif
- #define UA_free(ptr) free(ptr)
- #define UA_malloc(size) malloc(size)
- #define UA_calloc(num, size) calloc(num, size)
- #define UA_realloc(ptr, size) realloc(ptr, size)
- #ifndef NO_ALLOCA
- # if defined(__GNUC__) || defined(__clang__)
- # define UA_alloca(size) __builtin_alloca (size)
- # elif defined(_WIN32)
- # define UA_alloca(SIZE) _alloca(SIZE)
- # else
- # include <alloca.h>
- # define UA_alloca(SIZE) alloca(SIZE)
- # endif
- #endif
- /**
- * Atomic Operations
- * -----------------
- * Atomic operations that synchronize across processor cores (for
- * multithreading). Only the inline-functions defined next are used. Replace
- * with architecture-specific operations if necessary. */
- #ifndef UA_ENABLE_MULTITHREADING
- # define UA_atomic_sync()
- #else
- # ifdef _MSC_VER /* Visual Studio */
- # define UA_atomic_sync() _ReadWriteBarrier()
- # else /* GCC/Clang */
- # define UA_atomic_sync() __sync_synchronize()
- # endif
- #endif
- static UA_INLINE void *
- UA_atomic_xchg(void * volatile * addr, void *newptr) {
- #ifndef UA_ENABLE_MULTITHREADING
- void *old = *addr;
- *addr = newptr;
- return old;
- #else
- # ifdef _MSC_VER /* Visual Studio */
- return _InterlockedExchangePointer(addr, newptr);
- # else /* GCC/Clang */
- return __sync_lock_test_and_set(addr, newptr);
- # endif
- #endif
- }
- static UA_INLINE void *
- UA_atomic_cmpxchg(void * volatile * addr, void *expected, void *newptr) {
- #ifndef UA_ENABLE_MULTITHREADING
- void *old = *addr;
- if(old == expected) {
- *addr = newptr;
- }
- return old;
- #else
- # ifdef _MSC_VER /* Visual Studio */
- return _InterlockedCompareExchangePointer(addr, expected, newptr);
- # else /* GCC/Clang */
- return __sync_val_compare_and_swap(addr, expected, newptr);
- # endif
- #endif
- }
- static UA_INLINE uint32_t
- UA_atomic_add(volatile uint32_t *addr, uint32_t increase) {
- #ifndef UA_ENABLE_MULTITHREADING
- *addr += increase;
- return *addr;
- #else
- # ifdef _MSC_VER /* Visual Studio */
- return _InterlockedExchangeAdd(addr, increase) + increase;
- # else /* GCC/Clang */
- return __sync_add_and_fetch(addr, increase);
- # endif
- #endif
- }
- /**
- * Binary Encoding Overlays
- * ------------------------
- * Integers and floating point numbers are transmitted in little-endian (IEE 754
- * for floating point) encoding. If the target architecture uses the same
- * format, numeral datatypes can be memcpy'd (overlayed) on the binary stream.
- * This speeds up encoding.
- *
- * Integer Endianness
- * ^^^^^^^^^^^^^^^^^^ */
- #if defined(_WIN32) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
- (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)) /* little endian detected */
- # define UA_BINARY_OVERLAYABLE_INTEGER true
- #elif defined(__ANDROID__) /* Andoid */
- # include <endian.h>
- # if __BYTE_ORDER == __LITTLE_ENDIAN
- # define UA_BINARY_OVERLAYABLE_INTEGER true
- # endif
- #elif defined(__linux__) /* Linux */
- # include <endian.h>
- # if __BYTE_ORDER == __LITTLE_ENDIAN
- # define UA_BINARY_OVERLAYABLE_INTEGER true
- # endif
- # if __FLOAT_BYTE_ORDER == __LITTLE_ENDIAN
- # define UA_BINARY_OVERLAYABLE_FLOAT true
- # endif
- #elif defined(__OpenBSD__) /* OpenBSD */
- # include <sys/endian.h>
- # if BYTE_ORDER == LITTLE_ENDIAN
- # define UA_BINARY_OVERLAYABLE_INTEGER true
- # endif
- #elif defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__) /* Other BSD */
- # include <sys/endian.h>
- # if _BYTE_ORDER == _LITTLE_ENDIAN
- # define UA_BINARY_OVERLAYABLE_INTEGER true
- # endif
- #elif defined(__APPLE__) /* Apple (MacOS, iOS) */
- # include <libkern/OSByteOrder.h>
- # if defined(__LITTLE_ENDIAN__)
- # define UA_BINARY_OVERLAYABLE_INTEGER true
- # endif
- #elif defined(__QNX__) || defined(__QNXNTO__) /* QNX */
- # include <gulliver.h>
- # if defined(__LITTLEENDIAN__)
- # define UA_BINARY_OVERLAYABLE_INTEGER true
- # endif
- #endif
- #ifndef UA_BINARY_OVERLAYABLE_INTEGER
- # define UA_BINARY_OVERLAYABLE_INTEGER false
- #endif
- /**
- * Float Endianness
- * ^^^^^^^^^^^^^^^^ */
- #if defined(_WIN32)
- # define UA_BINARY_OVERLAYABLE_FLOAT true
- #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && \
- (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__) /* Defined only in GCC */
- # define UA_BINARY_OVERLAYABLE_FLOAT true
- #elif defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && \
- (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) /* Defined only in GCC */
- # define UA_BINARY_OVERLAYABLE_FLOAT true
- #endif
- #ifndef UA_BINARY_OVERLAYABLE_FLOAT
- # define UA_BINARY_OVERLAYABLE_FLOAT false
- #endif
- /**
- * Embed unavailable libc functions
- * -------------------------------- */
- #ifdef UA_ENABLE_EMBEDDED_LIBC
- void *memcpy(void *UA_RESTRICT dest, const void *UA_RESTRICT src, size_t n);
- void *memset(void *dest, int c, size_t n);
- size_t strlen(const char *s);
- int memcmp(const void *vl, const void *vr, size_t n);
- #else
- # include <string.h>
- #endif
- #ifdef __cplusplus
- } // extern "C"
- #endif
- #endif /* UA_CONFIG_H_ */
|