ua_types.h 19 KB

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