gmerlin
Typedefs | Functions
Configuration section

Typedefs

typedef struct bg_cfg_section_s bg_cfg_section_t
 Configuration section.
 

Functions

void bg_cfg_section_2_xml (const bg_cfg_section_t *section, xmlNodePtr xml_section)
 Convert a configuration section into a libxml2 node.
 
void bg_cfg_xml_2_section (xmlDocPtr xml_doc, xmlNodePtr xml_section, bg_cfg_section_t *section)
 Convert libxml2 node into a configuration section.
 
void bg_cfg_section_dump (bg_cfg_section_t *section, const char *filename)
 Dump a config section to a file.
 
bg_cfg_section_tbg_cfg_section_find_subsection (bg_cfg_section_t *section, const char *name)
 Find a child of a section.
 
bg_cfg_section_tbg_cfg_section_create_subsection_at_pos (bg_cfg_section_t *section, int pos)
 Create a subsection at the specified position.
 
void bg_cfg_section_move_child (bg_cfg_section_t *section, bg_cfg_section_t *child, int pos)
 Move a subsection to the specified position.
 
bg_cfg_section_tbg_cfg_section_find_subsection_by_index (bg_cfg_section_t *section, int index)
 Find a child of a section by index.
 
bg_cfg_section_tbg_cfg_section_create (const char *name)
 Create an empty config section.
 
bg_cfg_section_tbg_cfg_section_create_from_parameters (const char *name, const bg_parameter_info_t *parameters)
 Create a config section from a parameter array.
 
void bg_cfg_section_create_items (bg_cfg_section_t *section, const bg_parameter_info_t *parameters)
 Create items from a parameter info.
 
void bg_cfg_section_destroy (bg_cfg_section_t *section)
 Destroy a config section.
 
bg_cfg_section_tbg_cfg_section_copy (const bg_cfg_section_t *src)
 Duplicate a configuration section.
 
void bg_cfg_section_transfer (bg_cfg_section_t *src, bg_cfg_section_t *dst)
 Set values in a configuration section from another section.
 
void bg_cfg_section_transfer_children (bg_cfg_section_t *src, bg_cfg_section_t *dst)
 Like bg_cfg_section_transfer but acts only on the subsections.
 
void bg_cfg_section_add_ref (bg_cfg_section_t *section, bg_cfg_section_t *ref)
 Insert a reference to a section as child.
 
const char * bg_cfg_section_get_name (bg_cfg_section_t *section)
 Get the name of a configuration section.
 
char * bg_cfg_section_get_name_translated (bg_cfg_section_t *section)
 Get the translated name of a configuration section.
 
void bg_cfg_section_set_name (bg_cfg_section_t *section, const char *name, const char *gettext_domain, const char *gettext_directory)
 Set the name of a configuration section.
 
void bg_cfg_section_set_parameter (bg_cfg_section_t *section, const bg_parameter_info_t *info, const bg_parameter_value_t *value)
 Store a value in the section.
 
int bg_cfg_section_set_parameters_from_string (bg_cfg_section_t *section, const bg_parameter_info_t *info, const char *str)
 Set values from an option string.
 
void bg_cfg_section_get_parameter (bg_cfg_section_t *section, const bg_parameter_info_t *info, bg_parameter_value_t *value)
 Read a value from the section.
 
void bg_cfg_section_delete_subsection (bg_cfg_section_t *section, bg_cfg_section_t *subsection)
 Delete a subsection.
 
void bg_cfg_section_delete_subsections (bg_cfg_section_t *section)
 Delete all subsections.
 
void bg_cfg_section_set_parameter_int (bg_cfg_section_t *section, const char *name, int value)
 Store an integer value in a section.
 
void bg_cfg_section_set_parameter_float (bg_cfg_section_t *section, const char *name, float value)
 Store a float value in a section.
 
void bg_cfg_section_set_parameter_string (bg_cfg_section_t *section, const char *name, const char *value)
 Store a string value in a section.
 
void bg_cfg_section_set_parameter_time (bg_cfg_section_t *section, const char *name, gavl_time_t value)
 Store a time value in a section.
 
int bg_cfg_section_get_parameter_int (bg_cfg_section_t *section, const char *name, int *value)
 Get an integer value from a section.
 
