ua_types.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825
  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. #ifndef UA_FFI_BINDINGS
  21. #include <inttypes.h>
  22. #include <stdbool.h>
  23. #include <stddef.h>
  24. #include <string.h>
  25. #endif
  26. #include "ua_config.h"
  27. #include "ua_statuscodes.h"
  28. /** A two-state logical value (true or false). */
  29. typedef bool UA_Boolean;
  30. #define UA_TRUE true
  31. #define UA_FALSE false
  32. /** An integer value between -128 and 127. */
  33. typedef int8_t UA_SByte;
  34. #define UA_SBYTE_MAX 127
  35. #define UA_SBYTE_MIN -128
  36. /** An integer value between 0 and 256. */
  37. typedef uint8_t UA_Byte;
  38. #define UA_BYTE_MAX 256
  39. #define UA_BYTE_MIN 0
  40. /** An integer value between -32 768 and 32 767. */
  41. typedef int16_t UA_Int16;
  42. #define UA_INT16_MAX 32767
  43. #define UA_INT16_MIN -32768
  44. /** An integer value between 0 and 65 535. */
  45. typedef uint16_t UA_UInt16;
  46. #define UA_UINT16_MAX 65535
  47. #define UA_UINT16_MIN 0
  48. /** An integer value between -2 147 483 648 and 2 147 483 647. */
  49. typedef int32_t UA_Int32;
  50. #define UA_INT32_MAX 2147483647
  51. #define UA_INT32_MIN -2147483648
  52. /** An integer value between 0 and 429 4967 295. */
  53. typedef uint32_t UA_UInt32;
  54. #define UA_UINT32_MAX 4294967295
  55. #define UA_UINT32_MIN 0
  56. /** An integer value between -10 223 372 036 854 775 808 and 9 223 372 036 854 775 807 */
  57. typedef int64_t UA_Int64;
  58. #define UA_INT64_MAX (int64_t)9223372036854775807
  59. #define UA_INT64_MIN (int64_t)-9223372036854775808
  60. /** An integer value between 0 and 18 446 744 073 709 551 615. */
  61. typedef uint64_t UA_UInt64;
  62. #define UA_UINT64_MAX (int64_t)18446744073709551615
  63. #define UA_UINT64_MIN (int64_t)0
  64. /** An IEEE single precision (32 bit) floating point value. */
  65. typedef float UA_Float;
  66. /** An IEEE double precision (64 bit) floating point value. */
  67. typedef double UA_Double;
  68. /** A sequence of Unicode characters. */
  69. typedef struct {
  70. UA_Int32 length; ///< The length of the string
  71. UA_Byte *data; ///< The string's content (not null-terminated)
  72. } UA_String;
  73. /** An instance in time. A DateTime value is encoded as a 64-bit signed integer which represents the
  74. number of 100 nanosecond intervals since January 1, 1601 (UTC). */
  75. typedef UA_Int64 UA_DateTime;
  76. /** A 16 byte value that can be used as a globally unique identifier. */
  77. typedef struct {
  78. UA_UInt32 data1;
  79. UA_UInt16 data2;
  80. UA_UInt16 data3;
  81. UA_Byte data4[8];
  82. } UA_Guid;
  83. /** A sequence of octets. */
  84. typedef UA_String UA_ByteString;
  85. /** An XML element. */
  86. typedef UA_String UA_XmlElement;
  87. enum UA_NodeIdType {
  88. UA_NODEIDTYPE_NUMERIC = 2,
  89. UA_NODEIDTYPE_STRING = 3,
  90. UA_NODEIDTYPE_GUID = 4,
  91. UA_NODEIDTYPE_BYTESTRING = 5
  92. };
  93. /** An identifier for a node in the address space of an OPC UA Server. The shortened numeric types
  94. are introduced during encoding. */
  95. typedef struct {
  96. UA_UInt16 namespaceIndex; ///< The namespace index of the node
  97. enum UA_NodeIdType identifierType; ///< The type of the node identifier
  98. union {
  99. UA_UInt32 numeric;
  100. UA_String string;
  101. UA_Guid guid;
  102. UA_ByteString byteString;
  103. } identifier; ///< The node identifier
  104. } UA_NodeId;
  105. /** A NodeId that allows the namespace URI to be specified instead of an index. */
  106. typedef struct {
  107. UA_NodeId nodeId; ///< The nodeid without extensions
  108. UA_String namespaceUri; ///< The Uri of the namespace (tindex in the nodeId is ignored)
  109. UA_UInt32 serverIndex; ///< The index of the server
  110. } UA_ExpandedNodeId;
  111. /** 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. /** 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. /** A structure that contains an application specific data type that may not be recognized by the
  122. 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. /* Forward Declaration of UA_DataType */
  133. struct UA_DataType;
  134. typedef struct UA_DataType UA_DataType;
  135. /* NumericRanges are used select a subset in a (multidimensional) variant array.
  136. * NumericRange has no official type structure in the standard. On the wire, it
  137. * only exists as an encoded string, such as "1:2,0:3,5". The colon separates
  138. * min/max index and the comma separates dimensions. A single value indicates a
  139. * range with a single element (min==max). */
  140. typedef struct {
  141. UA_Int32 dimensionsSize;
  142. struct UA_NumericRangeDimension {
  143. UA_UInt32 min;
  144. UA_UInt32 max;
  145. } *dimensions;
  146. } UA_NumericRange;
  147. /** Variants store (arrays of) any data type. Either they provide a pointer to the data in
  148. * memory, or functions from which the data can be accessed. Variants are replaced together with
  149. * the data they store (exception: use a data source).
  150. *
  151. * Variant semantics:
  152. * - arrayLength = -1 && data == NULL: empty variant
  153. * - arrayLength = -1 && data == !NULL: variant holds a single element (a scalar)
  154. * - arrayLength >= 0: variant holds an array of the appropriate length
  155. * data can be NULL if arrayLength == 0
  156. */
  157. typedef struct {
  158. const UA_DataType *type; ///< The nodeid of the datatype
  159. enum {
  160. UA_VARIANT_DATA, ///< The data is "owned" by this variant (copied and deleted together)
  161. UA_VARIANT_DATA_NODELETE, /**< The data is "borrowed" by the variant and shall not be
  162. deleted at the end of this variant's lifecycle. It is not
  163. possible to overwrite borrowed data due to concurrent access.
  164. Use a custom datasource with a mutex. */
  165. } storageType; ///< Shall the data be deleted together with the variant
  166. UA_Int32 arrayLength; ///< the number of elements in the data-pointer
  167. void *data; ///< points to the scalar or array data
  168. UA_Int32 arrayDimensionsSize; ///< the number of dimensions the data-array has
  169. UA_Int32 *arrayDimensions; ///< the length of each dimension of the data-array
  170. } UA_Variant;
  171. /** A data value with an associated status code and timestamps. */
  172. typedef struct {
  173. UA_Boolean hasValue : 1;
  174. UA_Boolean hasStatus : 1;
  175. UA_Boolean hasSourceTimestamp : 1;
  176. UA_Boolean hasServerTimestamp : 1;
  177. UA_Boolean hasSourcePicoseconds : 1;
  178. UA_Boolean hasServerPicoseconds : 1;
  179. UA_Variant value;
  180. UA_StatusCode status;
  181. UA_DateTime sourceTimestamp;
  182. UA_Int16 sourcePicoseconds;
  183. UA_DateTime serverTimestamp;
  184. UA_Int16 serverPicoseconds;
  185. } UA_DataValue;
  186. /** A structure that contains detailed error and diagnostic information associated with a StatusCode. */
  187. typedef struct UA_DiagnosticInfo {
  188. UA_Boolean hasSymbolicId : 1;
  189. UA_Boolean hasNamespaceUri : 1;
  190. UA_Boolean hasLocalizedText : 1;
  191. UA_Boolean hasLocale : 1;
  192. UA_Boolean hasAdditionalInfo : 1;
  193. UA_Boolean hasInnerStatusCode : 1;
  194. UA_Boolean hasInnerDiagnosticInfo : 1;
  195. UA_Int32 symbolicId;
  196. UA_Int32 namespaceUri;
  197. UA_Int32 localizedText;
  198. UA_Int32 locale;
  199. UA_String additionalInfo;
  200. UA_StatusCode innerStatusCode;
  201. struct UA_DiagnosticInfo *innerDiagnosticInfo;
  202. } UA_DiagnosticInfo;
  203. /***************************/
  204. /* Type Handling Functions */
  205. /***************************/
  206. /* Boolean */
  207. UA_Boolean UA_EXPORT * UA_Boolean_new(void);
  208. static UA_INLINE void UA_Boolean_init(UA_Boolean *p) { *p = UA_FALSE; }
  209. void UA_EXPORT UA_Boolean_delete(UA_Boolean *p);
  210. static UA_INLINE void UA_Boolean_deleteMembers(UA_Boolean *p) { }
  211. static UA_INLINE UA_StatusCode UA_Boolean_copy(const UA_Boolean *src, UA_Boolean *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  212. /* SByte */
  213. UA_SByte UA_EXPORT * UA_SByte_new(void);
  214. static UA_INLINE void UA_SByte_init(UA_SByte *p) { *p = 0; }
  215. void UA_EXPORT UA_SByte_delete(UA_SByte *p);
  216. static UA_INLINE void UA_SByte_deleteMembers(UA_SByte *p) { }
  217. static UA_INLINE UA_StatusCode UA_SByte_copy(const UA_SByte *src, UA_SByte *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  218. /* Byte */
  219. UA_Byte UA_EXPORT * UA_Byte_new(void);
  220. static UA_INLINE void UA_Byte_init(UA_Byte *p) { *p = 0; }
  221. void UA_EXPORT UA_Byte_delete(UA_Byte *p);
  222. static UA_INLINE void UA_Byte_deleteMembers(UA_Byte *p) { }
  223. static UA_INLINE UA_StatusCode UA_Byte_copy(const UA_Byte *src, UA_Byte *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  224. /* Int16 */
  225. UA_Int16 UA_EXPORT * UA_Int16_new(void);
  226. static UA_INLINE void UA_Int16_init(UA_Int16 *p) { *p = 0; }
  227. void UA_EXPORT UA_Int16_delete(UA_Int16 *p);
  228. static UA_INLINE void UA_Int16_deleteMembers(UA_Int16 *p) { }
  229. static UA_INLINE UA_StatusCode UA_Int16_copy(const UA_Int16 *src, UA_Int16 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  230. /* UInt16 */
  231. UA_UInt16 UA_EXPORT * UA_UInt16_new(void);
  232. static UA_INLINE void UA_UInt16_init(UA_UInt16 *p) { *p = 0; }
  233. void UA_EXPORT UA_UInt16_delete(UA_UInt16 *p);
  234. static UA_INLINE void UA_UInt16_deleteMembers(UA_UInt16 *p) { }
  235. static UA_INLINE UA_StatusCode UA_UInt16_copy(const UA_UInt16 *src, UA_UInt16 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  236. /* Int32 */
  237. UA_Int32 UA_EXPORT * UA_Int32_new(void);
  238. static UA_INLINE void UA_Int32_init(UA_Int32 *p) { *p = 0; }
  239. void UA_EXPORT UA_Int32_delete(UA_Int32 *p);
  240. static UA_INLINE void UA_Int32_deleteMembers(UA_Int32 *p) { }
  241. static UA_INLINE UA_StatusCode UA_Int32_copy(const UA_Int32 *src, UA_Int32 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  242. /* UInt32 */
  243. UA_UInt32 UA_EXPORT * UA_UInt32_new(void);
  244. static UA_INLINE void UA_UInt32_init(UA_UInt32 *p) { *p = 0; }
  245. void UA_EXPORT UA_UInt32_delete(UA_UInt32 *p);
  246. static UA_INLINE void UA_UInt32_deleteMembers(UA_UInt32 *p) { }
  247. static UA_INLINE UA_StatusCode UA_UInt32_copy(const UA_UInt32 *src, UA_UInt32 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  248. /* Int64 */
  249. UA_Int64 UA_EXPORT * UA_Int64_new(void);
  250. static UA_INLINE void UA_Int64_init(UA_Int64 *p) { *p = 0; }
  251. void UA_EXPORT UA_Int64_delete(UA_Int64 *p);
  252. static UA_INLINE void UA_Int64_deleteMembers(UA_Int64 *p) { }
  253. static UA_INLINE UA_StatusCode UA_Int64_copy(const UA_Int64 *src, UA_Int64 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  254. /* UInt64 */
  255. UA_UInt64 UA_EXPORT * UA_UInt64_new(void);
  256. static UA_INLINE void UA_UInt64_init(UA_UInt64 *p) { *p = 0; }
  257. void UA_EXPORT UA_UInt64_delete(UA_UInt64 *p);
  258. static UA_INLINE void UA_UInt64_deleteMembers(UA_UInt64 *p) { }
  259. static UA_INLINE UA_StatusCode UA_UInt64_copy(const UA_UInt64 *src, UA_UInt64 *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  260. /* Float */
  261. UA_Float UA_EXPORT * UA_Float_new(void);
  262. static UA_INLINE void UA_Float_init(UA_Float *p) { *p = 0.0f; }
  263. void UA_EXPORT UA_Float_delete(UA_Float *p);
  264. static UA_INLINE void UA_Float_deleteMembers(UA_Float *p) { }
  265. static UA_INLINE UA_StatusCode UA_Float_copy(const UA_Float *src, UA_Float *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  266. /* Double */
  267. UA_Double UA_EXPORT * UA_Double_new(void);
  268. static UA_INLINE void UA_Double_init(UA_Double *p) { *p = 0.0f; }
  269. void UA_EXPORT UA_Double_delete(UA_Double *p);
  270. static UA_INLINE void UA_Double_deleteMembers(UA_Double *p) { }
  271. static UA_INLINE UA_StatusCode UA_Double_copy(const UA_Double *src, UA_Double *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  272. /* String */
  273. UA_String UA_EXPORT * UA_String_new(void);
  274. void UA_EXPORT UA_String_init(UA_String *p);
  275. void UA_EXPORT UA_String_delete(UA_String *p);
  276. void UA_EXPORT UA_String_deleteMembers(UA_String *p);
  277. UA_StatusCode UA_EXPORT UA_String_copy(const UA_String *src, UA_String *dst);
  278. UA_String UA_EXPORT UA_String_fromChars(char const src[]); ///> Copies the content on the heap. Returns a null-string when alloc fails.
  279. UA_Boolean UA_EXPORT UA_String_equal(const UA_String *s1, const UA_String *s2); ///> Compares two strings
  280. UA_StatusCode UA_EXPORT UA_String_copyprintf(char const fmt[], UA_String *dst, ...); ///> Printf a char-array into a UA_String. Memory for the string data is allocated.
  281. UA_EXPORT extern const UA_String UA_STRING_NULL;
  282. static UA_INLINE UA_String UA_STRING(char *chars) {
  283. UA_String str;
  284. str.length = strlen(chars);
  285. str.data = (UA_Byte*)chars;
  286. return str; }
  287. #define UA_STRING_ALLOC(CHARS) UA_String_fromChars(CHARS)
  288. /* DateTime */
  289. UA_DateTime UA_EXPORT * UA_DateTime_new(void);
  290. static UA_INLINE void UA_DateTime_init(UA_DateTime *p) { *p = (UA_DateTime)0.0f; }
  291. void UA_EXPORT UA_DateTime_delete(UA_DateTime *p);
  292. static UA_INLINE void UA_DateTime_deleteMembers(UA_DateTime *p) { }
  293. static UA_INLINE UA_StatusCode UA_DateTime_copy(const UA_DateTime *src, UA_DateTime *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  294. UA_DateTime UA_EXPORT UA_DateTime_now(void); ///> The current time
  295. UA_StatusCode UA_EXPORT UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
  296. typedef struct UA_DateTimeStruct {
  297. UA_Int16 nanoSec;
  298. UA_Int16 microSec;
  299. UA_Int16 milliSec;
  300. UA_Int16 sec;
  301. UA_Int16 min;
  302. UA_Int16 hour;
  303. UA_Int16 day;
  304. UA_Int16 month;
  305. UA_Int16 year;
  306. } UA_DateTimeStruct;
  307. UA_DateTimeStruct UA_EXPORT UA_DateTime_toStruct(UA_DateTime time);
  308. /* Guid */
  309. UA_Guid UA_EXPORT * UA_Guid_new(void);
  310. static UA_INLINE void UA_Guid_init(UA_Guid *p) { memset(p, 0, sizeof(UA_Guid)); }
  311. void UA_EXPORT UA_Guid_delete(UA_Guid *p);
  312. static UA_INLINE void UA_Guid_deleteMembers(UA_Guid *p) { }
  313. static UA_INLINE UA_StatusCode UA_Guid_copy(const UA_Guid *src, UA_Guid *dst) { *dst = *src; return UA_STATUSCODE_GOOD; }
  314. UA_Boolean UA_EXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
  315. UA_Guid UA_EXPORT UA_Guid_random(UA_UInt32 *seed); ///> Do not use for security-critical entropy!
  316. /* ByteString */
  317. static UA_INLINE UA_ByteString * UA_ByteString_new(void) { return UA_String_new(); }
  318. static UA_INLINE void UA_ByteString_init(UA_ByteString *p) { UA_String_init(p); }
  319. static UA_INLINE void UA_ByteString_delete(UA_ByteString *p) { UA_String_delete(p); }
  320. static UA_INLINE void UA_ByteString_deleteMembers(UA_ByteString *p) { UA_String_deleteMembers(p); }
  321. static UA_INLINE UA_StatusCode UA_ByteString_copy(const UA_ByteString *src, UA_ByteString *dst) {
  322. return UA_String_copy(src, dst); }
  323. #define UA_ByteString_equal(string1, string2) UA_String_equal((const UA_String*) string1, (const UA_String*)string2)
  324. /* Allocates memory of size length for the bytestring. The content is not set to zero. */
  325. UA_StatusCode UA_EXPORT UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length);
  326. UA_EXPORT extern const UA_ByteString UA_BYTESTRING_NULL;
  327. static UA_INLINE UA_ByteString UA_BYTESTRING(char *chars) {
  328. UA_ByteString str;
  329. str.length = strlen(chars);
  330. str.data = (UA_Byte*)chars;
  331. return str; }
  332. static UA_INLINE UA_ByteString UA_BYTESTRING_ALLOC(const char *chars) {
  333. UA_String str = UA_String_fromChars(chars);
  334. UA_ByteString bstr;
  335. bstr.length = str.length;
  336. bstr.data = str.data;
  337. return bstr;
  338. }
  339. /* XmlElement */
  340. static UA_INLINE UA_XmlElement * UA_XmlElement_new(void) { return UA_String_new(); }
  341. static UA_INLINE void UA_XmlElement_init(UA_XmlElement *p) { UA_String_init(p); }
  342. static UA_INLINE void UA_XmlElement_delete(UA_XmlElement *p) { UA_String_delete(p); }
  343. static UA_INLINE void UA_XmlElement_deleteMembers(UA_XmlElement *p) { UA_String_deleteMembers(p); }
  344. static UA_INLINE UA_StatusCode UA_XmlElement_copy(const UA_XmlElement *src, UA_XmlElement *dst) {
  345. return UA_String_copy(src, dst); }
  346. /* NodeId */
  347. UA_NodeId UA_EXPORT * UA_NodeId_new(void);
  348. void UA_EXPORT UA_NodeId_init(UA_NodeId *p);
  349. void UA_EXPORT UA_NodeId_delete(UA_NodeId *p);
  350. void UA_EXPORT UA_NodeId_deleteMembers(UA_NodeId *p);
  351. UA_StatusCode UA_EXPORT UA_NodeId_copy(const UA_NodeId *src, UA_NodeId *dst);
  352. UA_Boolean UA_EXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
  353. UA_Boolean UA_EXPORT UA_NodeId_isNull(const UA_NodeId *p);
  354. UA_NodeId UA_EXPORT UA_NodeId_fromInteger(UA_UInt16 nsIndex, UA_Int32 identifier);
  355. UA_NodeId UA_EXPORT UA_NodeId_fromCharString(UA_UInt16 nsIndex, char identifier[]);
  356. UA_NodeId UA_EXPORT UA_NodeId_fromCharStringCopy(UA_UInt16 nsIndex, char const identifier[]);
  357. UA_NodeId UA_EXPORT UA_NodeId_fromString(UA_UInt16 nsIndex, UA_String identifier);
  358. UA_NodeId UA_EXPORT UA_NodeId_fromStringCopy(UA_UInt16 nsIndex, UA_String identifier);
  359. UA_NodeId UA_EXPORT UA_NodeId_fromGuid(UA_UInt16 nsIndex, UA_Guid identifier);
  360. UA_NodeId UA_EXPORT UA_NodeId_fromCharByteString(UA_UInt16 nsIndex, char identifier[]);
  361. UA_NodeId UA_EXPORT UA_NodeId_fromCharByteStringCopy(UA_UInt16 nsIndex, char const identifier[]);
  362. UA_NodeId UA_EXPORT UA_NodeId_fromByteString(UA_UInt16 nsIndex, UA_ByteString identifier);
  363. UA_NodeId UA_EXPORT UA_NodeId_fromByteStringCopy(UA_UInt16 nsIndex, UA_ByteString identifier);
  364. UA_EXPORT extern const UA_NodeId UA_NODEID_NULL;
  365. static UA_INLINE UA_NodeId UA_NODEID_NUMERIC(UA_UInt16 nsIndex, UA_Int32 identifier) {
  366. UA_NodeId id;
  367. id.namespaceIndex = nsIndex;
  368. id.identifierType = UA_NODEIDTYPE_NUMERIC;
  369. id.identifier.numeric = identifier;
  370. return id; }
  371. static UA_INLINE UA_NodeId UA_NODEID_STRING(UA_UInt16 nsIndex, char *chars) {
  372. UA_NodeId id;
  373. id.namespaceIndex = nsIndex;
  374. id.identifierType = UA_NODEIDTYPE_STRING;
  375. id.identifier.string = UA_STRING(chars);
  376. return id; }
  377. static UA_INLINE UA_NodeId UA_NODEID_STRING_ALLOC(UA_UInt16 nsIndex, char *chars) {
  378. UA_NodeId id;
  379. id.namespaceIndex = nsIndex;
  380. id.identifierType = UA_NODEIDTYPE_STRING;
  381. id.identifier.string = UA_STRING_ALLOC(chars);
  382. return id; }
  383. static UA_INLINE UA_NodeId UA_NODEID_GUID(UA_UInt16 nsIndex, UA_Guid guid) {
  384. UA_NodeId id;
  385. id.namespaceIndex = nsIndex;
  386. id.identifierType = UA_NODEIDTYPE_GUID;
  387. id.identifier.guid = guid;
  388. return id; }
  389. static UA_INLINE UA_NodeId UA_NODEID_BYTESTRING(UA_UInt16 nsIndex, char *chars) {
  390. UA_NodeId id;
  391. id.namespaceIndex = nsIndex;
  392. id.identifierType = UA_NODEIDTYPE_BYTESTRING;
  393. id.identifier.byteString = UA_BYTESTRING(chars);
  394. return id; }
  395. static UA_INLINE UA_NodeId UA_NODEID_BYTESTRING_ALLOC(UA_UInt16 nsIndex, char *chars) {
  396. UA_NodeId id;
  397. id.namespaceIndex = nsIndex;
  398. id.identifierType = UA_NODEIDTYPE_BYTESTRING;
  399. id.identifier.byteString = UA_BYTESTRING_ALLOC(chars);
  400. return id; }
  401. /* ExpandedNodeId */
  402. UA_ExpandedNodeId UA_EXPORT * UA_ExpandedNodeId_new(void);
  403. void UA_EXPORT UA_ExpandedNodeId_init(UA_ExpandedNodeId *p);
  404. void UA_EXPORT UA_ExpandedNodeId_delete(UA_ExpandedNodeId *p);
  405. void UA_EXPORT UA_ExpandedNodeId_deleteMembers(UA_ExpandedNodeId *p);
  406. UA_StatusCode UA_EXPORT UA_ExpandedNodeId_copy(const UA_ExpandedNodeId *src, UA_ExpandedNodeId *dst);
  407. UA_Boolean UA_EXPORT UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
  408. UA_EXPORT extern const UA_ExpandedNodeId UA_EXPANDEDNODEID_NULL;
  409. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_NUMERIC(UA_UInt16 nsIndex, UA_Int32 identifier) {
  410. UA_ExpandedNodeId id;
  411. id.nodeId = UA_NODEID_NUMERIC(nsIndex, identifier);
  412. id.serverIndex = 0;
  413. id.namespaceUri = UA_STRING_NULL;
  414. return id; }
  415. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_STRING(UA_UInt16 nsIndex, char *chars) {
  416. UA_ExpandedNodeId id;
  417. id.nodeId = UA_NODEID_STRING(nsIndex, chars);
  418. id.serverIndex = 0;
  419. id.namespaceUri = UA_STRING_NULL;
  420. return id; }
  421. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_STRING_ALLOC(UA_UInt16 nsIndex, char *chars) {
  422. UA_ExpandedNodeId id;
  423. id.nodeId = UA_NODEID_STRING_ALLOC(nsIndex, chars);
  424. id.serverIndex = 0;
  425. id.namespaceUri = UA_STRING_NULL;
  426. return id; }
  427. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_STRING_GUID(UA_UInt16 nsIndex, UA_Guid guid) {
  428. UA_ExpandedNodeId id;
  429. id.nodeId = UA_NODEID_GUID(nsIndex, guid);
  430. id.serverIndex = 0;
  431. id.namespaceUri = UA_STRING_NULL;
  432. return id; }
  433. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_BYTESTRING(UA_UInt16 nsIndex, char *chars) {
  434. UA_ExpandedNodeId id;
  435. id.nodeId = UA_NODEID_BYTESTRING(nsIndex, chars);
  436. id.serverIndex = 0;
  437. id.namespaceUri = UA_STRING_NULL;
  438. return id; }
  439. static UA_INLINE UA_ExpandedNodeId UA_EXPANDEDNODEID_BYTESTRING_ALLOC(UA_UInt16 nsIndex, char *chars) {
  440. UA_ExpandedNodeId id;
  441. id.nodeId = UA_NODEID_BYTESTRING_ALLOC(nsIndex, chars);
  442. id.serverIndex = 0;
  443. id.namespaceUri = UA_STRING_NULL;
  444. return id; }
  445. /* StatusCode */
  446. UA_StatusCode UA_EXPORT * UA_StatusCode_new(void);
  447. static UA_INLINE void UA_StatusCode_init(UA_StatusCode *p) { *p = UA_STATUSCODE_GOOD; }
  448. void UA_EXPORT UA_StatusCode_delete(UA_StatusCode *p);
  449. static UA_INLINE void UA_StatusCode_deleteMembers(UA_StatusCode *p) { }
  450. static UA_INLINE UA_StatusCode UA_StatusCode_copy(const UA_StatusCode *src, UA_StatusCode *dst) {
  451. *dst = *src; return UA_STATUSCODE_GOOD; }
  452. /* QualifiedName */
  453. UA_QualifiedName UA_EXPORT * UA_QualifiedName_new(void);
  454. void UA_EXPORT UA_QualifiedName_init(UA_QualifiedName *p);
  455. void UA_EXPORT UA_QualifiedName_delete(UA_QualifiedName *p);
  456. void UA_EXPORT UA_QualifiedName_deleteMembers(UA_QualifiedName *p);
  457. UA_StatusCode UA_EXPORT UA_QualifiedName_copy(const UA_QualifiedName *src, UA_QualifiedName *dst);
  458. static UA_INLINE UA_QualifiedName UA_QUALIFIEDNAME(UA_UInt16 nsIndex, char *chars) {
  459. UA_QualifiedName qn;
  460. qn.namespaceIndex = nsIndex;
  461. qn.name = UA_STRING(chars);
  462. return qn; }
  463. static UA_INLINE UA_QualifiedName UA_QUALIFIEDNAME_ALLOC(UA_UInt16 nsIndex, char *chars) {
  464. UA_QualifiedName qn;
  465. qn.namespaceIndex = nsIndex;
  466. qn.name = UA_STRING_ALLOC(chars);
  467. return qn; }
  468. /* LocalizedText */
  469. UA_LocalizedText UA_EXPORT * UA_LocalizedText_new(void);
  470. void UA_EXPORT UA_LocalizedText_init(UA_LocalizedText *p);
  471. void UA_EXPORT UA_LocalizedText_delete(UA_LocalizedText *p);
  472. void UA_EXPORT UA_LocalizedText_deleteMembers(UA_LocalizedText *p);
  473. UA_StatusCode UA_EXPORT UA_LocalizedText_copy(const UA_LocalizedText *src, UA_LocalizedText *dst);
  474. static UA_INLINE UA_LocalizedText UA_LOCALIZEDTEXT(char *locale, char *text) {
  475. UA_LocalizedText lt;
  476. lt.locale = UA_STRING(locale);
  477. lt.text = UA_STRING(text);
  478. return lt; }
  479. static UA_INLINE UA_LocalizedText UA_LOCALIZEDTEXT_ALLOC(char *locale, char *text) {
  480. UA_LocalizedText lt;
  481. lt.locale = UA_STRING_ALLOC(locale);
  482. lt.text = UA_STRING_ALLOC(text);
  483. return lt; }
  484. /* ExtensionObject */
  485. UA_ExtensionObject UA_EXPORT * UA_ExtensionObject_new(void);
  486. void UA_EXPORT UA_ExtensionObject_init(UA_ExtensionObject *p);
  487. void UA_EXPORT UA_ExtensionObject_delete(UA_ExtensionObject *p);
  488. void UA_EXPORT UA_ExtensionObject_deleteMembers(UA_ExtensionObject *p);
  489. UA_StatusCode UA_EXPORT UA_ExtensionObject_copy(const UA_ExtensionObject *src, UA_ExtensionObject *dst);
  490. /* Variant */
  491. UA_Variant UA_EXPORT * UA_Variant_new(void);
  492. void UA_EXPORT UA_Variant_init(UA_Variant *p);
  493. void UA_EXPORT UA_Variant_delete(UA_Variant *p);
  494. void UA_EXPORT UA_Variant_deleteMembers(UA_Variant *p);
  495. UA_StatusCode UA_EXPORT UA_Variant_copy(const UA_Variant *src, UA_Variant *dst);
  496. /**
  497. * Returns true if the variant contains a scalar value. Note that empty variants contain an array of
  498. * length -1 (undefined).
  499. *
  500. * @param v The variant
  501. * @return Does the variant contain a scalar value.
  502. */
  503. UA_Boolean UA_EXPORT UA_Variant_isScalar(const UA_Variant *v);
  504. /**
  505. * Set the variant to a scalar value that already resides in memory. The value takes on the
  506. * lifecycle of the variant and is deleted with it.
  507. *
  508. * @param v The variant
  509. * @param p A pointer to the value data
  510. * @param type The datatype of the value in question
  511. * @return Indicates whether the operation succeeded or returns an error code
  512. */
  513. UA_StatusCode UA_EXPORT UA_Variant_setScalar(UA_Variant *v, void *p, const UA_DataType *type);
  514. /**
  515. * Set the variant to a scalar value that is copied from an existing variable.
  516. *
  517. * @param v The variant
  518. * @param p A pointer to the value data
  519. * @param type The datatype of the value
  520. * @return Indicates whether the operation succeeded or returns an error code
  521. */
  522. UA_StatusCode UA_EXPORT UA_Variant_setScalarCopy(UA_Variant *v, const void *p, const UA_DataType *type);
  523. /**
  524. * Set the variant to an array that already resides in memory. The array takes on the lifecycle of
  525. * the variant and is deleted with it.
  526. *
  527. * @param v The variant
  528. * @param array A pointer to the array data
  529. * @param elements The size of the array
  530. * @param type The datatype of the array
  531. * @return Indicates whether the operation succeeded or returns an error code
  532. */
  533. UA_StatusCode UA_EXPORT
  534. UA_Variant_setArray(UA_Variant *v, void *array, UA_Int32 elements, const UA_DataType *type);
  535. /**
  536. * Set the variant to an array that is copied from an existing array.
  537. *
  538. * @param v The variant
  539. * @param array A pointer to the array data
  540. * @param elements The size of the array
  541. * @param type The datatype of the array
  542. * @return Indicates whether the operation succeeded or returns an error code
  543. */
  544. UA_StatusCode UA_EXPORT
  545. UA_Variant_setArrayCopy(UA_Variant *v, const void *array, UA_Int32 elements, const UA_DataType *type);
  546. /**
  547. * Copy the variant, but use only a subset of the (multidimensional) array into a variant. Returns
  548. * an error code if the variant is not an array or if the indicated range does not fit.
  549. *
  550. * @param src The source variant
  551. * @param dst The target variant
  552. * @param range The range of the copied data
  553. * @return Returns UA_STATUSCODE_GOOD or an error code
  554. */
  555. UA_StatusCode UA_EXPORT
  556. UA_Variant_copyRange(const UA_Variant *src, UA_Variant *dst, const UA_NumericRange range);
  557. /**
  558. * Insert a range of data into an existing variant. The data array can't be reused afterwards if it
  559. * contains types without a fixed size (e.g. strings) since the members are moved into the variant
  560. * and take on its lifecycle.
  561. *
  562. * @param v The variant
  563. * @param dataArray The data array. The type must match the variant
  564. * @param dataArraySize The length of the data array. This is checked to match the range size.
  565. * @param range The range of where the new data is inserted
  566. * @return Returns UA_STATUSCODE_GOOD or an error code
  567. */
  568. UA_StatusCode UA_EXPORT
  569. UA_Variant_setRange(UA_Variant *v, void *dataArray, UA_Int32 dataArraySize, const UA_NumericRange range);
  570. /**
  571. * Deep-copy a range of data into an existing variant.
  572. *
  573. * @param v The variant
  574. * @param dataArray The data array. The type must match the variant
  575. * @param dataArraySize The length of the data array. This is checked to match the range size.
  576. * @param range The range of where the new data is inserted
  577. * @return Returns UA_STATUSCODE_GOOD or an error code
  578. */
  579. UA_StatusCode UA_EXPORT
  580. UA_Variant_setRangeCopy(UA_Variant *v, const void *dataArray, UA_Int32 dataArraySize,
  581. const UA_NumericRange range);
  582. /* DataValue */
  583. UA_DataValue UA_EXPORT * UA_DataValue_new(void);
  584. void UA_EXPORT UA_DataValue_init(UA_DataValue *p);
  585. void UA_EXPORT UA_DataValue_delete(UA_DataValue *p);
  586. void UA_EXPORT UA_DataValue_deleteMembers(UA_DataValue *p);
  587. UA_StatusCode UA_EXPORT UA_DataValue_copy(const UA_DataValue *src, UA_DataValue *dst);
  588. /* DiagnosticInfo */
  589. UA_DiagnosticInfo UA_EXPORT * UA_DiagnosticInfo_new(void);
  590. void UA_EXPORT UA_DiagnosticInfo_init(UA_DiagnosticInfo *p);
  591. void UA_EXPORT UA_DiagnosticInfo_delete(UA_DiagnosticInfo *p);
  592. void UA_EXPORT UA_DiagnosticInfo_deleteMembers(UA_DiagnosticInfo *p);
  593. UA_StatusCode UA_EXPORT UA_DiagnosticInfo_copy(const UA_DiagnosticInfo *src, UA_DiagnosticInfo *dst);
  594. /****************************/
  595. /* Structured Type Handling */
  596. /****************************/
  597. #define UA_MAX_TYPE_MEMBERS 13 // Maximum number of members per complex type
  598. #define UA_IS_BUILTIN(ID) (ID <= UA_TYPES_DIAGNOSTICINFO)
  599. typedef struct {
  600. #ifdef ENABLE_TYPEINTROSPECTION
  601. const char *memberName;
  602. #endif
  603. UA_UInt16 memberTypeIndex; ///< Index of the member in the datatypetable
  604. UA_Byte padding; /**< How much padding is there before this member element? For arrays this is
  605. split into 2 bytes padding before the length index (max 4 bytes) and 3
  606. bytes padding before the pointer (max 8 bytes) */
  607. UA_Boolean namespaceZero : 1; /**< The type of the member is defined in namespace zero. In this
  608. implementation, types from custom namespace may contain
  609. members from the same namespace or ns0 only.*/
  610. UA_Boolean isArray : 1; ///< The member is an array of the given type
  611. } UA_DataTypeMember;
  612. struct UA_DataType {
  613. #ifdef ENABLE_TYPEINTROSPECTION
  614. const char *typeName;
  615. #endif
  616. UA_NodeId typeId; ///< The nodeid of the type
  617. UA_UInt16 memSize; ///< Size of the struct in memory
  618. UA_UInt16 typeIndex; ///< Index of the type in the datatypetable
  619. UA_Byte membersSize; ///< How many members does the type have?
  620. UA_Boolean namespaceZero : 1; ///< The type is defined in namespace zero
  621. UA_Boolean fixedSize : 1; ///< The type (and its members contains no pointers
  622. UA_Boolean zeroCopyable : 1; ///< Can the type be copied directly off the stream?
  623. UA_DataTypeMember members[UA_MAX_TYPE_MEMBERS];
  624. };
  625. /**
  626. * Allocates and initializes a variable of type dataType
  627. *
  628. * @param dataType The datatype description
  629. * @return Returns the memory location of the variable or (void*)0 if no memory is available
  630. */
  631. void UA_EXPORT * UA_new(const UA_DataType *dataType);
  632. /**
  633. * Initializes a variable to default values
  634. *
  635. * @param p The memory location of the variable
  636. * @param dataType The datatype description
  637. */
  638. void UA_EXPORT UA_init(void *p, const UA_DataType *dataType);
  639. /**
  640. * Copies the content of two variables. If copying fails (e.g. because no memory was available for
  641. * an array), then dst is emptied and initialized to prevent memory leaks.
  642. *
  643. * @param src The memory location of the source variable
  644. * @param dst The memory location of the destination variable
  645. * @param dataType The datatype description
  646. * @return Indicates whether the operation succeeded or returns an error code
  647. */
  648. UA_StatusCode UA_EXPORT UA_copy(const void *src, void *dst, const UA_DataType *dataType);
  649. /**
  650. * Deletes the dynamically assigned content of a variable (e.g. a member-array). Afterwards, the
  651. * variable can be safely deleted without causing memory leaks. But the variable is not initialized
  652. * and may contain old data that is not memory-relevant.
  653. *
  654. * @param p The memory location of the variable
  655. * @param dataType The datatype description of the variable
  656. */
  657. void UA_EXPORT UA_deleteMembers(void *p, const UA_DataType *dataType);
  658. void UA_EXPORT UA_deleteMembersUntil(void *p, const UA_DataType *dataType, UA_Int32 lastMember);
  659. /**
  660. * Deletes (frees) a variable and all of its content.
  661. *
  662. * @param p The memory location of the variable
  663. * @param dataType The datatype description of the variable
  664. */
  665. void UA_EXPORT UA_delete(void *p, const UA_DataType *dataType);
  666. /********************/
  667. /* Array operations */
  668. /********************/
  669. #define MAX_ARRAY_SIZE 104857600 // arrays must be smaller than 100MB
  670. /**
  671. * Allocates and initializes an array of variables of a specific type
  672. *
  673. * @param dataType The datatype description
  674. * @param elements The number of elements in the array
  675. * @return Returns the memory location of the variable or (void*)0 if no memory could be allocated
  676. */
  677. void UA_EXPORT * UA_Array_new(const UA_DataType *dataType, UA_Int32 elements);
  678. /**
  679. * Allocates and copies an array. dst is set to (void*)0 if not enough memory is available.
  680. *
  681. * @param src The memory location of the source array
  682. * @param dst The memory location where the pointer to the destination array is written
  683. * @param dataType The datatype of the array members
  684. * @param elements The size of the array
  685. * @return Indicates whether the operation succeeded or returns an error code
  686. */
  687. UA_StatusCode UA_EXPORT UA_Array_copy(const void *src, void **dst, const UA_DataType *dataType, UA_Int32 elements);
  688. /**
  689. * Deletes an array.
  690. *
  691. * @param p The memory location of the array
  692. * @param dataType The datatype of the array members
  693. * @param elements The size of the array
  694. */
  695. void UA_EXPORT UA_Array_delete(void *p, const UA_DataType *dataType, UA_Int32 elements);
  696. /**********************/
  697. /* Node Attribute Ids */
  698. /**********************/
  699. /* These are not generated from XML. Server *and* client need them. */
  700. typedef enum {
  701. UA_ATTRIBUTEID_NODEID = 1,
  702. UA_ATTRIBUTEID_NODECLASS = 2,
  703. UA_ATTRIBUTEID_BROWSENAME = 3,
  704. UA_ATTRIBUTEID_DISPLAYNAME = 4,
  705. UA_ATTRIBUTEID_DESCRIPTION = 5,
  706. UA_ATTRIBUTEID_WRITEMASK = 6,
  707. UA_ATTRIBUTEID_USERWRITEMASK = 7,
  708. UA_ATTRIBUTEID_ISABSTRACT = 8,
  709. UA_ATTRIBUTEID_SYMMETRIC = 9,
  710. UA_ATTRIBUTEID_INVERSENAME = 10,
  711. UA_ATTRIBUTEID_CONTAINSNOLOOPS = 11,
  712. UA_ATTRIBUTEID_EVENTNOTIFIER = 12,
  713. UA_ATTRIBUTEID_VALUE = 13,
  714. UA_ATTRIBUTEID_DATATYPE = 14,
  715. UA_ATTRIBUTEID_VALUERANK = 15,
  716. UA_ATTRIBUTEID_ARRAYDIMENSIONS = 16,
  717. UA_ATTRIBUTEID_ACCESSLEVEL = 17,
  718. UA_ATTRIBUTEID_USERACCESSLEVEL = 18,
  719. UA_ATTRIBUTEID_MINIMUMSAMPLINGINTERVAL = 19,
  720. UA_ATTRIBUTEID_HISTORIZING = 20,
  721. UA_ATTRIBUTEID_EXECUTABLE = 21,
  722. UA_ATTRIBUTEID_USEREXECUTABLE = 22
  723. } UA_AttributeId;
  724. /***************************/
  725. /* Random Number Generator */
  726. /***************************/
  727. /**
  728. * If UA_MULTITHREADING is enabled, then the seed is stored in thread local storage. The seed is
  729. * initialized for every thread in the server/client.
  730. */
  731. UA_EXPORT void UA_random_seed(UA_UInt64 seed);
  732. UA_EXPORT UA_UInt32 UA_random(void);
  733. #ifdef __cplusplus
  734. } // extern "C"
  735. #endif
  736. #endif /* UA_TYPES_H_ */