ua_types.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. /*
  2. * Copyright (C) 2014 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_TYPES_H_
  16. #define UA_TYPES_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #include <stdint.h>
  21. #include <stdbool.h>
  22. #include <stddef.h>
  23. #include "ua_config.h"
  24. /** @brief A two-state logical value (true or false). */
  25. typedef bool UA_Boolean;
  26. #define UA_TRUE true
  27. #define UA_FALSE false
  28. /** @brief An integer value between -129 and 127. */
  29. typedef int8_t UA_SByte;
  30. #define UA_SBYTE_MAX 127
  31. #define UA_SBYTE_MIN -128
  32. /** @brief An integer value between 0 and 256. */
  33. typedef uint8_t UA_Byte;
  34. #define UA_BYTE_MAX 256
  35. #define UA_BYTE_MIN 0
  36. /** @brief An integer value between -32 768 and 32 767. */
  37. typedef int16_t UA_Int16;
  38. #define UA_INT16_MAX 32767
  39. #define UA_INT16_MIN -32768
  40. /** @brief An integer value between 0 and 65 535. */
  41. typedef uint16_t UA_UInt16;
  42. #define UA_UINT16_MAX 65535
  43. #define UA_UINT16_MIN 0
  44. /** @brief An integer value between -2 147 483 648 and 2 147 483 647. */
  45. typedef int32_t UA_Int32;
  46. #define UA_INT32_MAX 2147483647
  47. #define UA_INT32_MIN -2147483648
  48. /** @brief An integer value between 0 and 429 4967 295. */
  49. typedef uint32_t UA_UInt32;
  50. #define UA_UINT32_MAX 4294967295
  51. #define UA_UINT32_MIN 0
  52. /** @brief An integer value between -10 223 372 036 854 775 808 and 9 223 372 036 854 775 807 */
  53. typedef int64_t UA_Int64;
  54. #define UA_INT64_MAX 9223372036854775807
  55. #define UA_INT64_MIN -9223372036854775808
  56. /** @brief An integer value between 0 and 18 446 744 073 709 551 615. */
  57. typedef uint64_t UA_UInt64;
  58. #define UA_UINT64_MAX = 18446744073709551615
  59. #define UA_UINT64_MIN = 0
  60. /** @brief An IEEE single precision (32 bit) floating point value. */
  61. typedef float UA_Float;
  62. /** @brief An IEEE double precision (64 bit) floating point value. */
  63. typedef double UA_Double;
  64. /** @brief A sequence of Unicode characters. */
  65. typedef struct {
  66. UA_Int32 length; ///< The length of the string
  67. UA_Byte *data; ///< The string's content (not null-terminated)
  68. } UA_String;
  69. /** @brief An instance in time.
  70. * A DateTime value is encoded as a 64-bit signed integer which represents the
  71. * number of 100 nanosecond intervals since January 1, 1601 (UTC).
  72. */
  73. typedef UA_Int64 UA_DateTime; // 100 nanosecond resolution
  74. /** @brief A 16 byte value that can be used as a globally unique identifier. */
  75. typedef struct {
  76. UA_UInt32 data1;
  77. UA_UInt16 data2;
  78. UA_UInt16 data3;
  79. UA_Byte data4[8];
  80. } UA_Guid;
  81. /** @brief A sequence of octets. */
  82. typedef UA_String UA_ByteString;
  83. /** @brief An XML element. */
  84. typedef UA_String UA_XmlElement;
  85. /** @brief An identifier for a node in the address space of an OPC UA Server. */
  86. /* The shortened numeric types are introduced during encoding. */
  87. typedef struct {
  88. UA_UInt16 namespaceIndex; ///< The namespace index of the node
  89. enum UA_NodeIdType {
  90. UA_NODEIDTYPE_NUMERIC = 2,
  91. UA_NODEIDTYPE_STRING = 3,
  92. UA_NODEIDTYPE_GUID = 4,
  93. UA_NODEIDTYPE_BYTESTRING = 5
  94. } identifierType; ///< The type of the node identifier
  95. union {
  96. UA_UInt32 numeric;
  97. UA_String string;
  98. UA_Guid guid;
  99. UA_ByteString byteString;
  100. } identifier; ///< The node identifier
  101. } UA_NodeId;
  102. /** @brief A NodeId that allows the namespace URI to be specified instead of an index. */
  103. typedef struct {
  104. UA_NodeId nodeId; ///< The nodeid without extensions
  105. UA_String namespaceUri; ///< The Uri of the namespace (tindex in the nodeId is ignored)
  106. UA_UInt32 serverIndex; ///< The index of the server
  107. } UA_ExpandedNodeId;
  108. #include "ua_statuscodes.h"
  109. /** @brief A numeric identifier for a error or condition that is associated with a value or an operation. */
  110. typedef enum UA_StatusCode UA_StatusCode; // StatusCodes aren't an enum(=int) since 32 unsigned bits are needed. See also ua_statuscodes.h */
  111. /** @brief A name qualified by a namespace. */
  112. typedef struct {
  113. UA_UInt16 namespaceIndex; ///< The namespace index
  114. UA_String name; ///< The actual name
  115. } UA_QualifiedName;
  116. /** @brief Human readable text with an optional locale identifier. */
  117. typedef struct {
  118. UA_String locale; ///< The locale (e.g. "en-US")
  119. UA_String text; ///< The actual text
  120. } UA_LocalizedText;
  121. /** @brief A structure that contains an application specific data type that may
  122. not be recognized by the receiver. */
  123. typedef struct {
  124. UA_NodeId typeId; ///< The nodeid of the datatype
  125. enum {
  126. UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED = 0,
  127. UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING = 1,
  128. UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISXML = 2
  129. } encoding; ///< The encoding of the contained data
  130. UA_ByteString body; ///< The bytestring of the encoded data
  131. } UA_ExtensionObject;
  132. struct UA_DataType;
  133. typedef struct UA_DataType UA_DataType;
  134. /** @brief Variants store (arrays of) any data type. Either they provide a pointer to the data in
  135. * memory, or functions from which the data can be accessed. Variants are replaced together with
  136. * the data they store (exception: use a data source).
  137. *
  138. * Variant semantics:
  139. * - arrayLength = -1 && data == NULL: empty variant
  140. * - arrayLength = -1 && data == !NULL: variant holds a single element (a scalar)
  141. * - arrayLength >= 0: variant holds an array of the appropriate length
  142. * data can be NULL if arrayLength == 0
  143. */
  144. typedef struct {
  145. const UA_DataType *type; ///< The nodeid of the datatype
  146. enum {
  147. UA_VARIANT_DATA, ///< The data is "owned" by this variant (copied and deleted together)
  148. UA_VARIANT_DATA_NODELETE, /**< The data is "borrowed" by the variant and shall not be
  149. deleted at the end of this variant's lifecycle. It is not
  150. possible to overwrite borrowed data due to concurrent access.
  151. Use a custom datasource with a mutex. */
  152. } storageType; ///< Shall the data be deleted together with the variant
  153. UA_Int32 arrayLength; ///< the number of elements in the data-pointer
  154. void *data; ///< points to the scalar or array data
  155. UA_Int32 arrayDimensionsSize; ///< the number of dimensions the data-array has
  156. UA_Int32 *arrayDimensions; ///< the length of each dimension of the data-array
  157. } UA_Variant;
  158. /** @brief A data value with an associated status code and timestamps. */
  159. typedef struct {
  160. UA_Boolean hasValue : 1;
  161. UA_Boolean hasStatus : 1;
  162. UA_Boolean hasSourceTimestamp : 1;
  163. UA_Boolean hasServerTimestamp : 1;
  164. UA_Boolean hasSourcePicoseconds : 1;
  165. UA_Boolean hasServerPicoseconds : 1;
  166. UA_Variant value;
  167. UA_StatusCode status;
  168. UA_DateTime sourceTimestamp;
  169. UA_Int16 sourcePicoseconds;
  170. UA_DateTime serverTimestamp;
  171. UA_Int16 serverPicoseconds;
  172. } UA_DataValue;
  173. /** @brief A structure that contains detailed error and diagnostic information associated with a StatusCode. */
  174. typedef struct UA_DiagnosticInfo {
  175. UA_Boolean hasSymbolicId : 1;
  176. UA_Boolean hasNamespaceUri : 1;
  177. UA_Boolean hasLocalizedText : 1;
  178. UA_Boolean hasLocale : 1;
  179. UA_Boolean hasAdditionalInfo : 1;
  180. UA_Boolean hasInnerStatusCode : 1;
  181. UA_Boolean hasInnerDiagnosticInfo : 1;
  182. UA_Int32 symbolicId;
  183. UA_Int32 namespaceUri;
  184. UA_Int32 localizedText;
  185. UA_Int32 locale;
  186. UA_String additionalInfo;
  187. UA_StatusCode innerStatusCode;
  188. struct UA_DiagnosticInfo *innerDiagnosticInfo;
  189. } UA_DiagnosticInfo;
  190. #define UA_TYPE_HANDLING_FUNCTIONS(TYPE) \
  191. TYPE UA_EXPORT * TYPE##_new(void); \
  192. void UA_EXPORT TYPE##_init(TYPE * p); \
  193. void UA_EXPORT TYPE##_delete(TYPE * p); \
  194. void UA_EXPORT TYPE##_deleteMembers(TYPE * p); \
  195. UA_StatusCode UA_EXPORT TYPE##_copy(const TYPE *src, TYPE *dst);
  196. /* Functions for all types */
  197. UA_TYPE_HANDLING_FUNCTIONS(UA_Boolean)
  198. UA_TYPE_HANDLING_FUNCTIONS(UA_SByte)
  199. UA_TYPE_HANDLING_FUNCTIONS(UA_Byte)
  200. UA_TYPE_HANDLING_FUNCTIONS(UA_Int16)
  201. UA_TYPE_HANDLING_FUNCTIONS(UA_UInt16)
  202. UA_TYPE_HANDLING_FUNCTIONS(UA_Int32)
  203. UA_TYPE_HANDLING_FUNCTIONS(UA_UInt32)
  204. UA_TYPE_HANDLING_FUNCTIONS(UA_Int64)
  205. UA_TYPE_HANDLING_FUNCTIONS(UA_UInt64)
  206. UA_TYPE_HANDLING_FUNCTIONS(UA_Float)
  207. UA_TYPE_HANDLING_FUNCTIONS(UA_Double)
  208. UA_TYPE_HANDLING_FUNCTIONS(UA_String)
  209. #define UA_DateTime_new UA_Int64_new
  210. #define UA_DateTime_init UA_Int64_init
  211. #define UA_DateTime_delete UA_Int64_delete
  212. #define UA_DateTime_deleteMembers UA_Int64_deleteMembers
  213. #define UA_DateTime_copy UA_Int64_copy
  214. UA_TYPE_HANDLING_FUNCTIONS(UA_Guid)
  215. #define UA_ByteString_new UA_String_new
  216. #define UA_ByteString_init UA_String_init
  217. #define UA_ByteString_delete UA_String_delete
  218. #define UA_ByteString_deleteMembers UA_String_deleteMembers
  219. #define UA_ByteString_copy UA_String_copy
  220. #define UA_XmlElement_new UA_String_new
  221. #define UA_XmlElement_init UA_String_init
  222. #define UA_XmlElement_delete UA_String_delete
  223. #define UA_XmlElement_deleteMembers UA_String_deleteMembers
  224. #define UA_XmlElement_copy UA_String_copy
  225. UA_TYPE_HANDLING_FUNCTIONS(UA_NodeId)
  226. UA_TYPE_HANDLING_FUNCTIONS(UA_ExpandedNodeId)
  227. #define UA_StatusCode_new(p) UA_Int32_new((UA_Int32*)p)
  228. #define UA_StatusCode_init(p) UA_Int32_init((UA_Int32*)p)
  229. #define UA_StatusCode_delete(p) UA_Int32_delete((UA_Int32*)p)
  230. #define UA_StatusCode_deleteMembers(p) UA_Int32_deleteMembers((UA_Int32*)p)
  231. #define UA_StatusCode_copy(p) UA_Int32_copy((UA_Int32*)p)
  232. UA_TYPE_HANDLING_FUNCTIONS(UA_QualifiedName)
  233. UA_TYPE_HANDLING_FUNCTIONS(UA_LocalizedText)
  234. UA_TYPE_HANDLING_FUNCTIONS(UA_ExtensionObject)
  235. UA_TYPE_HANDLING_FUNCTIONS(UA_DataValue)
  236. UA_TYPE_HANDLING_FUNCTIONS(UA_Variant)
  237. UA_TYPE_HANDLING_FUNCTIONS(UA_DiagnosticInfo)
  238. /**********************************************/
  239. /* Custom functions for the builtin datatypes */
  240. /**********************************************/
  241. /* String */
  242. /** Copy a (zero terminated) char-array into a UA_String. Memory for the string data is
  243. allocated. If the memory cannot be allocated, a null-string is returned. */
  244. UA_String UA_EXPORT UA_String_fromChars(char const src[]);
  245. #define UA_STRING_NULL (UA_String) {-1, (UA_Byte*)0 }
  246. #define UA_STRING(CHARS) (UA_String) {strlen(CHARS), (UA_Byte*)CHARS }
  247. #define UA_STRING_ALLOC(CHARS) UA_String_fromChars(CHARS)
  248. /** Compares two strings */
  249. UA_Boolean UA_EXPORT UA_String_equal(const UA_String *string1, const UA_String *string2);
  250. /** Printf a char-array into a UA_String. Memory for the string data is allocated. */
  251. UA_StatusCode UA_EXPORT UA_String_copyprintf(char const fmt[], UA_String *dst, ...);
  252. /* DateTime */
  253. /** Returns the current time */
  254. UA_DateTime UA_EXPORT UA_DateTime_now(void);
  255. typedef struct UA_DateTimeStruct {
  256. UA_Int16 nanoSec;
  257. UA_Int16 microSec;
  258. UA_Int16 milliSec;
  259. UA_Int16 sec;
  260. UA_Int16 min;
  261. UA_Int16 hour;
  262. UA_Int16 day;
  263. UA_Int16 month;
  264. UA_Int16 year;
  265. } UA_DateTimeStruct;
  266. UA_DateTimeStruct UA_EXPORT UA_DateTime_toStruct(UA_DateTime time);
  267. UA_StatusCode UA_EXPORT UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
  268. /* Guid */
  269. /** Compares two guids */
  270. UA_Boolean UA_EXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
  271. /** Returns a randomly generated guid. Do not use for security-critical entropy! */
  272. UA_Guid UA_EXPORT UA_Guid_random(UA_UInt32 *seed);
  273. /* ByteString */
  274. #define UA_BYTESTRING_NULL (UA_ByteString) {-1, (UA_Byte*)0 }
  275. #define UA_ByteString_equal(string1, string2) \
  276. UA_String_equal((const UA_String*) string1, (const UA_String*)string2)
  277. /** Allocates memory of size length for the bytestring. The content is not set to zero. */
  278. UA_StatusCode UA_EXPORT UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length);
  279. /* NodeId */
  280. /** Compares two nodeids */
  281. UA_Boolean UA_EXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
  282. /** Is the nodeid a null-nodeid? */
  283. UA_Boolean UA_EXPORT UA_NodeId_isNull(const UA_NodeId *p);
  284. UA_NodeId UA_EXPORT UA_NodeId_fromInteger(UA_UInt16 nsIndex, UA_Int32 identifier);
  285. UA_NodeId UA_EXPORT UA_NodeId_fromCharString(UA_UInt16 nsIndex, char identifier[]);
  286. UA_NodeId UA_EXPORT UA_NodeId_fromCharStringCopy(UA_UInt16 nsIndex, char const identifier[]);
  287. UA_NodeId UA_EXPORT UA_NodeId_fromString(UA_UInt16 nsIndex, UA_String identifier);
  288. UA_NodeId UA_EXPORT UA_NodeId_fromStringCopy(UA_UInt16 nsIndex, UA_String identifier);
  289. UA_NodeId UA_EXPORT UA_NodeId_fromGuid(UA_UInt16 nsIndex, UA_Guid identifier);
  290. UA_NodeId UA_EXPORT UA_NodeId_fromCharByteString(UA_UInt16 nsIndex, char identifier[]);
  291. UA_NodeId UA_EXPORT UA_NodeId_fromCharByteStringCopy(UA_UInt16 nsIndex, char const identifier[]);
  292. UA_NodeId UA_EXPORT UA_NodeId_fromByteString(UA_UInt16 nsIndex, UA_ByteString identifier);
  293. UA_NodeId UA_EXPORT UA_NodeId_fromByteStringCopy(UA_UInt16 nsIndex, UA_ByteString identifier);
  294. #define UA_NODEID_NUMERIC(NSID, NUMERICID) UA_NodeId_fromInteger(NSID, NUMERICID)
  295. #define UA_NODEID_STRING(NSID, CHARS) UA_NodeId_fromCharString(NSID, CHARS)
  296. #define UA_NODEID_STRING_ALLOC(NSID, CHARS) UA_NodeId_fromCharStringCopy(NSID, CHARS)
  297. #define UA_NODEID_GUID(NSID, GUID) UA_NodeId_fromGuid(NSID, GUID)
  298. #define UA_NODEID_BYTESTRING(NSID, CHARS) UA_NodeId_fromCharByteString(NSID, CHARS)
  299. #define UA_NODEID_BYTESTRING_ALLOC(NSID, CHARS) UA_NodeId_fromCharStringCopy(NSID, CHARS)
  300. #define UA_NODEID_NULL UA_NODEID_NUMERIC(0,0)
  301. /* ExpandedNodeId */
  302. UA_Boolean UA_EXPORT UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
  303. #define UA_EXPANDEDNODEID_NUMERIC(NSID, NUMERICID) (UA_ExpandedNodeId) { \
  304. .nodeId = {.namespaceIndex = NSID, .identifierType = UA_NODEIDTYPE_NUMERIC, \
  305. .identifier.numeric = NUMERICID }, \
  306. .serverIndex = 0, .namespaceUri = {.data = (UA_Byte*)0, .length = -1} }
  307. /* QualifiedName */
  308. #define UA_QUALIFIEDNAME(NSID, CHARS) (const UA_QualifiedName) { \
  309. .namespaceIndex = NSID, .name = UA_STRING(CHARS) }
  310. #define UA_QUALIFIEDNAME_ALLOC(NSID, CHARS) (UA_QualifiedName) { \
  311. .namespaceIndex = NSID, .name = UA_STRING_ALLOC(CHARS) }
  312. /* LocalizedText */
  313. #define UA_LOCALIZEDTEXT(LOCALE, TEXT) (const UA_LocalizedText) { \
  314. .locale = UA_STRING(LOCALE), .text = UA_STRING(TEXT) }
  315. #define UA_LOCALIZEDTEXT_ALLOC(LOCALE, TEXT) (UA_LocalizedText) { \
  316. .locale = UA_STRING_ALLOC(LOCALE), .text = UA_STRING_ALLOC(TEXT) }
  317. /* Variant */
  318. /**
  319. * Returns true if the variant contains a scalar value. Note that empty variants contain an array of
  320. * length -1 (undefined).
  321. *
  322. * @param v The variant
  323. * @return Does the variant contain a scalar value.
  324. */
  325. UA_Boolean UA_EXPORT UA_Variant_isScalar(const UA_Variant *v);
  326. /**
  327. * Set the variant to a scalar value that already resides in memory. The value takes on the
  328. * lifecycle of the variant and is deleted with it.
  329. *
  330. * @param v The variant
  331. * @param p A pointer to the value data
  332. * @param type The datatype of the value in question
  333. * @return Indicates whether the operation succeeded or returns an error code
  334. */
  335. UA_StatusCode UA_EXPORT UA_Variant_setScalar(UA_Variant *v, void *p, const UA_DataType *type);
  336. /**
  337. * Set the variant to a scalar value that is copied from an existing variable.
  338. *
  339. * @param v The variant
  340. * @param p A pointer to the value data
  341. * @param type The datatype of the value
  342. * @return Indicates whether the operation succeeded or returns an error code
  343. */
  344. UA_StatusCode UA_EXPORT UA_Variant_setScalarCopy(UA_Variant *v, const void *p, const UA_DataType *type);
  345. /**
  346. * Set the variant to an array that already resides in memory. The array takes on the lifecycle of
  347. * the variant and is deleted with it.
  348. *
  349. * @param v The variant
  350. * @param array A pointer to the array data
  351. * @param noElements The size of the array
  352. * @param type The datatype of the array
  353. * @return Indicates whether the operation succeeded or returns an error code
  354. */
  355. UA_StatusCode UA_EXPORT UA_Variant_setArray(UA_Variant *v, void *array, UA_Int32 noElements,
  356. const UA_DataType *type);
  357. /**
  358. * Set the variant to an array that is copied from an existing array.
  359. *
  360. * @param v The variant
  361. * @param array A pointer to the array data
  362. * @param noElements The size of the array
  363. * @param type The datatype of the array
  364. * @return Indicates whether the operation succeeded or returns an error code
  365. */
  366. UA_StatusCode UA_EXPORT UA_Variant_setArrayCopy(UA_Variant *v, const void *array, UA_Int32 noElements,
  367. const UA_DataType *type);
  368. /** @brief NumericRanges are used select a subset in a (multidimensional)
  369. variant array. NumericRange has no official type structure in the standard.
  370. On the wire, it only exists as an encoded string, such as "1:2,0:3,5". The
  371. colon separates min/max index and the comma separates dimensions. A single
  372. value indicates a range with a single element (min==max). */
  373. typedef struct {
  374. UA_Int32 dimensionsSize;
  375. struct UA_NumericRangeDimension {
  376. UA_UInt32 min;
  377. UA_UInt32 max;
  378. } *dimensions;
  379. } UA_NumericRange;
  380. /**
  381. * Copy the variant, but use only a subset of the (multidimensional) array into a variant. Returns
  382. * an error code if the variant is not an array or if the indicated range does not fit.
  383. */
  384. UA_StatusCode UA_EXPORT UA_Variant_copyRange(const UA_Variant *src, UA_Variant *dst, UA_NumericRange range);
  385. /**
  386. * Insert a range of data into an existing variant. The data array can't be reused afterwards if it
  387. * contains types without a fixed size (e.g. strings) since they take on the lifetime of the
  388. * variant.
  389. *
  390. * @param v The variant
  391. * @param dataArray The data array. The type must match the variant
  392. * @param dataarraySize The length of the data array. This is checked to match the range size.
  393. * @param range The range of where the new data is inserted
  394. * @return Indicates whether the operation succeeded or returns an error code
  395. */
  396. UA_StatusCode UA_EXPORT UA_Variant_setRange(UA_Variant *v, void *dataArray, UA_Int32 dataArraySize,
  397. const UA_NumericRange range);
  398. /**
  399. * Deep-copy a range of data into an existing variant.
  400. *
  401. * @param v The variant
  402. * @param dataArray The data array. The type must match the variant
  403. * @param dataarraySize The length of the data array. This is checked to match the range size.
  404. * @param range The range of where the new data is inserted
  405. * @return Indicates whether the operation succeeded or returns an error code
  406. */
  407. UA_StatusCode UA_EXPORT UA_Variant_setRangeCopy(UA_Variant *v, const void *dataArray, UA_Int32 dataArraySize,
  408. const UA_NumericRange range);
  409. /****************************/
  410. /* Structured Type Handling */
  411. /****************************/
  412. #define UA_MAX_TYPE_MEMBERS 13 // Maximum number of members per complex type
  413. #ifndef _WIN32
  414. # define UA_BITFIELD(SIZE) : SIZE
  415. #else
  416. # define UA_BITFIELD(SIZE)
  417. #endif
  418. #define UA_IS_BUILTIN(ID) (ID <= UA_TYPES_DIAGNOSTICINFO)
  419. typedef struct {
  420. UA_UInt16 memberTypeIndex UA_BITFIELD(9); ///< Index of the member in the datatypetable
  421. UA_Boolean namespaceZero UA_BITFIELD(1); /**< The type of the member is defined in namespace
  422. zero. In this implementation, types from custom
  423. namespace may contain members from the same
  424. namespace or ns0 only.*/
  425. UA_Byte padding UA_BITFIELD(5); /**< How much padding is there before this member element? For
  426. arrays this is split into 2 bytes padding before the
  427. length index (max 4 bytes) and 3 bytes padding before the
  428. pointer (max 8 bytes) */
  429. UA_Boolean isArray UA_BITFIELD(1); ///< The member is an array of the given type
  430. } UA_DataTypeMember;
  431. struct UA_DataType {
  432. UA_NodeId typeId; ///< The nodeid of the type
  433. ptrdiff_t memSize UA_BITFIELD(16); ///< Size of the struct in memory
  434. UA_UInt16 typeIndex UA_BITFIELD(13); ///< Index of the type in the datatypetable
  435. UA_Boolean namespaceZero UA_BITFIELD(1); ///< The type is defined in namespace zero
  436. UA_Boolean fixedSize UA_BITFIELD(1); ///< The type (and its members) contains no pointers
  437. UA_Boolean zeroCopyable UA_BITFIELD(1); ///< Can the type be copied directly off the stream?
  438. UA_Byte membersSize; ///< How many members does the type have?
  439. UA_DataTypeMember members[UA_MAX_TYPE_MEMBERS];
  440. };
  441. /**
  442. * Allocates and initializes a variable of type dataType
  443. *
  444. * @param dataType The datatype description
  445. * @return Returns the memory location of the variable or (void*)0 if no memory is available
  446. */
  447. void UA_EXPORT * UA_new(const UA_DataType *dataType);
  448. /**
  449. * Initializes a variable to default values
  450. *
  451. * @param p The memory location of the variable
  452. * @param dataType The datatype description
  453. */
  454. void UA_EXPORT UA_init(void *p, const UA_DataType *dataType);
  455. /**
  456. * Copies the content of two variables. If copying fails (e.g. because no memory was available for
  457. * an array), then dst is emptied and initialized to prevent memory leaks.
  458. *
  459. * @param src The memory location of the source variable
  460. * @param dst The memory location of the destination variable
  461. * @param dataType The datatype description
  462. * @return Indicates whether the operation succeeded or returns an error code
  463. */
  464. UA_StatusCode UA_EXPORT UA_copy(const void *src, void *dst, const UA_DataType *dataType);
  465. /**
  466. * Deletes the dynamically assigned content of a variable (e.g. a member-array). Afterwards, the
  467. * variable can be safely deleted without causing memory leaks. But the variable is not initialized
  468. * and may contain old data that is not memory-relevant.
  469. *
  470. * @param p The memory location of the variable
  471. * @param dataType The datatype description of the variable
  472. */
  473. void UA_EXPORT UA_deleteMembers(void *p, const UA_DataType *dataType);
  474. void UA_EXPORT UA_deleteMembersUntil(void *p, const UA_DataType *dataType, UA_Int32 lastMember);
  475. /**
  476. * Deletes (frees) a variable and all of its content.
  477. *
  478. * @param p The memory location of the variable
  479. * @param dataType The datatype description of the variable
  480. */
  481. void UA_EXPORT UA_delete(void *p, const UA_DataType *dataType);
  482. /********************/
  483. /* Array operations */
  484. /********************/
  485. #define MAX_ARRAY_SIZE 104857600 // arrays must be smaller than 100MB
  486. /**
  487. * Allocates and initializes an array of variables of a specific type
  488. *
  489. * @param dataType The datatype description
  490. * @return Returns the memory location of the variable or (void*)0 if no memory could be allocated
  491. */
  492. void UA_EXPORT * UA_Array_new(const UA_DataType *dataType, UA_Int32 noElements);
  493. /**
  494. * Allocates and copies an array. dst is set to (void*)0 if not enough memory is available.
  495. *
  496. * @param src The memory location of the source array
  497. * @param dst The memory location where the pointer to the destination array is written
  498. * @param dataType The datatype of the array members
  499. * @param noElements The size of the array
  500. * @return Indicates whether the operation succeeded or returns an error code
  501. */
  502. UA_StatusCode UA_EXPORT UA_Array_copy(const void *src, void **dst, const UA_DataType *dataType, UA_Int32 noElements);
  503. /**
  504. * Deletes an array.
  505. *
  506. * @param src The memory location of the array
  507. * @param dataType The datatype of the array members
  508. * @param noElements The size of the array
  509. */
  510. void UA_EXPORT UA_Array_delete(void *p, const UA_DataType *dataType, UA_Int32 noElements);
  511. /* These are not generated from XML. Server *and* client need them. */
  512. typedef enum {
  513. UA_ATTRIBUTEID_NODEID = 1,
  514. UA_ATTRIBUTEID_NODECLASS = 2,
  515. UA_ATTRIBUTEID_BROWSENAME = 3,
  516. UA_ATTRIBUTEID_DISPLAYNAME = 4,
  517. UA_ATTRIBUTEID_DESCRIPTION = 5,
  518. UA_ATTRIBUTEID_WRITEMASK = 6,
  519. UA_ATTRIBUTEID_USERWRITEMASK = 7,
  520. UA_ATTRIBUTEID_ISABSTRACT = 8,
  521. UA_ATTRIBUTEID_SYMMETRIC = 9,
  522. UA_ATTRIBUTEID_INVERSENAME = 10,
  523. UA_ATTRIBUTEID_CONTAINSNOLOOPS = 11,
  524. UA_ATTRIBUTEID_EVENTNOTIFIER = 12,
  525. UA_ATTRIBUTEID_VALUE = 13,
  526. UA_ATTRIBUTEID_DATATYPE = 14,
  527. UA_ATTRIBUTEID_VALUERANK = 15,
  528. UA_ATTRIBUTEID_ARRAYDIMENSIONS = 16,
  529. UA_ATTRIBUTEID_ACCESSLEVEL = 17,
  530. UA_ATTRIBUTEID_USERACCESSLEVEL = 18,
  531. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL = 19,
  532. UA_ATTRIBUTEID_HISTORIZING = 20,
  533. UA_ATTRIBUTEID_EXECUTABLE = 21,
  534. UA_ATTRIBUTEID_USEREXECUTABLE = 22
  535. } UA_AttributeId;
  536. #ifdef __cplusplus
  537. } // extern "C"
  538. #endif
  539. #endif /* UA_TYPES_H_ */