High Performance OPC UA Server SDK  1.2.1.203
UA File Format Writer

The file writer offers an API for creating file in the UA binary file format. More...

Data Structures

struct  ua_file_namespace
 
struct  ua_file_stringtable
 
struct  ua_file_writer
 UA File Writer. More...
 

Functions

void ua_file_namespace_init (struct ua_file_namespace *ns)
 
void ua_file_namespace_clear (struct ua_file_namespace *ns)
 
void ua_file_basenode_init (struct ua_file_basenode *node)
 
void ua_file_basenode_clear (struct ua_file_basenode *node)
 
int ua_file_basenode_set_nodeid (struct ua_file_basenode *n, struct ua_nodeid *id)
 
int ua_file_basenode_set_browsename (struct ua_file_basenode *n, struct ua_file_qualifiedname_ref *qn)
 
int ua_file_basenode_set_displayname (struct ua_file_basenode *n, struct ua_file_localizedtext_ref *lt)
 
int ua_file_basenode_set_description (struct ua_file_basenode *n, struct ua_file_localizedtext_ref *lt)
 
int ua_file_basenode_set_writemask (struct ua_file_basenode *n, uint32_t writemask)
 
int ua_file_basenode_add_extension (struct ua_file_basenode *n, struct ua_file_extension *ex)
 
void ua_file_variable_init (struct ua_file_variable *node)
 
void ua_file_variable_clear (struct ua_file_variable *node)
 
int ua_file_variable_set_value (struct ua_file_variable *n, struct ua_variant *value)
 
int ua_file_variable_set_datatype (struct ua_file_variable *n, struct ua_nodeid *datatype)
 
int ua_file_variable_set_valuerank (struct ua_file_variable *n, int32_t valuerank)
 
int ua_file_variable_set_arraydimensions (struct ua_file_variable *n, uint8_t num_dimensions, uint32_t *dimensions)
 
int ua_file_variable_set_accesslevel (struct ua_file_variable *n, uint8_t access_level)
 
int ua_file_variable_set_minimumsamplinginterval (struct ua_file_variable *n, uint32_t sampling_interval)
 
int ua_file_variable_set_historizing (struct ua_file_variable *n, bool historizing)
 
void ua_file_object_init (struct ua_file_object *node)
 
void ua_file_object_clear (struct ua_file_object *node)
 
int ua_file_object_set_eventnotifier (struct ua_file_object *n, uint8_t event_notifier)
 
void ua_file_method_init (struct ua_file_method *node)
 
void ua_file_method_clear (struct ua_file_method *node)
 
int ua_file_method_set_executable (struct ua_file_method *n, bool executable)
 
void ua_file_view_init (struct ua_file_view *node)
 
void ua_file_view_clear (struct ua_file_view *node)
 
int ua_file_view_set_eventnotifier (struct ua_file_view *n, uint8_t event_notifier)
 
int ua_file_view_set_containsnoloops (struct ua_file_view *n, bool contains_no_loops)
 
void ua_file_variabletype_init (struct ua_file_variabletype *node)
 
void ua_file_variabletype_clear (struct ua_file_variabletype *node)
 
int ua_file_variabletype_set_isabstract (struct ua_file_variabletype *n, bool isabstract)
 
int ua_file_variabletype_set_value (struct ua_file_variabletype *n, struct ua_variant *value)
 
int ua_file_variabletype_set_datatype (struct ua_file_variabletype *n, struct ua_nodeid *datatype)
 
int ua_file_variabletype_set_valuerank (struct ua_file_variabletype *n, int32_t valuerank)
 
int ua_file_variabletype_set_arraydimensions (struct ua_file_variabletype *n, uint8_t num_dimensions, uint32_t *dimensions)
 
void ua_file_objecttype_init (struct ua_file_objecttype *node)
 
void ua_file_objecttype_clear (struct ua_file_objecttype *node)
 
int ua_file_objecttype_set_isabstract (struct ua_file_objecttype *n, bool isabstract)
 
void ua_file_datatype_init (struct ua_file_datatype *node)
 
void ua_file_datatype_clear (struct ua_file_datatype *node)
 
int ua_file_datatype_set_isabstract (struct ua_file_datatype *n, bool isabstract)
 
int ua_file_datatype_set_datatypedefinition (struct ua_file_datatype *n, struct ua_file_datatypedefinition *dtdef)
 
