ua_types.h 18 KB

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