int bg_cfg_section_get_parameter_float (bg_cfg_section_t *section, const char *name, float *value)
 Get an float value from a section.
 
int bg_cfg_section_get_parameter_string (bg_cfg_section_t *section, const char *name, const char **value)
 Get an string value from a section.
 
int bg_cfg_section_get_parameter_time (bg_cfg_section_t *section, const char *name, gavl_time_t *value)
 Get an time value from a section.
 
void bg_cfg_section_apply (bg_cfg_section_t *section, const bg_parameter_info_t *parameters, bg_set_parameter_func_t func, void *callback_data)
 Send all parameters to a module.
 
void bg_cfg_section_apply_noterminate (bg_cfg_section_t *section, const bg_parameter_info_t *infos, bg_set_parameter_func_t func, void *callback_data)
 Send all parameters to a module without terminating.
 
void bg_cfg_section_get (bg_cfg_section_t *section, const bg_parameter_info_t *parameters, bg_get_parameter_func_t func, void *callback_data)
 Get parameters from a module.
 
int bg_cfg_section_has_subsection (bg_cfg_section_t *section, const char *name)
 Qurey if a child section is available.
 
void bg_cfg_section_restore_defaults (bg_cfg_section_t *section, const bg_parameter_info_t *info)
 Restore default values of a section.
 

Detailed Description

Sections are nodes in the configuration tree. They can contain name-value pairs and child sections. Usually, config sections are kept within a configuration registry to store the applications configuration data.

They can, however, be used indepentently from a registry as universal data containers.

Typedef Documentation

◆ bg_cfg_section_t

typedef struct bg_cfg_section_s bg_cfg_section_t

Configuration section.

Opaque container for configuration data and child sections

Function Documentation

◆ bg_cfg_section_2_xml()

void bg_cfg_section_2_xml ( const bg_cfg_section_t * section,
xmlNodePtr xml_section )

Convert a configuration section into a libxml2 node.

Parameters
sectionConfiguration section
xml_sectionPointer to the xml node for the section

See the libxml2 documentation for more infos

◆ bg_cfg_xml_2_section()

void bg_cfg_xml_2_section ( xmlDocPtr xml_doc,
xmlNodePtr xml_section,
bg_cfg_section_t * section )

Convert libxml2 node into a configuration section.

Parameters
xml_docPointer to the xml document
xml_sectionPointer to the xml node for the section
sectionConfiguration section

See the libxml2 documentation for more infos

◆ bg_cfg_section_dump()

void bg_cfg_section_dump ( bg_cfg_section_t * section,
const char * filename )

Dump a config section to a file.

Parameters
sectionConfiguration section
filenameFile to write this to

Used for debugging

◆ bg_cfg_section_find_subsection()

bg_cfg_section_t * bg_cfg_section_find_subsection ( bg_cfg_section_t * section,
const char * name )

Find a child of a section.

Parameters
sectionA configuration section
namename of the subsection
Returns
Configuration section

If the child section does not exist, an empty section is created.

◆ bg_cfg_section_create_subsection_at_pos()

bg_cfg_section_t * bg_cfg_section_create_subsection_at_pos ( bg_cfg_section_t * section,
int pos )

Create a subsection at the specified position.

Parameters
sectionA configuration section
posPosition of the subsection (starting with 0)
Returns
Configuration section

◆ bg_cfg_section_move_child()

void bg_cfg_section_move_child ( bg_cfg_section_t * section,
bg_cfg_section_t * child,
int pos )

Move a subsection to the specified position.

Parameters
sectionA configuration section
childSubsection to be moved
posNew position of the subsection (starting with 0)

◆ bg_cfg_section_find_subsection_by_index()

bg_cfg_section_t * bg_cfg_section_find_subsection_by_index ( bg_cfg_section_t * section,
int index )

Find a child of a section by index.

Parameters
sectionA configuration section
indexIndex (starting with 0)
Returns
Configuration section

If the child section does not exist, NULL is returned.

◆ bg_cfg_section_create()

bg_cfg_section_t * bg_cfg_section_create ( const char * name)

Create an empty config section.

Parameters
nameName
Returns
Configuration section

◆ bg_cfg_section_create_from_parameters()

bg_cfg_section_t * bg_cfg_section_create_from_parameters ( const char * name,
const bg_parameter_info_t * parameters )

Create a config section from a parameter array.