void ua_file_referencetype_init (struct ua_file_referencetype *node)
 
void ua_file_referencetype_clear (struct ua_file_referencetype *node)
 
int ua_file_referencetype_set_isabstract (struct ua_file_referencetype *n, bool isabstract)
 
int ua_file_referencetype_set_symmetric (struct ua_file_referencetype *n, bool symmetric)
 
int ua_file_referencetype_set_inversename (struct ua_file_referencetype *n, struct ua_file_localizedtext_ref *inverse_name)
 
int ua_file_writer_init (struct ua_file_writer *w)
 Intializes the file writer context. More...
 
int ua_file_writer_clear (struct ua_file_writer *w)
 Cleans up the file writer context. More...
 
int ua_file_writer_init_registry (struct ua_file_writer *w, unsigned int size)
 Intializes the file writer extension registry. More...
 
int ua_file_writer_open (struct ua_file_writer *w, const char *filename)
 
int ua_file_writer_write_datatype (struct ua_file_writer *w, struct ua_file_datatype *dt)
 
int ua_file_writer_add_stringtables (struct ua_file_writer *w, unsigned int num_strings, const char *locales)
 
int ua_file_writer_add_string (struct ua_file_writer *w, unsigned int table_index, unsigned int string_index, char *text)
 Adds a new string to the given string table. More...
 
int ua_file_writer_add_namespace (struct ua_file_writer *w, const struct ua_file_namespace *ns)
 Adds a new namespace which is provided by this model. More...
 
int ua_file_writer_add_required_namespace (struct ua_file_writer *w, const struct ua_file_namespace *ns)
 Adds a required namespace which is needed for this model. More...
 
int ua_file_writer_add_extension_namespace (struct ua_file_writer *w, const char *nsuri)
 Adds a namespace for extensions. More...
 
int ua_file_writer_add_extension (struct ua_file_writer *w, struct ua_file_extension *ext)
 Adds a global extension to the file. More...
 
int ua_file_writer_add_datatype (struct ua_file_writer *w, struct ua_file_datatype *node)
 Adds a datatype node to the file.
 
int ua_file_writer_add_referencetype (struct ua_file_writer *w, struct ua_file_referencetype *node)
 Adds a referencetype node to the file.
 
int ua_file_writer_add_objecttype (struct ua_file_writer *w, struct ua_file_objecttype *node)
 Adds a objecttype node to the file.
 
int ua_file_writer_add_variabletype (struct ua_file_writer *w, struct ua_file_variabletype *node)
 Adds a variabletype node to the file.
 
int ua_file_writer_add_variable (struct ua_file_writer *w, struct ua_file_variable *node)
 Adds a variable node to the file.
 
int ua_file_writer_add_method (struct ua_file_writer *w, struct ua_file_method *node)
 Adds a method node to the file.
 
int ua_file_writer_add_object (struct ua_file_writer *w, struct ua_file_object *node)
 Adds a object node to the file.
 
int ua_file_writer_add_view (struct ua_file_writer *w, struct ua_file_view *node)
 Adds a view node to the file.
 
int ua_file_writer_add_reference (struct ua_file_writer *w, struct ua_nodeid *src, struct ua_nodeid *dst, struct ua_nodeid *type)
 Adds a reference to the file.
 
int ua_file_writer_close (struct ua_file_writer *w)
 Closes the file opened by ua_file_writer_open. More...
 

Detailed Description

The file writer offers an API for creating file in the UA binary file format.

Creating files is designed for the PC use case to create binary files in engineering use cases whih are then downloaded to embedded devices running a High Performance OPC UA server.

The binary files contains the information model of the server, but can be enriched with customer specific information like e.g. a runtime address of variables using the ua_file_extension mechanism.

It is important to understand that the API does not cache the address space, but directly writes into the file. Therefor your MUST use the correct order of calls.

  1. Intialize the file writer using ua_file_writer_init()
  2. Add model meta data: number of nodes, namespaces, stringtables, etc.
  3. Open the file for writing using ua_file_writer_open()
  4. Add nodes
    1. Add data types using ua_file_writer_add_datatype()
    2. add reference types using ua_file_writer_add_referencetype()
    3. add variable types using ua_file_writer_add_variabletype()
    4. add object types using ua_file_writer_add_objecttype()
    5. add variables using ua_file_writer_add_variable()
    6. add objects using ua_file_writer_add_object()
    7. add methods using ua_file_writer_add_method()
    8. add views using ua_file_writer_add_view()
  5. Add references using ua_file_writer_add_reference()
  6. Close the file open file using ua_file_writer_close()
  7. Clean up file writer context using ua_file_writer_clear()

