ua_types.h 26 KB

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