Parameters
nameName
parametersA parameter array
Returns
Configuration section

Creates a configuration section from a parameter array. The values in the section are set from the defaults given in the array.

◆ bg_cfg_section_create_items()

void bg_cfg_section_create_items ( bg_cfg_section_t * section,
const bg_parameter_info_t * parameters )

Create items from a parameter info.

Parameters
sectionConfiguration section
parametersA parameter array

This iterates through parameters and creates all missing entries with the values set to their defaults

◆ bg_cfg_section_destroy()

void bg_cfg_section_destroy ( bg_cfg_section_t * section)

Destroy a config section.

Parameters
sectionConfiguration section

◆ bg_cfg_section_copy()

bg_cfg_section_t * bg_cfg_section_copy ( const bg_cfg_section_t * src)

Duplicate a configuration section.

Parameters
srcConfiguration section
Returns
A newly allocated section with all values copied from src.

◆ bg_cfg_section_transfer()

void bg_cfg_section_transfer ( bg_cfg_section_t * src,
bg_cfg_section_t * dst )

Set values in a configuration section from another section.

Parameters
srcSource section
dstDestination section

This function iterates through all entries of src and copies the values to dst. Values, which don't exist in dst, are created. The same is then done for all children of src.

◆ bg_cfg_section_transfer_children()

void bg_cfg_section_transfer_children ( bg_cfg_section_t * src,
bg_cfg_section_t * dst )

Like bg_cfg_section_transfer but acts only on the subsections.

Parameters
srcSource section
dstDestination section

◆ bg_cfg_section_add_ref()

void bg_cfg_section_add_ref ( bg_cfg_section_t * section,
bg_cfg_section_t * ref )

Insert a reference to a section as child.

Parameters
sectionConfiguration section
refChild section to be added as reference

◆ bg_cfg_section_get_name()

const char * bg_cfg_section_get_name ( bg_cfg_section_t * section)

Get the name of a configuration section.

Parameters
sectionConfiguration section
Returns
The name

◆ bg_cfg_section_get_name_translated()

char * bg_cfg_section_get_name_translated ( bg_cfg_section_t * section)

Get the translated name of a configuration section.

Parameters
sectionConfiguration section
Returns
The translated name

The returned string must be freed by the caller

◆ bg_cfg_section_set_name()

void bg_cfg_section_set_name ( bg_cfg_section_t * section,
const char * name,
const char * gettext_domain,
const char * gettext_directory )

Set the name of a configuration section.

Parameters
sectionConfiguration section
nameThe new name
gettext_domainFirst argument for bindtextdomain()
gettext_directorySecond argument for bindtextdomain()

◆ bg_cfg_section_set_parameter()

void bg_cfg_section_set_parameter ( bg_cfg_section_t * section,
const bg_parameter_info_t * info,
const bg_parameter_value_t * value )

Store a value in the section.

Parameters
sectionThe configuration section
infoThe parameter destription
valueThe value to be stored

If the value does not exist in the section, it is created from the parameter description.

◆ bg_cfg_section_set_parameters_from_string()

int bg_cfg_section_set_parameters_from_string ( bg_cfg_section_t * section,
const bg_parameter_info_t * info,
const char * str )

Set values from an option string.

Parameters
sectionThe configuration section
infoThe parameter destription
strA string describing the values

This takes a string from the commandline and stores it in the section.

Todo
Document syntax for all parameter types

◆ bg_cfg_section_get_parameter()

void bg_cfg_section_get_parameter ( bg_cfg_section_t * section,
const bg_parameter_info_t * info,
bg_parameter_value_t * value )

Read a value from the section.

Parameters
sectionThe configuration section
infoThe parameter destription
valueThe value will be stored here

If the value does not exist in the section, it is created from the parameter description.

◆ bg_cfg_section_delete_subsection()

void bg_cfg_section_delete_subsection ( bg_cfg_section_t * section,
bg_cfg_section_t * subsection )

Delete a subsection.

Parameters
sectionThe configuration section
subsectionThe child section to be deleten

If the subsection if no child of section, this function does nothing.

◆ bg_cfg_section_delete_subsections()

void bg_cfg_section_delete_subsections ( bg_cfg_section_t * section)

Delete all subsections.

Parameters
sectionThe configuration section

