ua_types.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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_TYPES_H_
  16. #define UA_TYPES_H_
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. #ifndef UA_FFI_BINDINGS
  21. #include <stdbool.h>
  22. #include <inttypes.h>
  23. #endif
  24. #include "ua_config.h"
  25. #include "ua_statuscodes.h"
  26. /* Indicates that an array has the length 0 (NULL indicates an non-defined array of length -1)*/
  27. #define UA_EMPTY_ARRAY_SENTINEL ((void*)0x01)
  28. /****************************/
  29. /* Builtin Type Definitions */
  30. /****************************/
  31. #define UA_BUILTIN_TYPES_COUNT 25
  32. /** Boolean: A two-state logical value (true or false) */
  33. typedef bool UA_Boolean;
  34. #define UA_TRUE true
  35. #define UA_FALSE false
  36. /** SByte: An integer value between -128 and 127 */
  37. typedef int8_t UA_SByte;
  38. #define UA_SBYTE_MAX 127
  39. #define UA_SBYTE_MIN (-128)
  40. /** Byte: An integer value between 0 and 256 */
  41. typedef uint8_t UA_Byte;
  42. #define UA_BYTE_MAX 256
  43. #define UA_BYTE_MIN 0
  44. /** Int16: An integer value between -32 768 and 32 767 */
  45. typedef int16_t UA_Int16;
  46. #define UA_INT16_MAX 32767
  47. #define UA_INT16_MIN (-32768)
  48. /** UInt16: An integer value between 0 and 65 535 */
  49. typedef uint16_t UA_UInt16;
  50. #define UA_UINT16_MAX 65535
  51. #define UA_UINT16_MIN 0
  52. /** Int32: An integer value between -2 147 483 648 and 2 147 483 647 */
  53. typedef int32_t UA_Int32;
  54. #define UA_INT32_MAX 2147483647
  55. #define UA_INT32_MIN (-2147483648)
  56. /** UInt32: An integer value between 0 and 4 294 967 295 */
  57. typedef uint32_t UA_UInt32;
  58. #define UA_UINT32_MAX 4294967295
  59. #define UA_UINT32_MIN 0
  60. /* do not use for cryptographic entropy */
  61. UA_EXPORT UA_UInt32 UA_UInt32_random(void);
  62. /** Int64: An integer value between -10 223 372 036 854 775 808 and 9 223 372 036 854 775 807 */
  63. typedef int64_t UA_Int64;
  64. #define UA_INT64_MAX (int64_t)9223372036854775807
  65. #define UA_INT64_MIN ((int64_t)-9223372036854775808)
  66. /** UInt64: An integer value between 0 and 18 446 744 073 709 551 615 */
  67. typedef uint64_t UA_UInt64;
  68. #define UA_UINT64_MAX (int64_t)18446744073709551615
  69. #define UA_UINT64_MIN (int64_t)0
  70. /** Float: An IEEE single precision (32 bit) floating point value */
  71. typedef float UA_Float;
  72. /** Double: An IEEE double precision (64 bit) floating point value */
  73. typedef double UA_Double;
  74. /********************************************/
  75. /* String: A sequence of Unicode characters */
  76. /********************************************/
  77. typedef struct {
  78. size_t length; // The length of the string
  79. UA_Byte *data; // The string's content (not null-terminated)
  80. } UA_String;
  81. UA_EXPORT extern const UA_String UA_STRING_NULL;
  82. static UA_INLINE UA_String UA_STRING(char *chars) {
  83. UA_String str; str.length = strlen(chars);
  84. str.data = (UA_Byte*)chars; return str; }
  85. #define UA_STRING_ALLOC(CHARS) UA_String_fromChars(CHARS)
  86. /** Copies the content on the heap. Returns a null-string when alloc fails */
  87. UA_String UA_EXPORT UA_String_fromChars(char const src[]) UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  88. UA_Boolean UA_EXPORT UA_String_equal(const UA_String *s1, const UA_String *s2);
  89. /*********************************/
  90. /* DateTime: An instance in time */
  91. /*********************************/
  92. /* A DateTime value is encoded as a 64-bit signed integer which represents the
  93. number of 100 nanosecond intervals since January 1, 1601 (UTC) */
  94. typedef UA_Int64 UA_DateTime;
  95. /* The current time */
  96. UA_DateTime UA_EXPORT UA_DateTime_now(void);
  97. /* CPU clock invariant to system time changes. Use only for time diffs, not current time */
  98. UA_DateTime UA_EXPORT UA_DateTime_nowMonotonic(void);
  99. typedef struct UA_DateTimeStruct {
  100. UA_UInt16 nanoSec;
  101. UA_UInt16 microSec;
  102. UA_UInt16 milliSec;
  103. UA_UInt16 sec;
  104. UA_UInt16 min;
  105. UA_UInt16 hour;
  106. UA_UInt16 day;
  107. UA_UInt16 month;
  108. UA_UInt16 year;
  109. } UA_DateTimeStruct;
  110. UA_DateTimeStruct UA_EXPORT UA_DateTime_toStruct(UA_DateTime time);
  111. UA_String UA_EXPORT UA_DateTime_toString(UA_DateTime time);
  112. /**************************************************************************/
  113. /* Guid: A 16 byte value that can be used as a globally unique identifier */
  114. /**************************************************************************/
  115. typedef struct {
  116. UA_UInt32 data1;
  117. UA_UInt16 data2;
  118. UA_UInt16 data3;
  119. UA_Byte data4[8];
  120. } UA_Guid;
  121. UA_Boolean UA_EXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
  122. /* do not use for cryptographic entropy */
  123. UA_Guid UA_EXPORT UA_Guid_random(void);
  124. /************************************/
  125. /* ByteString: A sequence of octets */
  126. /************************************/
  127. typedef UA_String UA_ByteString;
  128. static UA_INLINE UA_Boolean
  129. UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2) {
  130. return UA_String_equal((const UA_String*)string1, (const UA_String*)string2); }
  131. /* Allocates memory of size length for the bytestring. The content is not set to zero. */
  132. UA_StatusCode UA_EXPORT UA_ByteString_allocBuffer(UA_ByteString *bs, size_t length);
  133. UA_EXPORT extern const UA_ByteString UA_BYTESTRING_NULL;
  134. static UA_INLINE UA_ByteString UA_BYTESTRING(char *chars) {
  135. UA_ByteString str; str.length = strlen(chars); str.data = (UA_Byte*)chars; return str; }
  136. static UA_INLINE UA_ByteString UA_BYTESTRING_ALLOC(const char *chars) {
  137. UA_String str = UA_String_fromChars(chars); UA_ByteString bstr;
  138. bstr.length = str.length; bstr.data = str.data; return bstr;
  139. }
  140. /******************************/
  141. /* XmlElement: An XML element */
  142. /******************************/
  143. typedef UA_String UA_XmlElement;
  144. /*****************************************************************************/
  145. /* NodeId: An identifier for a node in the address space of an OPC UA Server */
  146. /*****************************************************************************/
  147. enum UA_NodeIdType {
  148. UA_NODEIDTYPE_NUMERIC = 0, ///< On the wire, this can be 0,1,2 for numeric nodeids of different sizes
  149. UA_NODEIDTYPE_STRING = 3,
  150. UA_NODEIDTYPE_GUID = 4,
  151. UA_NODEIDTYPE_BYTESTRING = 5
  152. };
  153. typedef struct {
  154. UA_UInt16 namespaceIndex;
  155. enum UA_NodeIdType identifierType;
  156. union {
  157. UA_UInt32 numeric;
  158. UA_String string;
  159. UA_Guid guid;
  160. UA_ByteString byteString;
  161. } identifier;
  162. } UA_NodeId;
  163. UA_EXPORT extern const UA_NodeId UA_NODEID_NULL;
  164. static UA_INLINE UA_Boolean UA_NodeId_isNull(const UA_NodeId *p) {
  165. return (p->namespaceIndex == 0 && p->identifierType == UA_NODEIDTYPE_NUMERIC &&
  166. p->identifier.numeric == 0);
  167. }
  168. UA_Boolean UA_EXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
  169. static UA_INLINE UA_NodeId UA_NODEID_NUMERIC(UA_UInt16 nsIndex, UA_Int32 identifier) {
  170. UA_NodeId id; id.namespaceIndex = nsIndex; id.identifierType = UA_NODEIDTYPE_NUMERIC;
  171. id.identifier.numeric = identifier; return id; }
  172. static UA_INLINE UA_NodeId UA_NODEID_STRING(UA_UInt16 nsIndex, char *chars) {
  173. UA_NodeId id; id.namespaceIndex = nsIndex; id.identifierType = UA_NODEIDTYPE_STRING;
  174. id.identifier.string = UA_STRING(chars); return id; }
  175. static UA_INLINE UA_NodeId UA_NODEID_STRING_ALLOC(UA_UInt16 nsIndex, const char *chars) {
  176. UA_NodeId id; id.namespaceIndex = nsIndex; id.identifierType = UA_NODEIDTYPE_STRING;
  177. id.identifier.string = UA_STRING_ALLOC(chars); return id; }
  178. static UA_INLINE UA_NodeId UA_NODEID_GUID(UA_UInt16 nsIndex, UA_Guid guid) {
  179. UA_NodeId id; id.namespaceIndex = nsIndex; id.identifierType = UA_NODEIDTYPE_GUID;
  180. id.identifier.guid = guid; return id; }
  181. static UA_INLINE UA_NodeId UA_NODEID_BYTESTRING(UA_UInt16 nsIndex, char *chars) {
  182. UA_NodeId id; id.namespaceIndex = nsIndex; id.identifierType = UA_NODEIDTYPE_BYTESTRING;
  183. id.identifier.byteString = UA_BYTESTRING(chars); return id; }
  184. static UA_INLINE UA_NodeId UA_NODEID_BYTESTRING_ALLOC(UA_UInt16 nsIndex, const char *chars) {
  185. UA_NodeId id; id.namespaceIndex = nsIndex; id.identifierType = UA_NODEIDTYPE_BYTESTRING;
  186. id.identifier.byteString = UA_BYTESTRING_ALLOC(chars); return id; }
  187. /**********************************************************************************************/
  188. /* ExpandedNodeId: A NodeId that allows the namespace URI to be specified instead of an index */
  189. /**********************************************************************************************/
  190. typedef struct {
  191. UA_NodeId nodeId;
  192. UA_String namespaceUri;
  193. UA_UInt32 serverIndex;
  194. } UA_ExpandedNodeId;
  195. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_NUMERIC(UA_UInt16 nsIndex, UA_Int32 identifier) {
  196. UA_ExpandedNodeId id; id.nodeId = UA_NODEID_NUMERIC(nsIndex, identifier);
  197. id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id; }
  198. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_STRING(UA_UInt16 nsIndex, char *chars) {
  199. UA_ExpandedNodeId id; id.nodeId = UA_NODEID_STRING(nsIndex, chars);
  200. id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id; }
  201. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_STRING_ALLOC(UA_UInt16 nsIndex, const char *chars) {
  202. UA_ExpandedNodeId id; id.nodeId = UA_NODEID_STRING_ALLOC(nsIndex, chars);
  203. id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id; }
  204. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_STRING_GUID(UA_UInt16 nsIndex, UA_Guid guid) {
  205. UA_ExpandedNodeId id; id.nodeId = UA_NODEID_GUID(nsIndex, guid);
  206. id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id; }
  207. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_BYTESTRING(UA_UInt16 nsIndex, char *chars) {
  208. UA_ExpandedNodeId id; id.nodeId = UA_NODEID_BYTESTRING(nsIndex, chars);
  209. id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id; }
  210. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_BYTESTRING_ALLOC(UA_UInt16 nsIndex, const char *chars) {
  211. UA_ExpandedNodeId id; id.nodeId = UA_NODEID_BYTESTRING_ALLOC(nsIndex, chars);
  212. id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id; }
  213. /**************************************************/
  214. /* QualifiedName: A name qualified by a namespace */
  215. /**************************************************/
  216. typedef struct {
  217. UA_UInt16 namespaceIndex;
  218. UA_String name;
  219. } UA_QualifiedName;
  220. static UA_INLINE UA_QualifiedName UA_QUALIFIEDNAME(UA_UInt16 nsIndex, char *chars) {
  221. UA_QualifiedName qn; qn.namespaceIndex = nsIndex; qn.name = UA_STRING(chars); return qn; }
  222. static UA_INLINE UA_QualifiedName UA_QUALIFIEDNAME_ALLOC(UA_UInt16 nsIndex, const char *chars) {
  223. UA_QualifiedName qn; qn.namespaceIndex = nsIndex; qn.name = UA_STRING_ALLOC(chars); return qn; }
  224. /*************************************************************************/
  225. /* LocalizedText: Human readable text with an optional locale identifier */
  226. /*************************************************************************/
  227. typedef struct {
  228. UA_String locale;
  229. UA_String text;
  230. } UA_LocalizedText;
  231. static UA_INLINE UA_LocalizedText UA_LOCALIZEDTEXT(char *locale, char *text) {
  232. UA_LocalizedText lt; lt.locale = UA_STRING(locale);
  233. lt.text = UA_STRING(text); return lt; }
  234. static UA_INLINE UA_LocalizedText UA_LOCALIZEDTEXT_ALLOC(const char *locale, const char *text) {
  235. UA_LocalizedText lt; lt.locale = UA_STRING_ALLOC(locale);
  236. lt.text = UA_STRING_ALLOC(text); return lt; }
  237. /* Forward Declaration of UA_DataType */
  238. struct UA_DataType;
  239. typedef struct UA_DataType UA_DataType;
  240. /********************************************************************************/
  241. /* ExtensionObject: A structure that contains an application specific data type */
  242. /* that may not be recognized by the receiver */
  243. /********************************************************************************/
  244. typedef struct {
  245. enum {
  246. UA_EXTENSIONOBJECT_ENCODED_NOBODY = 0,
  247. UA_EXTENSIONOBJECT_ENCODED_BYTESTRING = 1,
  248. UA_EXTENSIONOBJECT_ENCODED_XML = 2,
  249. UA_EXTENSIONOBJECT_DECODED = 3, ///< There is a pointer to the decoded data
  250. UA_EXTENSIONOBJECT_DECODED_NODELETE = 4 ///< Don't delete the decoded data at the lifecycle end
  251. } encoding;
  252. union {
  253. struct {
  254. UA_NodeId typeId; ///< The nodeid of the datatype
  255. UA_ByteString body; ///< The bytestring of the encoded data
  256. } encoded;
  257. struct {
  258. const UA_DataType *type;
  259. void *data;
  260. } decoded;
  261. } content;
  262. } UA_ExtensionObject;
  263. /*********************************************/
  264. /* Variant: Stores (arrays of) any data type */
  265. /*********************************************/
  266. /* Variant semantics:
  267. - arrayLength == 0 && data == NULL: no existing data
  268. - arrayLength == 0 && data == 0x01: array of length 0
  269. - arrayLength == 0 && data > 0x01: scalar value
  270. - arrayLength > 0: array of the given length
  271. */
  272. typedef struct {
  273. const UA_DataType *type; // The data type description
  274. enum {
  275. UA_VARIANT_DATA, /* The data has the same lifecycle as the variant */
  276. UA_VARIANT_DATA_NODELETE, /* The data is "borrowed" by the variant and shall not be
  277. deleted at the end of the variant's lifecycle. */
  278. } storageType;
  279. size_t arrayLength; // The number of elements in the data array
  280. void *data; // Points to the scalar or array data
  281. size_t arrayDimensionsSize; // The number of dimensions the data-array has
  282. UA_UInt32 *arrayDimensions; // The length of each dimension of the data-array
  283. } UA_Variant;
  284. /**
  285. * Returns true if the variant contains a scalar value. Note that empty variants
  286. * contain an array of length -1 (undefined).
  287. *
  288. * @param v The variant
  289. * @return Does the variant contain a scalar value.
  290. */
  291. static UA_INLINE UA_Boolean UA_Variant_isScalar(const UA_Variant *v) {
  292. return (v->arrayLength == 0 && v->data > UA_EMPTY_ARRAY_SENTINEL); }
  293. /**
  294. * Set the variant to a scalar value that already resides in memory. The value
  295. * takes on the lifecycle of the variant and is deleted with it.
  296. *
  297. * @param v The variant
  298. * @param p A pointer to the value data
  299. * @param type The datatype of the value in question
  300. */
  301. void UA_EXPORT
  302. UA_Variant_setScalar(UA_Variant *v, void * UA_RESTRICT p, const UA_DataType *type);
  303. /**
  304. * Set the variant to a scalar value that is copied from an existing variable.
  305. *
  306. * @param v The variant
  307. * @param p A pointer to the value data
  308. * @param type The datatype of the value
  309. * @return Indicates whether the operation succeeded or returns an error code
  310. */
  311. UA_StatusCode UA_EXPORT
  312. UA_Variant_setScalarCopy(UA_Variant *v, const void *p, const UA_DataType *type);
  313. /**
  314. * Set the variant to an array that already resides in memory. The array takes
  315. * on the lifecycle of the variant and is deleted with it.
  316. *
  317. * @param v The variant
  318. * @param array A pointer to the array data
  319. * @param arraySize The size of the array
  320. * @param type The datatype of the array
  321. */
  322. void UA_EXPORT
  323. UA_Variant_setArray(UA_Variant *v, void * UA_RESTRICT array,
  324. size_t arraySize, const UA_DataType *type);
  325. /**
  326. * Set the variant to an array that is copied from an existing array.
  327. *
  328. * @param v The variant
  329. * @param array A pointer to the array data
  330. * @param arraySize The size of the array
  331. * @param type The datatype of the array
  332. * @return Indicates whether the operation succeeded or returns an error code
  333. */
  334. UA_StatusCode UA_EXPORT
  335. UA_Variant_setArrayCopy(UA_Variant *v, const void *array,
  336. size_t arraySize, const UA_DataType *type);
  337. /* NumericRanges are used to indicate subsets of a (multidimensional) variant
  338. * array. NumericRange has no official type structure in the standard. On the
  339. * wire, it only exists as an encoded string, such as "1:2,0:3,5". The colon
  340. * separates min/max index and the comma separates dimensions. A single value
  341. * indicates a range with a single element (min==max). */
  342. typedef struct {
  343. size_t dimensionsSize;
  344. struct UA_NumericRangeDimension {
  345. UA_UInt32 min;
  346. UA_UInt32 max;
  347. } *dimensions;
  348. } UA_NumericRange;
  349. /**
  350. * Copy the variant, but use only a subset of the (multidimensional) array into a variant. Returns
  351. * an error code if the variant is not an array or if the indicated range does not fit.
  352. *
  353. * @param src The source variant
  354. * @param dst The target variant
  355. * @param range The range of the copied data
  356. * @return Returns UA_STATUSCODE_GOOD or an error code
  357. */
  358. UA_StatusCode UA_EXPORT
  359. UA_Variant_copyRange(const UA_Variant *src, UA_Variant *dst, const UA_NumericRange range);
  360. /**
  361. * Insert a range of data into an existing variant. The data array can't be reused afterwards if it
  362. * contains types without a fixed size (e.g. strings) since the members are moved into the variant
  363. * and take on its lifecycle.
  364. *
  365. * @param v The variant
  366. * @param dataArray The data array. The type must match the variant
  367. * @param dataArraySize The length of the data array. This is checked to match the range size.
  368. * @param range The range of where the new data is inserted
  369. * @return Returns UA_STATUSCODE_GOOD or an error code
  370. */
  371. UA_StatusCode UA_EXPORT
  372. UA_Variant_setRange(UA_Variant *v, void * UA_RESTRICT array,
  373. size_t arraySize, const UA_NumericRange range);
  374. /**
  375. * Deep-copy a range of data into an existing variant.
  376. *
  377. * @param v The variant
  378. * @param dataArray The data array. The type must match the variant
  379. * @param dataArraySize The length of the data array. This is checked to match the range size.
  380. * @param range The range of where the new data is inserted
  381. * @return Returns UA_STATUSCODE_GOOD or an error code
  382. */
  383. UA_StatusCode UA_EXPORT
  384. UA_Variant_setRangeCopy(UA_Variant *v, const void *array,
  385. size_t arraySize, const UA_NumericRange range);
  386. /**************************************************************************/
  387. /* DataValue: A data value with an associated status code and timestamps. */
  388. /**************************************************************************/
  389. typedef struct {
  390. UA_Boolean hasValue : 1;
  391. UA_Boolean hasStatus : 1;
  392. UA_Boolean hasSourceTimestamp : 1;
  393. UA_Boolean hasServerTimestamp : 1;
  394. UA_Boolean hasSourcePicoseconds : 1;
  395. UA_Boolean hasServerPicoseconds : 1;
  396. UA_Variant value;
  397. UA_StatusCode status;
  398. UA_DateTime sourceTimestamp;
  399. UA_Int16 sourcePicoseconds;
  400. UA_DateTime serverTimestamp;
  401. UA_Int16 serverPicoseconds;
  402. } UA_DataValue;
  403. /***************************************************************************/
  404. /* DiagnosticInfo: A structure that contains detailed error and diagnostic */
  405. /* information associated with a StatusCode. */
  406. /***************************************************************************/
  407. typedef struct UA_DiagnosticInfo {
  408. UA_Boolean hasSymbolicId : 1;
  409. UA_Boolean hasNamespaceUri : 1;
  410. UA_Boolean hasLocalizedText : 1;
  411. UA_Boolean hasLocale : 1;
  412. UA_Boolean hasAdditionalInfo : 1;
  413. UA_Boolean hasInnerStatusCode : 1;
  414. UA_Boolean hasInnerDiagnosticInfo : 1;
  415. UA_Int32 symbolicId;
  416. UA_Int32 namespaceUri;
  417. UA_Int32 localizedText;
  418. UA_Int32 locale;
  419. UA_String additionalInfo;
  420. UA_StatusCode innerStatusCode;
  421. struct UA_DiagnosticInfo *innerDiagnosticInfo;
  422. } UA_DiagnosticInfo;
  423. /*************************/
  424. /* Generic Type Handling */
  425. /*************************/
  426. #define UA_MAX_TYPE_MEMBERS 13 // Maximum number of members per structured type
  427. typedef struct {
  428. #ifdef UA_ENABLE_TYPENAMES
  429. const char *memberName;
  430. #endif
  431. UA_UInt16 memberTypeIndex; ///< Index of the member in the datatypetable
  432. UA_Byte padding; /**< How much padding is there before this member
  433. element? For arrays this is the padding before the
  434. size_t lenght member. (No padding between size_t
  435. and the following ptr.) */
  436. UA_Boolean namespaceZero : 1; /**< The type of the member is defined in namespace
  437. zero. In this implementation, types from custom
  438. namespace may contain members from the same
  439. namespace or ns0 only.*/
  440. UA_Boolean isArray : 1; ///< The member is an array of the given type
  441. } UA_DataTypeMember;
  442. struct UA_DataType {
  443. #ifdef UA_ENABLE_TYPENAMES
  444. const char *typeName;
  445. #endif
  446. UA_NodeId typeId; ///< The nodeid of the type
  447. UA_UInt16 memSize; ///< Size of the struct in memory
  448. UA_UInt16 typeIndex; ///< Index of the type in the datatypetable
  449. UA_Byte membersSize; ///< How many members does the type have?
  450. UA_Boolean builtin : 1; ///< The type is "builtin" and has dedicated de- and encoding functions
  451. UA_Boolean fixedSize : 1; ///< The type (and its members) contains no pointers
  452. UA_Boolean zeroCopyable : 1; ///< The type can be copied directly off the stream (given that the endianness matches)
  453. UA_DataTypeMember members[UA_MAX_TYPE_MEMBERS];
  454. };
  455. /**
  456. * Allocates and initializes a variable of type dataType
  457. *
  458. * @param type The datatype description
  459. * @return Returns the memory location of the variable or (void*)0 if no memory is available
  460. */
  461. void UA_EXPORT * UA_new(const UA_DataType *type) UA_FUNC_ATTR_MALLOC;
  462. /**
  463. * Initializes a variable to default values
  464. *
  465. * @param p The memory location of the variable
  466. * @param type The datatype description
  467. */
  468. static UA_INLINE void UA_init(void *p, const UA_DataType *type) {
  469. memset(p, 0, type->memSize); }
  470. /**
  471. * Copies the content of two variables. If copying fails (e.g. because no memory was available for
  472. * an array), then dst is emptied and initialized to prevent memory leaks.
  473. *
  474. * @param src The memory location of the source variable
  475. * @param dst The memory location of the destination variable
  476. * @param type The datatype description
  477. * @return Indicates whether the operation succeeded or returns an error code
  478. */
  479. UA_StatusCode UA_EXPORT
  480. UA_copy(const void *src, void *dst, const UA_DataType *type);
  481. /**
  482. * Deletes the dynamically assigned content of a variable (e.g. a member-array).
  483. * Afterwards, the variable can be safely deleted without causing memory leaks.
  484. * But the variable is not initialized and may contain old data that is not
  485. * memory-relevant.
  486. *
  487. * @param p The memory location of the variable
  488. * @param type The datatype description of the variable
  489. */
  490. void UA_EXPORT UA_deleteMembers(void *p, const UA_DataType *type);
  491. /**
  492. * Deletes (frees) a variable and all of its content.
  493. *
  494. * @param p The memory location of the variable
  495. * @param type The datatype description of the variable
  496. */
  497. void UA_EXPORT UA_delete(void *p, const UA_DataType *type);
  498. /********************/
  499. /* Array operations */
  500. /********************/
  501. #define MAX_ARRAY_SIZE 104857600 // arrays must be smaller than 100MB
  502. /**
  503. * Allocates and initializes an array of variables of a specific type
  504. *
  505. * @param size The requested array length
  506. * @param type The datatype description
  507. * @return Returns the memory location of the variable or (void*)0 if no memory could be allocated
  508. */
  509. void UA_EXPORT * UA_Array_new(size_t size, const UA_DataType *type) UA_FUNC_ATTR_MALLOC;
  510. /**
  511. * Allocates and copies an array. dst is set to (void*)0 if not enough memory is available.
  512. *
  513. * @param src The memory location of the source array
  514. * @param src_size The size of the array
  515. * @param dst The location of the pointer to the new array
  516. * @param type The datatype of the array members
  517. * @return Returns whether copying succeeded
  518. */
  519. UA_StatusCode UA_EXPORT
  520. UA_Array_copy(const void *src, size_t src_size, void **dst,
  521. const UA_DataType *type) UA_FUNC_ATTR_WARN_UNUSED_RESULT;
  522. /**
  523. * Deletes an array.
  524. *
  525. * @param p The memory location of the array
  526. * @param size The size of the array
  527. * @param type The datatype of the array members
  528. */
  529. void UA_EXPORT UA_Array_delete(void *p, size_t size, const UA_DataType *type);
  530. /**********************/
  531. /* Node Attribute Ids */
  532. /**********************/
  533. /* These are not generated from XML. Server *and* client need them. */
  534. typedef enum {
  535. UA_ATTRIBUTEID_NODEID = 1,
  536. UA_ATTRIBUTEID_NODECLASS = 2,
  537. UA_ATTRIBUTEID_BROWSENAME = 3,
  538. UA_ATTRIBUTEID_DISPLAYNAME = 4,
  539. UA_ATTRIBUTEID_DESCRIPTION = 5,
  540. UA_ATTRIBUTEID_WRITEMASK = 6,
  541. UA_ATTRIBUTEID_USERWRITEMASK = 7,
  542. UA_ATTRIBUTEID_ISABSTRACT = 8,
  543. UA_ATTRIBUTEID_SYMMETRIC = 9,
  544. UA_ATTRIBUTEID_INVERSENAME = 10,
  545. UA_ATTRIBUTEID_CONTAINSNOLOOPS = 11,
  546. UA_ATTRIBUTEID_EVENTNOTIFIER = 12,
  547. UA_ATTRIBUTEID_VALUE = 13,
  548. UA_ATTRIBUTEID_DATATYPE = 14,
  549. UA_ATTRIBUTEID_VALUERANK = 15,
  550. UA_ATTRIBUTEID_ARRAYDIMENSIONS = 16,
  551. UA_ATTRIBUTEID_ACCESSLEVEL = 17,
  552. UA_ATTRIBUTEID_USERACCESSLEVEL = 18,
  553. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL = 19,
  554. UA_ATTRIBUTEID_HISTORIZING = 20,
  555. UA_ATTRIBUTEID_EXECUTABLE = 21,
  556. UA_ATTRIBUTEID_USEREXECUTABLE = 22
  557. } UA_AttributeId;
  558. typedef enum {
  559. UA_ACCESSLEVELMASK_READ = 0x01,
  560. UA_ACCESSLEVELMASK_WRITE = 0x02,
  561. UA_ACCESSLEVELMASK_HISTORYREAD = 0x4,
  562. UA_ACCESSLEVELMASK_HISTORYWRITE = 0x08,
  563. UA_ACCESSLEVELMASK_SEMANTICCHANGE = 0x10
  564. } UA_AccessLevelMask;
  565. /***************************/
  566. /* Random Number Generator */
  567. /***************************/
  568. /**
  569. * If UA_ENABLE_MULTITHREADING is defined, then the seed is stored in thread local
  570. * storage. The seed is initialized for every thread in the server/client.
  571. */
  572. UA_EXPORT void UA_random_seed(UA_UInt64 seed);
  573. #ifdef __cplusplus
  574. } // extern "C"
  575. #endif
  576. #endif /* UA_TYPES_H_ */