ua_types.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. #ifndef UA_TYPES_H_
  2. #define UA_TYPES_H_
  3. #include <stdio.h>
  4. #include <stdint.h>
  5. /**
  6. * @defgroup types Datatypes
  7. *
  8. * @brief This module describes the datatypes used in OPC UA. There is a
  9. * division into built-in datatypes (integers, strings, etc.) and more complex
  10. * datatypes that are comprise of built-in datatypes (structs defined in the OPC
  11. * UA standard).
  12. *
  13. * All datatypes follow the same schema in the naming of relevant functions.
  14. *
  15. * - <type>_init: Sets all values to a "safe" standard. For example, if the
  16. * datatype contains a string-element, its size will be set to zero.
  17. *
  18. * - <type>_new: Allocates the memory for the type and runs <type>_init on the
  19. * returned pointer.
  20. *
  21. * - <type>_copy: Copies a datatype. This performs a deep copy that iterates
  22. * over the members.
  23. *
  24. * - <type>_delete: Frees the memory where the datatype was stored.
  25. *
  26. * - <type>_deleteMembers: Frees the memory of dynamically sized members (e.g. a
  27. * string) of a datatype. This is useful when the datatype was allocated on
  28. * the stack, whereas the dynamically sized members is heap-allocated.
  29. *
  30. * @{
  31. */
  32. /* Function return values */
  33. #define UA_SUCCESS 0
  34. #define UA_NO_ERROR UA_SUCCESS
  35. #define UA_ERROR (0x01 << 31)
  36. #define UA_ERR_INCONSISTENT (UA_ERROR | (0x01 << 1))
  37. #define UA_ERR_INVALID_VALUE (UA_ERROR | (0x01 << 2))
  38. #define UA_ERR_NO_MEMORY (UA_ERROR | (0x01 << 3))
  39. #define UA_ERR_NOT_IMPLEMENTED (UA_ERROR | (0x01 << 4))
  40. /* Boolean values and null */
  41. #define UA_TRUE (42 == 42)
  42. #define TRUE UA_TRUE
  43. #define UA_FALSE (!UA_TRUE)
  44. #define FALSE UA_FALSE
  45. /* Compare values */
  46. #define UA_EQUAL 0
  47. #define UA_NOT_EQUAL (!UA_EQUAL)
  48. /** @brief A two-state logical value (true or false). */
  49. typedef _Bool UA_Boolean;
  50. /** @brief An integer value between −128 and 127. */
  51. typedef int8_t UA_SByte;
  52. /** @brief An integer value between 0 and 256. */
  53. typedef uint8_t UA_Byte;
  54. /** @brief An integer value between −32 768 and 32 767. */
  55. typedef int16_t UA_Int16;
  56. /** @brief An integer value between 0 and 65 535. */
  57. typedef uint16_t UA_UInt16;
  58. /** @brief An integer value between −2 147 483 648 and 2 147 483 647. */
  59. typedef int32_t UA_Int32;
  60. /** @brief An integer value between 0 and 429 4967 295. */
  61. typedef uint32_t UA_UInt32;
  62. /** @brief An integer value between −9 223 372 036 854 775 808 and 9 223 372 036 854 775 807 */
  63. typedef int64_t UA_Int64;
  64. /** @brief An integer value between 0 and 18 446 744 073 709 551 615. */
  65. typedef uint64_t UA_UInt64;
  66. /** @brief An IEEE single precision (32 bit) floating point value. */
  67. typedef float UA_Float;
  68. /** @brief An IEEE double precision (64 bit) floating point value. */
  69. typedef double UA_Double;
  70. /** @brief A sequence of Unicode characters. */
  71. typedef struct UA_String {
  72. UA_Int32 length;
  73. UA_Byte *data;
  74. } UA_String;
  75. /** @brief An instance in time. */
  76. typedef UA_Int64 UA_DateTime; //100 nanosecond resolution
  77. /** @brief A 16 byte value that can be used as a globally unique identifier. */
  78. typedef struct UA_Guid {
  79. UA_UInt32 data1;
  80. UA_UInt16 data2;
  81. UA_UInt16 data3;
  82. UA_Byte data4[8];
  83. } UA_Guid;
  84. /** @brief A sequence of octets. */
  85. typedef struct UA_String UA_ByteString;
  86. /** @brief An XML element. */
  87. typedef struct UA_String UA_XmlElement;
  88. /** @brief An identifier for a node in the address space of an OPC UA Server. */
  89. typedef struct UA_NodeId {
  90. UA_Byte encodingByte; //enum BID_NodeIdEncodingValuesType
  91. UA_UInt16 namespace;
  92. union {
  93. UA_UInt32 numeric;
  94. UA_String string;
  95. UA_Guid guid;
  96. UA_ByteString byteString;
  97. } identifier;
  98. } UA_NodeId;
  99. #define NS0NODEID(NUMERIC_ID) \
  100. (UA_NodeId){.encodingByte = 0 /*UA_NODEIDTYPE_TWOBYTE*/, .namespace = 0, .identifier.numeric = NUMERIC_ID}
  101. #define UA_NODEIDTYPE_NAMESPACE_URI_FLAG 0x80
  102. #define UA_NODEIDTYPE_SERVERINDEX_FLAG 0x40
  103. #define UA_NODEIDTYPE_MASK (~(UA_NODEIDTYPE_NAMESPACE_URI_FLAG | UA_NODEIDTYPE_SERVERINDEX_FLAG))
  104. /** @brief A NodeId that allows the namespace URI to be specified instead of an index. */
  105. typedef struct UA_ExpandedNodeId {
  106. UA_NodeId nodeId;
  107. UA_String namespaceUri;
  108. UA_UInt32 serverIndex;
  109. } UA_ExpandedNodeId;
  110. #define NS0EXPANDEDNODEID(NUMERIC_ID) \
  111. (UA_ExpandedNodeId){.nodeId = NS0NODEID(NUMERIC_ID), .namespaceUri = {-1, UA_NULL}, .serverIndex = 0}
  112. /** @brief A numeric identifier for a error or condition that is associated with a value or an operation. */
  113. typedef UA_UInt32 UA_StatusCode; // StatusCodes aren't an enum(=int) since 32 unsigned bits are needed. See also ua_statuscodes.h */
  114. /** @brief A name qualified by a namespace. */
  115. typedef struct UA_QualifiedName {
  116. UA_UInt16 namespaceIndex;
  117. UA_String name;
  118. } UA_QualifiedName;
  119. /** @brief Human readable text with an optional locale identifier. */
  120. typedef struct UA_LocalizedText {
  121. UA_String locale;
  122. UA_String text;
  123. } UA_LocalizedText;
  124. enum UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_enum {
  125. UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_LOCALE = 0x01,
  126. UA_LOCALIZEDTEXT_ENCODINGMASKTYPE_TEXT = 0x02
  127. };
  128. /** @brief A structure that contains an application specific data type that may
  129. not be recognized by the receiver. */
  130. typedef struct UA_ExtensionObject {
  131. UA_NodeId typeId;
  132. UA_Byte encoding; // Type of the enum UA_ExtensionObjectEncodingMaskType
  133. UA_ByteString body; // contains either the bytestring or a pointer to the memory-object
  134. } UA_ExtensionObject;
  135. enum UA_ExtensionObject_EncodingMaskType_enum {
  136. UA_EXTENSIONOBJECT_ENCODINGMASK_NOBODYISENCODED = 0x00,
  137. UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISBYTESTRING = 0x01,
  138. UA_EXTENSIONOBJECT_ENCODINGMASK_BODYISXML = 0x02
  139. };
  140. struct UA_VTable_Entry; // forwards declaration
  141. typedef struct UA_VTable_Entry UA_VTable_Entry;
  142. /** @brief A union of all of the types specified above.
  143. *
  144. * Variants store (arrays of) built-in types. If you want to store a more
  145. * complex (or self-defined) type, you have to use an UA_ExtensionObject.*/
  146. typedef struct UA_Variant {
  147. UA_VTable_Entry *vt; // internal entry into vTable
  148. UA_Int32 arrayLength; // total number of elements
  149. void *data;
  150. UA_Int32 arrayDimensionsLength;
  151. UA_Int32 *arrayDimensions;
  152. } UA_Variant;
  153. /* VariantBinaryEncoding - Part: 6, Chapter: 5.2.2.16, Page: 22 */
  154. enum UA_VARIANT_ENCODINGMASKTYPE_enum {
  155. UA_VARIANT_ENCODINGMASKTYPE_TYPEID_MASK = 0x3F, // bits 0:5
  156. UA_VARIANT_ENCODINGMASKTYPE_DIMENSIONS = (0x01 << 6), // bit 6
  157. UA_VARIANT_ENCODINGMASKTYPE_ARRAY = (0x01 << 7) // bit 7
  158. };
  159. /** @brief A data value with an associated status code and timestamps. */
  160. typedef struct UA_DataValue {
  161. UA_Byte encodingMask;
  162. UA_Variant value;
  163. UA_StatusCode status;
  164. UA_DateTime sourceTimestamp;
  165. UA_Int16 sourcePicoseconds;
  166. UA_DateTime serverTimestamp;
  167. UA_Int16 serverPicoseconds;
  168. } UA_DataValue;
  169. enum UA_DATAVALUE_ENCODINGMASKTYPE_enum {
  170. UA_DATAVALUE_ENCODINGMASK_VARIANT = 0x01,
  171. UA_DATAVALUE_ENCODINGMASK_STATUSCODE = 0x02,
  172. UA_DATAVALUE_ENCODINGMASK_SOURCETIMESTAMP = 0x04,
  173. UA_DATAVALUE_ENCODINGMASK_SERVERTIMESTAMP = 0x08,
  174. UA_DATAVALUE_ENCODINGMASK_SOURCEPICOSECONDS = 0x10,
  175. UA_DATAVALUE_ENCODINGMASK_SERVERPICOSECONDS = 0x20
  176. };
  177. /** @brief A structure that contains detailed error and diagnostic information associated with a StatusCode. */
  178. typedef struct UA_DiagnosticInfo {
  179. UA_Byte encodingMask; // Type of the Enum UA_DIAGNOSTICINFO_ENCODINGMASKTYPE
  180. UA_Int32 symbolicId;
  181. UA_Int32 namespaceUri;
  182. UA_Int32 localizedText;
  183. UA_Int32 locale;
  184. UA_String additionalInfo;
  185. UA_StatusCode innerStatusCode;
  186. struct UA_DiagnosticInfo *innerDiagnosticInfo;
  187. } UA_DiagnosticInfo;
  188. enum UA_DIAGNOSTICINFO_ENCODINGMASKTYPE_enum {
  189. UA_DIAGNOSTICINFO_ENCODINGMASK_SYMBOLICID = 0x01,
  190. UA_DIAGNOSTICINFO_ENCODINGMASK_NAMESPACE = 0x02,
  191. UA_DIAGNOSTICINFO_ENCODINGMASK_LOCALIZEDTEXT = 0x04,
  192. UA_DIAGNOSTICINFO_ENCODINGMASK_LOCALE = 0x08,
  193. UA_DIAGNOSTICINFO_ENCODINGMASK_ADDITIONALINFO = 0x10,
  194. UA_DIAGNOSTICINFO_ENCODINGMASK_INNERSTATUSCODE = 0x20,
  195. UA_DIAGNOSTICINFO_ENCODINGMASK_INNERDIAGNOSTICINFO = 0x40
  196. };
  197. /** @brief Type use internally to denote an invalid datatype. */
  198. typedef void UA_InvalidType;
  199. /*************/
  200. /* Functions */
  201. /*************/
  202. #ifdef DEBUG
  203. #define UA_TYPE_PROTOTYPES(TYPE) \
  204. UA_Int32 TYPE##_new(TYPE **p); \
  205. UA_Int32 TYPE##_init(TYPE * p); \
  206. UA_Int32 TYPE##_delete(TYPE * p); \
  207. UA_Int32 TYPE##_deleteMembers(TYPE * p); \
  208. UA_Int32 TYPE##_copy(const TYPE *src, TYPE *dst); \
  209. void TYPE##_print(const TYPE *p, FILE *stream);
  210. #else
  211. #define UA_TYPE_PROTOTYPES(TYPE) \
  212. UA_Int32 TYPE##_new(TYPE **p); \
  213. UA_Int32 TYPE##_init(TYPE * p); \
  214. UA_Int32 TYPE##_delete(TYPE * p); \
  215. UA_Int32 TYPE##_deleteMembers(TYPE * p); \
  216. UA_Int32 TYPE##_copy(const TYPE *src, TYPE *dst);
  217. #endif
  218. /* Functions for all types */
  219. UA_TYPE_PROTOTYPES(UA_Boolean)
  220. UA_TYPE_PROTOTYPES(UA_SByte)
  221. UA_TYPE_PROTOTYPES(UA_Byte)
  222. UA_TYPE_PROTOTYPES(UA_Int16)
  223. UA_TYPE_PROTOTYPES(UA_UInt16)
  224. UA_TYPE_PROTOTYPES(UA_Int32)
  225. UA_TYPE_PROTOTYPES(UA_UInt32)
  226. UA_TYPE_PROTOTYPES(UA_Int64)
  227. UA_TYPE_PROTOTYPES(UA_UInt64)
  228. UA_TYPE_PROTOTYPES(UA_Float)
  229. UA_TYPE_PROTOTYPES(UA_Double)
  230. UA_TYPE_PROTOTYPES(UA_String)
  231. UA_TYPE_PROTOTYPES(UA_DateTime)
  232. UA_TYPE_PROTOTYPES(UA_Guid)
  233. UA_TYPE_PROTOTYPES(UA_ByteString)
  234. UA_TYPE_PROTOTYPES(UA_XmlElement)
  235. UA_TYPE_PROTOTYPES(UA_NodeId)
  236. UA_TYPE_PROTOTYPES(UA_ExpandedNodeId)
  237. UA_TYPE_PROTOTYPES(UA_StatusCode)
  238. UA_TYPE_PROTOTYPES(UA_QualifiedName)
  239. UA_TYPE_PROTOTYPES(UA_LocalizedText)
  240. UA_TYPE_PROTOTYPES(UA_ExtensionObject)
  241. UA_TYPE_PROTOTYPES(UA_DataValue)
  242. UA_TYPE_PROTOTYPES(UA_Variant)
  243. UA_TYPE_PROTOTYPES(UA_DiagnosticInfo)
  244. UA_TYPE_PROTOTYPES(UA_InvalidType)
  245. /* String */
  246. #define UA_STRING_NULL (UA_String){-1, UA_NULL}
  247. #define UA_STRING_STATIC(STRING) (UA_String){sizeof(STRING)-1, (UA_Byte*)STRING}
  248. UA_Int32 UA_String_copycstring(char const *src, UA_String *dst);
  249. UA_Int32 UA_String_copyprintf(char const *fmt, UA_String *dst, ...);
  250. UA_Int32 UA_String_equal(const UA_String *string1, const UA_String *string2);
  251. #ifdef DEBUG
  252. void UA_String_printf(char const *label, const UA_String *string);
  253. void UA_String_printx(char const *label, const UA_String *string);
  254. void UA_String_printx_hex(char const *label, const UA_String *string);
  255. #endif
  256. /* DateTime */
  257. UA_DateTime UA_DateTime_now();
  258. typedef struct UA_DateTimeStruct {
  259. UA_Int16 nanoSec;
  260. UA_Int16 microSec;
  261. UA_Int16 milliSec;
  262. UA_Int16 sec;
  263. UA_Int16 min;
  264. UA_Int16 hour;
  265. UA_Int16 day;
  266. UA_Int16 mounth;
  267. UA_Int16 year;
  268. } UA_DateTimeStruct;
  269. UA_DateTimeStruct UA_DateTime_toStruct(UA_DateTime time);
  270. UA_Int32 UA_DateTime_toString(UA_DateTime time, UA_String *timeString);
  271. /* Guid */
  272. UA_Int32 UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
  273. /* ByteString */
  274. UA_Int32 UA_ByteString_equal(const UA_ByteString *string1, const UA_ByteString *string2);
  275. UA_Int32 UA_ByteString_newMembers(UA_ByteString *p, UA_Int32 length);
  276. #ifdef DEBUG
  277. void UA_ByteString_printf(char *label, const UA_ByteString *string);
  278. void UA_ByteString_printx(char *label, const UA_ByteString *string);
  279. void UA_ByteString_printx_hex(char *label, const UA_ByteString *string);
  280. #endif
  281. /* NodeId */
  282. UA_Int32 UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
  283. #ifdef DEBUG
  284. void UA_NodeId_printf(char *label, const UA_NodeId *node);
  285. #endif
  286. UA_Boolean UA_NodeId_isNull(const UA_NodeId *p);
  287. UA_Boolean UA_NodeId_isBasicType(UA_NodeId const *id);
  288. /* ExpandedNodeId */
  289. UA_Boolean UA_ExpandedNodeId_isNull(const UA_ExpandedNodeId *p);
  290. /* QualifiedName */
  291. #define UA_QUALIFIEDNAME_STATIC(STRING) \
  292. (UA_QualifiedName){0, {sizeof(STRING)-1, (UA_Byte*)STRING}}
  293. #ifdef DEBUG
  294. void UA_QualifiedName_printf(char const *label, const UA_QualifiedName *qn);
  295. #endif
  296. /* LocalizedText */
  297. #define UA_LOCALIZEDTEXT_STATIC(STRING) (UA_LocalizedText){{2, (UA_Byte*)"en"}, UA_STRING_STATIC(STRING)}
  298. UA_Int32 UA_LocalizedText_copycstring(char const *src, UA_LocalizedText *dst);
  299. /* Variant */
  300. UA_Int32 UA_Variant_copySetValue(UA_Variant *v, UA_VTable_Entry *vt, const void *value);
  301. UA_Int32 UA_Variant_copySetArray(UA_Variant *v, UA_VTable_Entry *vt, UA_Int32 arrayLength, const void *array);
  302. /** @brief Functions UA_Variant_borrowSetValue and ..Array allow to define
  303. variants whose payload will not be deleted. This is achieved by a second
  304. vtable. The functionality can be used e.g. when UA_VariableNodes point into a
  305. "father" structured object that is stored in an UA_VariableNode itself. */
  306. UA_Int32 UA_Variant_borrowSetValue(UA_Variant *v, UA_VTable_Entry *vt, const void *value);
  307. UA_Int32 UA_Variant_borrowSetArray(UA_Variant *v, UA_VTable_Entry *vt, UA_Int32 arrayLength,
  308. const void *array);
  309. /* Array operations */
  310. UA_Int32 UA_Array_new(void **p, UA_Int32 noElements, UA_VTable_Entry *vt);
  311. UA_Int32 UA_Array_init(void *p, UA_Int32 noElements, UA_VTable_Entry *vt);
  312. UA_Int32 UA_Array_delete(void *p, UA_Int32 noElements, UA_VTable_Entry *vt);
  313. /* @brief The destination array is allocated according to noElements. */
  314. UA_Int32 UA_Array_copy(const void *src, UA_Int32 noElements, UA_VTable_Entry *vt, void **dst);
  315. #ifdef DEBUG
  316. void UA_Array_print(const void *p, UA_Int32 noElements, UA_VTable_Entry *vt, FILE *stream);
  317. #endif
  318. /**********/
  319. /* VTable */
  320. /**********/
  321. /* @brief Returns the size of the encoded element.*/
  322. typedef UA_Int32 (*UA_calcSize)(const void *p);
  323. /* @brief The encoding function allocates the target bytestring. */
  324. typedef UA_Int32 (*UA_encode)(const void *src, UA_ByteString *dst, UA_UInt32 *offset);
  325. /* @brief The decoding function decodes a ByteString into an UA datatype. */
  326. typedef UA_Int32 (*UA_decode)(const UA_ByteString *src, UA_UInt32 *offset, void *dst);
  327. typedef struct UA_Encoding {
  328. UA_calcSize calcSize;
  329. UA_encode encode;
  330. UA_decode decode;
  331. } UA_Encoding;
  332. #define UA_ENCODING_BINARY 0
  333. #define UA_ENCODING_XML 1
  334. struct UA_VTable_Entry {
  335. UA_NodeId typeId;
  336. UA_Byte *name;
  337. UA_Int32 (*new)(void **p);
  338. UA_Int32 (*init)(void *p);
  339. UA_Int32 (*copy)(void const *src, void *dst);
  340. UA_Int32 (*delete)(void *p);
  341. UA_Int32 (*deleteMembers)(void *p);
  342. #ifdef DEBUG
  343. void (*print)(const void *p, FILE *stream);
  344. #endif
  345. UA_UInt32 memSize; // size of the struct only in memory (no dynamic components)
  346. UA_Boolean dynMembers; // does the type contain members that are dynamically
  347. // allocated (strings, ..)? Otherwise, the size on
  348. // the wire == size in memory.
  349. UA_Encoding encodings[2]; // binary, xml, ...
  350. };
  351. typedef UA_Int32 (*UA_nodeIdToVTableIndex)(const UA_NodeId *id);
  352. typedef struct UA_VTable {
  353. UA_nodeIdToVTableIndex getTypeIndex;
  354. UA_VTable_Entry *types;
  355. } UA_VTable;
  356. /***********************************/
  357. /* Macros for type implementations */
  358. /***********************************/
  359. #define UA_TYPE_DEFAULT(TYPE) \
  360. UA_TYPE_DELETE_DEFAULT(TYPE) \
  361. UA_TYPE_DELETEMEMBERS_NOACTION(TYPE) \
  362. UA_TYPE_INIT_DEFAULT(TYPE) \
  363. UA_TYPE_NEW_DEFAULT(TYPE) \
  364. UA_TYPE_COPY_DEFAULT(TYPE) \
  365. #define UA_TYPE_NEW_DEFAULT(TYPE) \
  366. UA_Int32 TYPE##_new(TYPE **p) { \
  367. UA_Int32 retval = UA_SUCCESS; \
  368. retval |= UA_alloc((void **)p, sizeof(TYPE)); \
  369. retval |= TYPE##_init(*p); \
  370. return retval; \
  371. }
  372. #define UA_TYPE_INIT_DEFAULT(TYPE) \
  373. UA_Int32 TYPE##_init(TYPE * p) { \
  374. if(p == UA_NULL) return UA_ERROR; \
  375. *p = (TYPE)0; \
  376. return UA_SUCCESS; \
  377. }
  378. #define UA_TYPE_INIT_AS(TYPE, TYPE_AS) \
  379. UA_Int32 TYPE##_init(TYPE * p) { \
  380. return TYPE_AS##_init((TYPE_AS *)p); \
  381. }
  382. #define UA_TYPE_DELETE_DEFAULT(TYPE) \
  383. UA_Int32 TYPE##_delete(TYPE *p) { \
  384. UA_Int32 retval = UA_SUCCESS; \
  385. retval |= TYPE##_deleteMembers(p); \
  386. retval |= UA_free(p); \
  387. return retval; \
  388. }
  389. #define UA_TYPE_DELETE_AS(TYPE, TYPE_AS) \
  390. UA_Int32 TYPE##_delete(TYPE * p) { return TYPE_AS##_delete((TYPE_AS *)p); }
  391. #define UA_TYPE_DELETEMEMBERS_NOACTION(TYPE) \
  392. UA_Int32 TYPE##_deleteMembers(TYPE * p) { return UA_SUCCESS; }
  393. #define UA_TYPE_DELETEMEMBERS_AS(TYPE, TYPE_AS) \
  394. UA_Int32 TYPE##_deleteMembers(TYPE * p) { return TYPE_AS##_deleteMembers((TYPE_AS *)p); }
  395. /* Use only when the type has no arrays. Otherwise, implement deep copy */
  396. #define UA_TYPE_COPY_DEFAULT(TYPE) \
  397. UA_Int32 TYPE##_copy(TYPE const *src, TYPE *dst) { \
  398. if(src == UA_NULL || dst == UA_NULL) return UA_ERROR; \
  399. UA_Int32 retval = UA_SUCCESS; \
  400. retval |= UA_memcpy(dst, src, sizeof(TYPE)); \
  401. return retval; \
  402. }
  403. #define UA_TYPE_COPY_AS(TYPE, TYPE_AS) \
  404. UA_Int32 TYPE##_copy(TYPE const *src, TYPE *dst) { \
  405. return TYPE_AS##_copy((TYPE_AS *)src, (TYPE_AS *)dst); \
  406. }
  407. #define UA_TYPE_PRINT_AS(TYPE, TYPE_AS) \
  408. void TYPE##_print(TYPE const *p, FILE *stream) { \
  409. TYPE_AS##_print((TYPE_AS *)p, stream); \
  410. } \
  411. #ifdef DEBUG //print functions only in debug mode
  412. #define UA_TYPE_AS(TYPE, TYPE_AS) \
  413. UA_TYPE_NEW_DEFAULT(TYPE) \
  414. UA_TYPE_INIT_AS(TYPE, TYPE_AS) \
  415. UA_TYPE_DELETE_AS(TYPE, TYPE_AS) \
  416. UA_TYPE_DELETEMEMBERS_AS(TYPE, TYPE_AS) \
  417. UA_TYPE_COPY_AS(TYPE, TYPE_AS) \
  418. UA_TYPE_PRINT_AS(TYPE, TYPE_AS)
  419. #else
  420. #define UA_TYPE_AS(TYPE, TYPE_AS) \
  421. UA_TYPE_NEW_DEFAULT(TYPE) \
  422. UA_TYPE_INIT_AS(TYPE, TYPE_AS) \
  423. UA_TYPE_DELETE_AS(TYPE, TYPE_AS) \
  424. UA_TYPE_DELETEMEMBERS_AS(TYPE, TYPE_AS) \
  425. UA_TYPE_COPY_AS(TYPE, TYPE_AS)
  426. #endif
  427. /// @} /* end of group */
  428. #endif /* UA_TYPES_H_ */