The following snippet from the example filewriter_demo/demo.c demonstrates the usage.

/* initialize file writer context */
/* START META DATA: fill meta data before opening the file for writing. */
/* create string tables */
ua_file_writer_add_stringtables(&w, NUM_STRINGS, "en-US;it-IT");
for (i = 0; i < NUM_STRINGS; ++i) {
ua_file_writer_add_string(&w, 0, i, (char*)g_strings_en[i]);
ua_file_writer_add_string(&w, 1, i, (char*)g_strings_it[i]);
}
/* add required namespaces: This demo depends on NS0 only */
ua_file_namespace_init(&ns);
ns.nsidx = 0;
ns.nsuri = "http://opcfoundation.org/UA/";
ua_file_namespace_clear(&ns);
/* add provided namespaces: This demo creates one new namespace */
ua_file_namespace_init(&ns);
ns.nsidx = FRUITS_NSIDX;
ns.nsuri = FRUITS_NSURI;
for (i = 0; i < countof(g_addrspace); ++i) {
ns.stat.num_numerics++; /* count numeric nodeids */
switch (g_addrspace[i].type) {
case VARTYPE_FOLDER:
ns.stat.num_objects++; /* count objects */
break;
case VARTYPE_VARIABLE:
case VARTYPE_PROPERTY:
ns.stat.num_variables++; /* count variables */
break;
}
ns.stat.num_references += 2; /* count numeric nodeids */
}
/* set total number of nodes for global file header: this is the sum of
* the provided ns stat entries. We only add one namespace so this is identical
* as above.
*/
w.stat = ns.stat;
ua_file_namespace_clear(&ns);
/* create extension registry: this is necessary for adding extensions */
/* END META DATA */
/* open/create the file for writing, this will implicitly write the
* file header, global extensions, string tables, and namesapce tables. */
ua_file_writer_open(&w, filename);
create_nodes(&w);
create_references(&w);

Function Documentation

int ua_file_writer_add_extension ( struct ua_file_writer w,
struct ua_file_extension ext 
)

Adds a global extension to the file.

Parameters
wpointer to file writer
extextension to add.
See also
ua_file_extensions_add
int ua_file_writer_add_extension_namespace ( struct ua_file_writer w,
const char *  nsuri 
)

Adds a namespace for extensions.

Parameters
wpointer to file writer
nsuriNamespace URI to add.
Returns
Returns a positive nsidx for the URI on succes, or a negative error code.
See also
ua_file_extension_registry_add_uri
int ua_file_writer_add_namespace ( struct ua_file_writer w,
const struct ua_file_namespace ns 
)

Adds a new namespace which is provided by this model.

Parameters
wpointer to file writer
nsNamespace information to add.
Returns
Zero on success, -1 on error.
int ua_file_writer_add_required_namespace ( struct ua_file_writer w,
const struct ua_file_namespace ns 
)

Adds a required namespace which is needed for this model.

Parameters
wpointer to file writer
nsNamespace information to add.
Returns
Zero on success, -1 on error.
int ua_file_writer_add_string ( struct ua_file_writer w,
unsigned int  table_index,
unsigned int  string_index,
char *  text 
)

Adds a new string to the given string table.

Parameters
wpointer to file writer
table_indexThe table index created with ua_file_writer_add_stringtables
string_indexThe string index for text.
textThe string to add.
Returns
Zero on success, -1 on error.
int ua_file_writer_clear ( struct ua_file_writer w)

Cleans up the file writer context.

int ua_file_writer_close ( struct ua_file_writer w)

Closes the file opened by ua_file_writer_open.

Parameters
wpointer to file writer
Returns
Zero on success, or a negative error code.
int ua_file_writer_init ( struct ua_file_writer w)

Intializes the file writer context.

int ua_file_writer_init_registry ( struct ua_file_writer w,
unsigned int  size 
)

Intializes the file writer extension registry.

Parameters
wpointer to file writer
sizeRegistry size.
See also
ua_file_extension_registry_init
Returns
Zero on success, UA_EBADNOMEM if memory allocation failed.