High Performance OPC UA Server SDK
1.7.1.383
|
Setter and attach functions for the ua_variant structure. More...
Functions | |
BASE_EXPORT void | ua_variant_set_bool (struct ua_variant *v, bool val) |
Write a boolean to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_byte (struct ua_variant *v, uint8_t val) |
Write a byte(uint8) to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_sbyte (struct ua_variant *v, int8_t val) |
Write a signed byte(int8) to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_uint16 (struct ua_variant *v, uint16_t val) |
Write an uint16 to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_int16 (struct ua_variant *v, int16_t val) |
Write an int16 to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_uint32 (struct ua_variant *v, uint32_t val) |
Write an uint32 to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_int32 (struct ua_variant *v, int32_t val) |
Write an int32 to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_uint64 (struct ua_variant *v, uint64_t val) |
Write an uint64 to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_int64 (struct ua_variant *v, int64_t val) |
Write an int64 to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_float (struct ua_variant *v, float val) |
Write a float to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_double (struct ua_variant *v, double val) |
Write a double to the ua_variant val . More... | |
BASE_EXPORT void | ua_variant_set_datetime (struct ua_variant *v, ua_datetime val) |
Write a double to the ua_variant val . More... | |
BASE_EXPORT int | ua_variant_set_string (struct ua_variant *v, const char *val) |
Fills the given variant v with an OPC UA String. More... | |
BASE_EXPORT int | ua_variant_set_stringn (struct ua_variant *v, const char *val, size_t len) |
Fills the given variant v with an OPC UA String. More... | |
BASE_EXPORT int | ua_variant_set_bytestring (struct ua_variant *v, const char *data, int len) |
Fills the given variant v with an OPC UA ByteString. More... | |
BASE_EXPORT int | ua_variant_set_xmlelement (struct ua_variant *v, const char *data, int len) |
Fills the given variant v with an XML element. More... | |
BASE_EXPORT int | ua_variant_set_nodeid (struct ua_variant *v, const struct ua_nodeid *id) |
Fills the given variant v with an UA Nodeid. More... | |
BASE_EXPORT int | ua_variant_set_expandednodeid (struct ua_variant *v, const struct ua_expandednodeid *id) |
Fills the given variant v with an UA ExpandedNodeid. More... | |
BASE_EXPORT int | ua_variant_set_guid (struct ua_variant *v, const struct ua_guid *guid) |
Fills the given variant v with an UA GUID. More... | |
BASE_EXPORT void | ua_variant_set_statuscode (struct ua_variant *v, ua_statuscode status) |
BASE_EXPORT int | ua_variant_set_qualifiedname (struct ua_variant *v, int nsindex, const char *name) |
Fills the given variant v with an UA Qualifiedname. More... | |
BASE_EXPORT int | ua_variant_set_localizedtext (struct ua_variant *v, const char *locale, const char *text) |
Fills the given variant v with an UA Localizedtext. More... | |
BASE_EXPORT int | ua_variant_set_extensionobject (struct ua_variant *v, const void *obj, const struct ua_nodeid *type_id) |
Set an encodable object as extensionobject to a variant. More... | |
BASE_EXPORT int | ua_variant_set_extensionobject_numeric (struct ua_variant *v, const void *obj, uint16_t nsindex, uint32_t value) |
This is a convenience overload function for ua_variant_set_extensionobject() which allows settings UA defined structure types without creating helper variables for the typeid. More... | |
BASE_EXPORT int | ua_variant_set_extensionobject_binary (struct ua_variant *v, const struct ua_bytestring *data, const struct ua_nodeid *encoding_id) |
Stores a pre-encoded binary extensionobject in the variant. More... | |
BASE_EXPORT int | ua_variant_set_scalar (struct ua_variant *dst, enum ua_variant_type type, const void *val) |
Set a scalar as value for the variant dst . More... | |
BASE_EXPORT void | ua_variant_attach_string (struct ua_variant *v, char *val) |
Fills the given variant v with an OPC UA String. More... | |
BASE_EXPORT void | ua_variant_attach_stringn (struct ua_variant *v, char *val, size_t len) |
Fills the given variant v with an OPC UA String. More... | |
BASE_EXPORT int | ua_variant_smart_attach_const_string (struct ua_variant *v, const char *val) |
Fills the given variant v with an OPC UA String. More... | |
BASE_EXPORT int | ua_variant_smart_attach_const_stringn (struct ua_variant *v, const char *val, size_t len) |
Fills the given variant v with an OPC UA String. More... | |
BASE_EXPORT int | ua_variant_attach_scalar (struct ua_variant *v, enum ua_variant_type type, void *val) |
Attach a scaler value to the given variant. More... | |
BASE_EXPORT int | ua_variant_attach_extensionobject (struct ua_variant *v, void *obj, const struct ua_nodeid *type_id) |
Attach an encodable object as extensionobject to a variant. More... | |
BASE_EXPORT int | ua_variant_set_bool_array (struct ua_variant *v, bool *val, size_t num) |
BASE_EXPORT int | ua_variant_set_byte_array (struct ua_variant *v, uint8_t *val, size_t num) |
BASE_EXPORT int | ua_variant_set_sbyte_array (struct ua_variant *v, int8_t *val, size_t num) |
BASE_EXPORT int | ua_variant_set_uint16_array (struct ua_variant *v, uint16_t *val, size_t num) |
BASE_EXPORT int | ua_variant_set_int16_array (struct ua_variant *v, int16_t *val, size_t num) |
BASE_EXPORT int | ua_variant_set_uint32_array (struct ua_variant *v, uint32_t *val, size_t num) |
BASE_EXPORT int | ua_variant_set_int32_array (struct ua_variant *v, int32_t *val, size_t num) |
BASE_EXPORT int | ua_variant_set_uint64_array (struct ua_variant *v, uint64_t *val, size_t num) |
BASE_EXPORT int | ua_variant_set_int64_array (struct ua_variant *v, int64_t *val, size_t num) |
BASE_EXPORT int | ua_variant_set_float_array (struct ua_variant *v, float *val, size_t num) |
BASE_EXPORT int | ua_variant_set_double_array (struct ua_variant *v, double *val, size_t num) |
BASE_EXPORT int | ua_variant_set_extensionobject_array (struct ua_variant *v, const void *obj, size_t num, const struct ua_nodeid *type_id) |
Stores an array of custom structures in a variant. More... | |
BASE_EXPORT int | ua_variant_set_array (struct ua_variant *v, enum ua_variant_type type, const void *values, size_t num) |
Stores the given array data in the variant. More... | |
BASE_EXPORT int | ua_variant_set_string_array (struct ua_variant *v, const char **val, size_t num) |
Set a C string array as data for a variant. More... | |
BASE_EXPORT int | ua_variant_attach_array (struct ua_variant *v, enum ua_variant_type type, void *val, size_t num) |
Attach an array value to the given variant. More... | |
BASE_EXPORT int | ua_variant_smart_attach_string_array (struct ua_variant *v, const char **val, size_t num) |
Smart attach a C string array as data for a variant. More... | |
BASE_EXPORT int | ua_variant_attach_extensionobject_array (struct ua_variant *v, void *array, size_t num, const struct ua_nodeid *type_id) |
Attach an array of complex objects to a variant as extensionobjects. More... | |
BASE_EXPORT int | ua_variant_set_matrix (struct ua_variant *v, enum ua_variant_type type, const void *values, size_t num, const int32_t *dimensions, int32_t num_dimensions) |
Stores the given matrix data in the variant. More... | |
Setter and attach functions for the ua_variant structure.
Setter functions set a copy of the value as the new value of the structure. Thus the original value must still be cleared.
Attach functions attach the original value as the new value of the structure. Thus the original value must NOT be cleared.
In both cases the original variant is not cleared, so if there is data contained in the variant ua_variant_clear must be called before calling any of these functions.
BASE_EXPORT int ua_variant_attach_array | ( | struct ua_variant * | v, |
enum ua_variant_type | type, | ||
void * | val, | ||
size_t | num | ||
) |
Attach an array value to the given variant.
This function takes ownership of the memory val
and must not be freed by the caller. The memory must be allocated using ipc_malloc.
v | Variant to attach the data to. |
type | The type of data. |
val | Address of array value. |
num | Number of elements in array. |
BASE_EXPORT int ua_variant_attach_extensionobject | ( | struct ua_variant * | v, |
void * | obj, | ||
const struct ua_nodeid * | type_id | ||
) |
Attach an encodable object as extensionobject to a variant.
On success the variant takes ownership of the object.
v | variant to attach object to. |
obj | object to attach. |
type_id | type of the object |
BASE_EXPORT int ua_variant_attach_extensionobject_array | ( | struct ua_variant * | v, |
void * | array, | ||
size_t | num, | ||
const struct ua_nodeid * | type_id | ||
) |
Attach an array of complex objects to a variant as extensionobjects.
Takes a plain array of objects and converts it into an array of extensionobjects to attach to the variant. Uses as little as possible allocations, so the objects from the array are shallow copied, the array itself is of no use and must be freed by the caller.
Works only for arrays where all objects are of the same type.
In case of an error the variant is left as NULL variant and the provided array is still valid.
v | Variant to attach array to. |
array | Array with complex objects. |
num | Number of objects in the array |
type_id | TypeId of the objects. |
BASE_EXPORT int ua_variant_attach_scalar | ( | struct ua_variant * | v, |
enum ua_variant_type | type, | ||
void * | val | ||
) |
Attach a scaler value to the given variant.
For simple non-pointer types (e.g. bool, int, float, ...) this is a simple memcpy and the value is not further touched.
For structures (e.g. Guid, NodeId, ByteString, ...) the pointer is attached and the variant takes ownership of the memory. So val
must not be freed and must have been allocated with ipc_malloc by the caller.
v | Variant to attach the data to. |
type | The type of data. |
val | Address of scalar value. |
BASE_EXPORT void ua_variant_attach_string | ( | struct ua_variant * | v, |
char * | val | ||
) |
Fills the given variant v
with an OPC UA String.
This function does not create a copy of the provided string val
. The string must be UTF-8 encoded. It is safe to pass a NULL pointer here, in this case the UA string becomes a NULL-String.
BASE_EXPORT void ua_variant_attach_stringn | ( | struct ua_variant * | v, |
char * | val, | ||
size_t | len | ||
) |
Fills the given variant v
with an OPC UA String.
This function behaves like ua_variant_attach_string, but avoids a strlen call by providing the string length as an additional parameter.
BASE_EXPORT int ua_variant_set_array | ( | struct ua_variant * | v, |
enum ua_variant_type | type, | ||
const void * | values, | ||
size_t | num | ||
) |
Stores the given array data in the variant.
This operation creates a copy of the given data.
v | The variant to work on. |
type | The datatype of the array elements. |
values | Array of values of type type . |
num | Number of elements in val . |
BASE_EXPORT void ua_variant_set_bool | ( | struct ua_variant * | v, |
bool | val | ||
) |
Write a boolean to the ua_variant val
.
BASE_EXPORT void ua_variant_set_byte | ( | struct ua_variant * | v, |
uint8_t | val | ||
) |
Write a byte(uint8) to the ua_variant val
.
BASE_EXPORT int ua_variant_set_bytestring | ( | struct ua_variant * | v, |
const char * | data, | ||
int | len | ||
) |
Fills the given variant v
with an OPC UA ByteString.
This function creates a copy of the provided data
.
BASE_EXPORT void ua_variant_set_datetime | ( | struct ua_variant * | v, |
ua_datetime | val | ||
) |
Write a double to the ua_variant val
.
BASE_EXPORT void ua_variant_set_double | ( | struct ua_variant * | v, |
double | val | ||
) |
Write a double to the ua_variant val
.
BASE_EXPORT int ua_variant_set_expandednodeid | ( | struct ua_variant * | v, |
const struct ua_expandednodeid * | id | ||
) |
Fills the given variant v
with an UA ExpandedNodeid.
This function creates a copy of the provided id
.
BASE_EXPORT int ua_variant_set_extensionobject | ( | struct ua_variant * | v, |
const void * | obj, | ||
const struct ua_nodeid * | type_id | ||
) |
Set an encodable object as extensionobject to a variant.
The variant receives a copy of the object, so the caller is responsible for deleting the object.
The type must be registered in the SDK's type system using ua_type_table_register_structure. The encoding_id will be set internally if the given type_id is known type.
The SDK will encode the object using the registered type information.
v | Variant which receives the extensionobject. |
obj | object to set. |
type_id | type of the object |
BASE_EXPORT int ua_variant_set_extensionobject_array | ( | struct ua_variant * | v, |
const void * | obj, | ||
size_t | num, | ||
const struct ua_nodeid * | type_id | ||
) |
Stores an array of custom structures in a variant.
The difficulty here is that according to how UA has defined this feature, the extensionobject does not store the native array in one extensionobject, but creates an array of extensionobjects, where each element just store one structure array element.
This function creates a deep copy of the gievn structure array.
It is allowed to use 0 for num
, which will create an empty array.
v | Variant to attach the data to. |
obj | Array of structure to store in the variant. |
num | Array size. |
type_id | type of the object. |
BASE_EXPORT int ua_variant_set_extensionobject_binary | ( | struct ua_variant * | v, |
const struct ua_bytestring * | data, | ||
const struct ua_nodeid * | encoding_id | ||
) |
Stores a pre-encoded binary extensionobject in the variant.
This function is used for custom structures which are encoded on application level. This structures must be pre-encoded in UA binary format. The SDK does not need to know this type, so they don't need to be registered at the SDK.
v | Variant which receives the extensionobject. |
data | Bytestring with pre-encoded UA binary data. |
encoding_id | EncodingId of the custom type. |
BASE_EXPORT int ua_variant_set_extensionobject_numeric | ( | struct ua_variant * | v, |
const void * | obj, | ||
uint16_t | nsindex, | ||
uint32_t | value | ||
) |
This is a convenience overload function for ua_variant_set_extensionobject() which allows settings UA defined structure types without creating helper variables for the typeid.
This also works for other non-UA defined types with numeric typeid. For performance reasons, most types are using numeric typeids anyway.
v | Variant which receives the extensionobject. |
obj | object to set. |
nsindex | The namespace index of the typeid. Zero for UA defined types. |
value | The numeric value of the typeid. You can use the generated defines UA_ID_* for this. |
BASE_EXPORT void ua_variant_set_float | ( | struct ua_variant * | v, |
float | val | ||
) |
Write a float to the ua_variant val
.
BASE_EXPORT int ua_variant_set_guid | ( | struct ua_variant * | v, |
const struct ua_guid * | guid | ||
) |
Fills the given variant v
with an UA GUID.
This function creates a copy of the provided guid
.
BASE_EXPORT void ua_variant_set_int16 | ( | struct ua_variant * | v, |
int16_t | val | ||
) |
Write an int16 to the ua_variant val
.
BASE_EXPORT void ua_variant_set_int32 | ( | struct ua_variant * | v, |
int32_t | val | ||
) |
Write an int32 to the ua_variant val
.
BASE_EXPORT void ua_variant_set_int64 | ( | struct ua_variant * | v, |
int64_t | val | ||
) |
Write an int64 to the ua_variant val
.
BASE_EXPORT int ua_variant_set_localizedtext | ( | struct ua_variant * | v, |
const char * | locale, | ||
const char * | text | ||
) |
Fills the given variant v
with an UA Localizedtext.
This function creates a copy of the provided locale
and text
.
BASE_EXPORT int ua_variant_set_matrix | ( | struct ua_variant * | v, |
enum ua_variant_type | type, | ||
const void * | values, | ||
size_t | num, | ||
const int32_t * | dimensions, | ||
int32_t | num_dimensions | ||
) |
Stores the given matrix data in the variant.
This operation creates a copy of the given data.
v | The variant to work on. |
type | The datatype of the array elements. |
values | The matrix data. This contains num values of type * type. |
num | Total number of elements in values |
dimensions | Array of matrix dimensions, where each elements contains the length of the matrix dimension. The lower rank dimension is encoded first. |
num_dimensions | Number of dimensions. This is the length of dimensions . |
BASE_EXPORT int ua_variant_set_nodeid | ( | struct ua_variant * | v, |
const struct ua_nodeid * | id | ||
) |
Fills the given variant v
with an UA Nodeid.
This function creates a copy of the provided id
.
BASE_EXPORT int ua_variant_set_qualifiedname | ( | struct ua_variant * | v, |
int | nsindex, | ||
const char * | name | ||
) |
Fills the given variant v
with an UA Qualifiedname.
This function creates a copy of the provided name
.
BASE_EXPORT void ua_variant_set_sbyte | ( | struct ua_variant * | v, |
int8_t | val | ||
) |
Write a signed byte(int8) to the ua_variant val
.
BASE_EXPORT int ua_variant_set_scalar | ( | struct ua_variant * | dst, |
enum ua_variant_type | type, | ||
const void * | val | ||
) |
Set a scalar as value for the variant dst
.
Creates as copy of the value pointed to by val
and sets it as value for the variant.
BASE_EXPORT int ua_variant_set_string | ( | struct ua_variant * | v, |
const char * | val | ||
) |
Fills the given variant v
with an OPC UA String.
This function creates a copy of the provided string val
. The string must be UTF-8 encoded. It is safe to pass a NULL pointer here, in this case the UA string becomes a NULL-String.
BASE_EXPORT int ua_variant_set_string_array | ( | struct ua_variant * | v, |
const char ** | val, | ||
size_t | num | ||
) |
Set a C string array as data for a variant.
v | Variant structure to set array. |
val | Array of C strings. |
num | Number of element in the array. |
BASE_EXPORT int ua_variant_set_stringn | ( | struct ua_variant * | v, |
const char * | val, | ||
size_t | len | ||
) |
Fills the given variant v
with an OPC UA String.
This function behaves like ua_variant_set_string, but avoids a strlen call by providing the string length as an additional parameter.
BASE_EXPORT void ua_variant_set_uint16 | ( | struct ua_variant * | v, |
uint16_t | val | ||
) |
Write an uint16 to the ua_variant val
.
BASE_EXPORT void ua_variant_set_uint32 | ( | struct ua_variant * | v, |
uint32_t | val | ||
) |
Write an uint32 to the ua_variant val
.
BASE_EXPORT void ua_variant_set_uint64 | ( | struct ua_variant * | v, |
uint64_t | val | ||
) |
Write an uint64 to the ua_variant val
.
BASE_EXPORT int ua_variant_set_xmlelement | ( | struct ua_variant * | v, |
const char * | data, | ||
int | len | ||
) |
Fills the given variant v
with an XML element.
This function creates a copy of the provided data
. This is technically equivalent to ua_variant_set_bytestring. But data should contain a valid UTF-8 encoded XML element. This code does not perform any XML validtion so the caller is responsible for providing valid data.
BASE_EXPORT int ua_variant_smart_attach_const_string | ( | struct ua_variant * | v, |
const char * | val | ||
) |
Fills the given variant v
with an OPC UA String.
When compiled without MEMORY_USE_SHM this simply attaches the string to the variant. When compiled with MEMORY_USE_SHM this creates a copy in shared memory, which is necessary to work across memory boundaries. Attaching a string is faster and consumes less memory than coping a string, so we try to avoid the latter one if possible.
BASE_EXPORT int ua_variant_smart_attach_const_stringn | ( | struct ua_variant * | v, |
const char * | val, | ||
size_t | len | ||
) |
Fills the given variant v
with an OPC UA String.
This function behaves like ua_variant_smart_attach_const_string, but avoids a strlen call by providing the string length as an additional parameter.
BASE_EXPORT int ua_variant_smart_attach_string_array | ( | struct ua_variant * | v, |
const char ** | val, | ||
size_t | num | ||
) |
Smart attach a C string array as data for a variant.
Similar to ua_variant_set_string_array but uses ua_string_smart_attach_const to set the individual array members. This is faster and consumes less memory when MEMORY_USE_SHM is disabled.