123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904 |
- #ifndef UA_TYPES_H_
- #define UA_TYPES_H_
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include "ua_config.h"
- #include "ua_constants.h"
- #define UA_BUILTIN_TYPES_COUNT 25U
- typedef bool UA_Boolean;
- #define UA_TRUE true
- #define UA_FALSE false
- typedef int8_t UA_SByte;
- #define UA_SBYTE_MIN (-128)
- #define UA_SBYTE_MAX 127
- typedef uint8_t UA_Byte;
- #define UA_BYTE_MIN 0
- #define UA_BYTE_MAX 255
- typedef int16_t UA_Int16;
- #define UA_INT16_MIN (-32768)
- #define UA_INT16_MAX 32767
- typedef uint16_t UA_UInt16;
- #define UA_UINT16_MIN 0
- #define UA_UINT16_MAX 65535
- typedef int32_t UA_Int32;
- #define UA_INT32_MIN (-2147483648)
- #define UA_INT32_MAX 2147483647
- typedef uint32_t UA_UInt32;
- #define UA_UINT32_MIN 0
- #define UA_UINT32_MAX 4294967295
- typedef int64_t UA_Int64;
- #define UA_INT64_MIN ((int64_t)-9223372036854775808)
- #define UA_INT64_MAX (int64_t)9223372036854775807
- typedef uint64_t UA_UInt64;
- #define UA_UINT64_MIN (int64_t)0
- #define UA_UINT64_MAX (int64_t)18446744073709551615
- typedef float UA_Float;
- typedef double UA_Double;
- typedef uint32_t UA_StatusCode;
- typedef struct {
- UA_StatusCode code;
- const char* name;
- const char* explanation;
- } UA_StatusCodeDescription;
- UA_EXPORT const UA_StatusCodeDescription *
- UA_StatusCode_description(UA_StatusCode code);
- static UA_INLINE const char *
- UA_StatusCode_name(UA_StatusCode code) {
- return UA_StatusCode_description(code)->name;
- }
- static UA_INLINE const char *
- UA_StatusCode_explanation(UA_StatusCode code) {
- return UA_StatusCode_description(code)->explanation;
- }
- typedef struct {
- size_t length;
- UA_Byte *data;
- } UA_String;
- UA_String UA_EXPORT UA_String_fromChars(char const src[]) UA_FUNC_ATTR_WARN_UNUSED_RESULT;
- UA_Boolean UA_EXPORT UA_String_equal(const UA_String *s1, const UA_String *s2);
- UA_EXPORT extern const UA_String UA_STRING_NULL;
- static UA_INLINE UA_String
- UA_STRING(char *chars) {
- UA_String str; str.length = strlen(chars);
- str.data = (UA_Byte*)chars; return str;
- }
- #define UA_STRING_ALLOC(CHARS) UA_String_fromChars(CHARS)
- typedef int64_t UA_DateTime;
- #define UA_USEC_TO_DATETIME 10LL
- #define UA_MSEC_TO_DATETIME (UA_USEC_TO_DATETIME * 1000LL)
- #define UA_SEC_TO_DATETIME (UA_MSEC_TO_DATETIME * 1000LL)
- #define UA_DATETIME_UNIX_EPOCH (11644473600LL * UA_SEC_TO_DATETIME)
- UA_DateTime UA_EXPORT UA_DateTime_now(void);
- UA_DateTime UA_EXPORT UA_DateTime_nowMonotonic(void);
- typedef struct UA_DateTimeStruct {
- UA_UInt16 nanoSec;
- UA_UInt16 microSec;
- UA_UInt16 milliSec;
- UA_UInt16 sec;
- UA_UInt16 min;
- UA_UInt16 hour;
- UA_UInt16 day;
- UA_UInt16 month;
- UA_UInt16 year;
- } UA_DateTimeStruct;
- UA_DateTimeStruct UA_EXPORT UA_DateTime_toStruct(UA_DateTime t);
- UA_String UA_EXPORT UA_DateTime_toString(UA_DateTime t);
- typedef struct {
- UA_UInt32 data1;
- UA_UInt16 data2;
- UA_UInt16 data3;
- UA_Byte data4[8];
- } UA_Guid;
- UA_Boolean UA_EXPORT UA_Guid_equal(const UA_Guid *g1, const UA_Guid *g2);
- UA_EXPORT extern const UA_Guid UA_GUID_NULL;
- typedef UA_String UA_ByteString;
- static UA_INLINE UA_Boolean
- UA_ByteString_equal(const UA_ByteString *string1,
- const UA_ByteString *string2) {
- return UA_String_equal((const UA_String*)string1,
- (const UA_String*)string2);
- }
- UA_StatusCode UA_EXPORT
- UA_ByteString_allocBuffer(UA_ByteString *bs, size_t length);
- UA_EXPORT extern const UA_ByteString UA_BYTESTRING_NULL;
- static UA_INLINE UA_ByteString
- UA_BYTESTRING(char *chars) {
- UA_ByteString str; str.length = strlen(chars);
- str.data = (UA_Byte*)chars; return str;
- }
- static UA_INLINE UA_ByteString
- UA_BYTESTRING_ALLOC(const char *chars) {
- UA_String str = UA_String_fromChars(chars); UA_ByteString bstr;
- bstr.length = str.length; bstr.data = str.data; return bstr;
- }
- typedef UA_String UA_XmlElement;
- enum UA_NodeIdType {
- UA_NODEIDTYPE_NUMERIC = 0,
- UA_NODEIDTYPE_STRING = 3,
- UA_NODEIDTYPE_GUID = 4,
- UA_NODEIDTYPE_BYTESTRING = 5
- };
- typedef struct {
- UA_UInt16 namespaceIndex;
- enum UA_NodeIdType identifierType;
- union {
- UA_UInt32 numeric;
- UA_String string;
- UA_Guid guid;
- UA_ByteString byteString;
- } identifier;
- } UA_NodeId;
- UA_EXPORT extern const UA_NodeId UA_NODEID_NULL;
- UA_Boolean UA_EXPORT UA_NodeId_isNull(const UA_NodeId *p);
- UA_Boolean UA_EXPORT UA_NodeId_equal(const UA_NodeId *n1, const UA_NodeId *n2);
- UA_UInt32 UA_EXPORT UA_NodeId_hash(const UA_NodeId *n);
- static UA_INLINE UA_NodeId
- UA_NODEID_NUMERIC(UA_UInt16 nsIndex, UA_UInt32 identifier) {
- UA_NodeId id; id.namespaceIndex = nsIndex;
- id.identifierType = UA_NODEIDTYPE_NUMERIC;
- id.identifier.numeric = identifier; return id;
- }
- static UA_INLINE UA_NodeId
- UA_NODEID_STRING(UA_UInt16 nsIndex, char *chars) {
- UA_NodeId id; id.namespaceIndex = nsIndex;
- id.identifierType = UA_NODEIDTYPE_STRING;
- id.identifier.string = UA_STRING(chars); return id;
- }
- static UA_INLINE UA_NodeId
- UA_NODEID_STRING_ALLOC(UA_UInt16 nsIndex, const char *chars) {
- UA_NodeId id; id.namespaceIndex = nsIndex;
- id.identifierType = UA_NODEIDTYPE_STRING;
- id.identifier.string = UA_STRING_ALLOC(chars); return id;
- }
- static UA_INLINE UA_NodeId
- UA_NODEID_GUID(UA_UInt16 nsIndex, UA_Guid guid) {
- UA_NodeId id; id.namespaceIndex = nsIndex;
- id.identifierType = UA_NODEIDTYPE_GUID;
- id.identifier.guid = guid; return id;
- }
- static UA_INLINE UA_NodeId
- UA_NODEID_BYTESTRING(UA_UInt16 nsIndex, char *chars) {
- UA_NodeId id; id.namespaceIndex = nsIndex;
- id.identifierType = UA_NODEIDTYPE_BYTESTRING;
- id.identifier.byteString = UA_BYTESTRING(chars); return id;
- }
- static UA_INLINE UA_NodeId
- UA_NODEID_BYTESTRING_ALLOC(UA_UInt16 nsIndex, const char *chars) {
- UA_NodeId id; id.namespaceIndex = nsIndex;
- id.identifierType = UA_NODEIDTYPE_BYTESTRING;
- id.identifier.byteString = UA_BYTESTRING_ALLOC(chars); return id;
- }
- typedef struct {
- UA_NodeId nodeId;
- UA_String namespaceUri;
- UA_UInt32 serverIndex;
- } UA_ExpandedNodeId;
- static UA_INLINE UA_ExpandedNodeId
- UA_EXPANDEDNODEID_NUMERIC(UA_UInt16 nsIndex, UA_UInt32 identifier) {
- UA_ExpandedNodeId id; id.nodeId = UA_NODEID_NUMERIC(nsIndex, identifier);
- id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id;
- }
- static UA_INLINE UA_ExpandedNodeId
- UA_EXPANDEDNODEID_STRING(UA_UInt16 nsIndex, char *chars) {
- UA_ExpandedNodeId id; id.nodeId = UA_NODEID_STRING(nsIndex, chars);
- id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id;
- }
- static UA_INLINE UA_ExpandedNodeId
- UA_EXPANDEDNODEID_STRING_ALLOC(UA_UInt16 nsIndex, const char *chars) {
- UA_ExpandedNodeId id; id.nodeId = UA_NODEID_STRING_ALLOC(nsIndex, chars);
- id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id;
- }
- static UA_INLINE UA_ExpandedNodeId
- UA_EXPANDEDNODEID_STRING_GUID(UA_UInt16 nsIndex, UA_Guid guid) {
- UA_ExpandedNodeId id; id.nodeId = UA_NODEID_GUID(nsIndex, guid);
- id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id;
- }
- static UA_INLINE UA_ExpandedNodeId
- UA_EXPANDEDNODEID_BYTESTRING(UA_UInt16 nsIndex, char *chars) {
- UA_ExpandedNodeId id; id.nodeId = UA_NODEID_BYTESTRING(nsIndex, chars);
- id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id;
- }
- static UA_INLINE UA_ExpandedNodeId
- UA_EXPANDEDNODEID_BYTESTRING_ALLOC(UA_UInt16 nsIndex, const char *chars) {
- UA_ExpandedNodeId id; id.nodeId = UA_NODEID_BYTESTRING_ALLOC(nsIndex, chars);
- id.serverIndex = 0; id.namespaceUri = UA_STRING_NULL; return id;
- }
- typedef struct {
- UA_UInt16 namespaceIndex;
- UA_String name;
- } UA_QualifiedName;
- static UA_INLINE UA_Boolean
- UA_QualifiedName_isNull(const UA_QualifiedName *q) {
- return (q->namespaceIndex == 0 && q->name.length == 0);
- }
- static UA_INLINE UA_QualifiedName
- UA_QUALIFIEDNAME(UA_UInt16 nsIndex, char *chars) {
- UA_QualifiedName qn; qn.namespaceIndex = nsIndex;
- qn.name = UA_STRING(chars); return qn;
- }
- static UA_INLINE UA_QualifiedName
- UA_QUALIFIEDNAME_ALLOC(UA_UInt16 nsIndex, const char *chars) {
- UA_QualifiedName qn; qn.namespaceIndex = nsIndex;
- qn.name = UA_STRING_ALLOC(chars); return qn;
- }
- typedef struct {
- UA_String locale;
- UA_String text;
- } UA_LocalizedText;
- static UA_INLINE UA_LocalizedText
- UA_LOCALIZEDTEXT(char *locale, char *text) {
- UA_LocalizedText lt; lt.locale = UA_STRING(locale);
- lt.text = UA_STRING(text); return lt;
- }
- static UA_INLINE UA_LocalizedText
- UA_LOCALIZEDTEXT_ALLOC(const char *locale, const char *text) {
- UA_LocalizedText lt; lt.locale = UA_STRING_ALLOC(locale);
- lt.text = UA_STRING_ALLOC(text); return lt;
- }
- typedef struct {
- UA_UInt32 min;
- UA_UInt32 max;
- } UA_NumericRangeDimension;
- typedef struct {
- size_t dimensionsSize;
- UA_NumericRangeDimension *dimensions;
- } UA_NumericRange;
- struct UA_DataType;
- typedef struct UA_DataType UA_DataType;
- #define UA_EMPTY_ARRAY_SENTINEL ((void*)0x01)
- typedef enum {
- UA_VARIANT_DATA,
- UA_VARIANT_DATA_NODELETE,
- } UA_VariantStorageType;
- typedef struct {
- const UA_DataType *type;
- UA_VariantStorageType storageType;
- size_t arrayLength;
- void *data;
- size_t arrayDimensionsSize;
- UA_UInt32 *arrayDimensions;
- } UA_Variant;
- static UA_INLINE UA_Boolean
- UA_Variant_isEmpty(const UA_Variant *v) {
- return v->type == NULL;
- }
- static UA_INLINE UA_Boolean
- UA_Variant_isScalar(const UA_Variant *v) {
- return (v->arrayLength == 0 && v->data > UA_EMPTY_ARRAY_SENTINEL);
- }
- static UA_INLINE UA_Boolean
- UA_Variant_hasScalarType(const UA_Variant *v, const UA_DataType *type) {
- return UA_Variant_isScalar(v) && type == v->type;
- }
- static UA_INLINE UA_Boolean
- UA_Variant_hasArrayType(const UA_Variant *v, const UA_DataType *type) {
- return (!UA_Variant_isScalar(v)) && type == v->type;
- }
- void UA_EXPORT
- UA_Variant_setScalar(UA_Variant *v, void * UA_RESTRICT p,
- const UA_DataType *type);
- UA_StatusCode UA_EXPORT
- UA_Variant_setScalarCopy(UA_Variant *v, const void *p,
- const UA_DataType *type);
- void UA_EXPORT
- UA_Variant_setArray(UA_Variant *v, void * UA_RESTRICT array,
- size_t arraySize, const UA_DataType *type);
- UA_StatusCode UA_EXPORT
- UA_Variant_setArrayCopy(UA_Variant *v, const void *array,
- size_t arraySize, const UA_DataType *type);
- UA_StatusCode UA_EXPORT
- UA_Variant_copyRange(const UA_Variant *src, UA_Variant *dst,
- const UA_NumericRange range);
- UA_StatusCode UA_EXPORT
- UA_Variant_setRange(UA_Variant *v, void * UA_RESTRICT array,
- size_t arraySize, const UA_NumericRange range);
- UA_StatusCode UA_EXPORT
- UA_Variant_setRangeCopy(UA_Variant *v, const void *array,
- size_t arraySize, const UA_NumericRange range);
- typedef enum {
- UA_EXTENSIONOBJECT_ENCODED_NOBODY = 0,
- UA_EXTENSIONOBJECT_ENCODED_BYTESTRING = 1,
- UA_EXTENSIONOBJECT_ENCODED_XML = 2,
- UA_EXTENSIONOBJECT_DECODED = 3,
- UA_EXTENSIONOBJECT_DECODED_NODELETE = 4
- } UA_ExtensionObjectEncoding;
- typedef struct {
- UA_ExtensionObjectEncoding encoding;
- union {
- struct {
- UA_NodeId typeId;
- UA_ByteString body;
- } encoded;
- struct {
- const UA_DataType *type;
- void *data;
- } decoded;
- } content;
- } UA_ExtensionObject;
- typedef struct {
- UA_Boolean hasValue : 1;
- UA_Boolean hasStatus : 1;
- UA_Boolean hasSourceTimestamp : 1;
- UA_Boolean hasServerTimestamp : 1;
- UA_Boolean hasSourcePicoseconds : 1;
- UA_Boolean hasServerPicoseconds : 1;
- UA_Variant value;
- UA_StatusCode status;
- UA_DateTime sourceTimestamp;
- UA_UInt16 sourcePicoseconds;
- UA_DateTime serverTimestamp;
- UA_UInt16 serverPicoseconds;
- } UA_DataValue;
- typedef struct UA_DiagnosticInfo {
- UA_Boolean hasSymbolicId : 1;
- UA_Boolean hasNamespaceUri : 1;
- UA_Boolean hasLocalizedText : 1;
- UA_Boolean hasLocale : 1;
- UA_Boolean hasAdditionalInfo : 1;
- UA_Boolean hasInnerStatusCode : 1;
- UA_Boolean hasInnerDiagnosticInfo : 1;
- UA_Int32 symbolicId;
- UA_Int32 namespaceUri;
- UA_Int32 localizedText;
- UA_Int32 locale;
- UA_String additionalInfo;
- UA_StatusCode innerStatusCode;
- struct UA_DiagnosticInfo *innerDiagnosticInfo;
- } UA_DiagnosticInfo;
- typedef struct {
- #ifdef UA_ENABLE_TYPENAMES
- const char *memberName;
- #endif
- UA_UInt16 memberTypeIndex;
- UA_Byte padding;
- UA_Boolean namespaceZero : 1;
- UA_Boolean isArray : 1;
- } UA_DataTypeMember;
- struct UA_DataType {
- #ifdef UA_ENABLE_TYPENAMES
- const char *typeName;
- #endif
- UA_NodeId typeId;
- UA_UInt16 memSize;
- UA_UInt16 typeIndex;
- UA_Byte membersSize;
- UA_Boolean builtin : 1;
- UA_Boolean pointerFree : 1;
- UA_Boolean overlayable : 1;
- UA_UInt16 binaryEncodingId;
-
- UA_DataTypeMember *members;
- };
- const UA_DataType UA_EXPORT *
- UA_findDataType(const UA_NodeId *typeId);
- void UA_EXPORT * UA_new(const UA_DataType *type) UA_FUNC_ATTR_MALLOC;
- static UA_INLINE void
- UA_init(void *p, const UA_DataType *type) {
- memset(p, 0, type->memSize);
- }
- UA_StatusCode UA_EXPORT
- UA_copy(const void *src, void *dst, const UA_DataType *type);
- void UA_EXPORT UA_deleteMembers(void *p, const UA_DataType *type);
- void UA_EXPORT UA_delete(void *p, const UA_DataType *type);
- void UA_EXPORT * UA_Array_new(size_t size, const UA_DataType *type) UA_FUNC_ATTR_MALLOC;
- UA_StatusCode UA_EXPORT
- UA_Array_copy(const void *src, size_t size, void **dst,
- const UA_DataType *type) UA_FUNC_ATTR_WARN_UNUSED_RESULT;
- void UA_EXPORT UA_Array_delete(void *p, size_t size, const UA_DataType *type);
- void UA_EXPORT UA_random_seed(UA_UInt64 seed);
- UA_UInt32 UA_EXPORT UA_UInt32_random(void);
- UA_Guid UA_EXPORT UA_Guid_random(void);
- #ifdef __cplusplus
- }
- #endif
- #endif
|