◆ bg_cfg_section_set_parameter_int()

void bg_cfg_section_set_parameter_int ( bg_cfg_section_t * section,
const char * name,
int value )

Store an integer value in a section.

Parameters
sectionThe configuration section
nameName of the entry
valueValue to be stored

◆ bg_cfg_section_set_parameter_float()

void bg_cfg_section_set_parameter_float ( bg_cfg_section_t * section,
const char * name,
float value )

Store a float value in a section.

Parameters
sectionThe configuration section
nameName of the entry
valueValue to be stored

◆ bg_cfg_section_set_parameter_string()

void bg_cfg_section_set_parameter_string ( bg_cfg_section_t * section,
const char * name,
const char * value )

Store a string value in a section.

Parameters
sectionThe configuration section
nameName of the entry
valueValue to be stored

◆ bg_cfg_section_set_parameter_time()

void bg_cfg_section_set_parameter_time ( bg_cfg_section_t * section,
const char * name,
gavl_time_t value )

Store a time value in a section.

Parameters
sectionThe configuration section
nameName of the entry
valueValue to be stored

◆ bg_cfg_section_get_parameter_int()

int bg_cfg_section_get_parameter_int ( bg_cfg_section_t * section,
const char * name,
int * value )

Get an integer value from a section.

Parameters
sectionThe configuration section
nameName of the entry
valueReturns value
Returns
1 if entry was available, 0 else.

◆ bg_cfg_section_get_parameter_float()

int bg_cfg_section_get_parameter_float ( bg_cfg_section_t * section,
const char * name,
float * value )

Get an float value from a section.

Parameters
sectionThe configuration section
nameName of the entry
valueReturns value
Returns
1 if entry was available, 0 else.

◆ bg_cfg_section_get_parameter_string()

int bg_cfg_section_get_parameter_string ( bg_cfg_section_t * section,
const char * name,
const char ** value )

Get an string value from a section.

Parameters
sectionThe configuration section
nameName of the entry
valueReturns value
Returns
1 if entry was available, 0 else.

◆ bg_cfg_section_get_parameter_time()

int bg_cfg_section_get_parameter_time ( bg_cfg_section_t * section,
const char * name,
gavl_time_t * value )

Get an time value from a section.

Parameters
sectionThe configuration section
nameName of the entry
valueReturns value
Returns
1 if entry was available, 0 else.

◆ bg_cfg_section_apply()

void bg_cfg_section_apply ( bg_cfg_section_t * section,
const bg_parameter_info_t * parameters,
bg_set_parameter_func_t func,
void * callback_data )

Send all parameters to a module.

Parameters
sectionThe configuration section
parametersParameter array
funcFunction to be called
callback_dataFirst argument passed to func

This function iterates though all parameters and calls func with the stored values. It is the main function to transfer data from the section to a module.

◆ bg_cfg_section_apply_noterminate()

void bg_cfg_section_apply_noterminate ( bg_cfg_section_t * section,
const bg_parameter_info_t * infos,
bg_set_parameter_func_t func,
void * callback_data )

Send all parameters to a module without terminating.

Parameters
sectionThe configuration section
infosParameter array
funcFunction to be called
callback_dataFirst argument passed to func

This function works like bg_cfg_section_apply but doesn't call func with a NULL name argument at the end.

◆ bg_cfg_section_get()

void bg_cfg_section_get ( bg_cfg_section_t * section,
const bg_parameter_info_t * parameters,
bg_get_parameter_func_t func,
void * callback_data )

Get parameters from a module.

Parameters
sectionThe configuration section
parametersParameter array
funcFunction to be called
callback_dataFirst argument passed to func

This function iterates though all parameters and calls func with the stored values. It is the main function to transfer data from the module to a section. It is used only, if the module has parameters, which are changed internally.

◆ bg_cfg_section_has_subsection()

int bg_cfg_section_has_subsection ( bg_cfg_section_t * section,
const char * name )

Qurey if a child section is available.

Parameters
sectionThe configuration section
nameName of the child section
Returns
1 if the child section is available, 0 else.

◆ bg_cfg_section_restore_defaults()

void bg_cfg_section_restore_defaults ( bg_cfg_section_t * section,
const bg_parameter_info_t * info )

Restore default values of a section.

Parameters
sectionThe configuration section
infoParameter info