Libecoli 0.4.0
Extensible COmmand LIne library
 
Loading...
Searching...
No Matches
Node configuration

Configure nodes behavior through generic API. More...

Data Structures

struct  ec_config_schema
 
struct  ec_config
 

Enumerations

enum  ec_config_type {
  EC_CONFIG_TYPE_NONE = 0 , EC_CONFIG_TYPE_BOOL , EC_CONFIG_TYPE_INT64 , EC_CONFIG_TYPE_UINT64 ,
  EC_CONFIG_TYPE_STRING , EC_CONFIG_TYPE_NODE , EC_CONFIG_TYPE_LIST , EC_CONFIG_TYPE_DICT
}
 

Functions

int ec_config_schema_validate (const struct ec_config_schema *schema)
 
void ec_config_schema_dump (FILE *out, const struct ec_config_schema *schema)
 
const struct ec_config_schemaec_config_schema_lookup (const struct ec_config_schema *schema, const char *key)
 
enum ec_config_type ec_config_schema_type (const struct ec_config_schema *schema_elt)
 
const struct ec_config_schemaec_config_schema_sub (const struct ec_config_schema *schema_elt)
 
bool ec_config_key_is_reserved (const char *name)
 
enum ec_config_type ec_config_get_type (const struct ec_config *config)
 
struct ec_configec_config_bool (bool boolean)
 
struct ec_configec_config_i64 (int64_t i64)
 
struct ec_configec_config_u64 (uint64_t u64)
 
struct ec_configec_config_string (const char *string)
 
struct ec_configec_config_node (struct ec_node *node)
 
struct ec_configec_config_dict (void)
 
struct ec_configec_config_list (void)
 
int ec_config_list_add (struct ec_config *list, struct ec_config *value)
 
int ec_config_list_del (struct ec_config *list, struct ec_config *config)
 
ssize_t ec_config_count (const struct ec_config *config)
 
int ec_config_validate (const struct ec_config *dict, const struct ec_config_schema *schema)
 
int ec_config_dict_set (struct ec_config *dict, const char *key, struct ec_config *value)
 
int ec_config_dict_del (struct ec_config *dict, const char *key)
 
int ec_config_cmp (const struct ec_config *config1, const struct ec_config *config2)
 
struct ec_configec_config_dict_get (const struct ec_config *config, const char *key)
 
struct ec_configec_config_list_first (struct ec_config *list)
 
struct ec_configec_config_list_next (struct ec_config *list, struct ec_config *config)
 
void ec_config_free (struct ec_config *config)
 
struct ec_configec_config_dup (const struct ec_config *config)
 
void ec_config_dump (FILE *out, const struct ec_config *config)
 
struct ec_node ** ec_node_config_node_list_to_table (const struct ec_config *config, size_t *len)
 
struct ec_configec_node_config_node_list_from_vargs (va_list ap)
 

Variables

const char * ec_config_reserved_keys []
 

Detailed Description

Configure nodes behavior through generic API.

Helpers that are commonly used in nodes.

Enumeration Type Documentation

◆ ec_config_type

The type identifier for a config value.

Definition at line 26 of file ecoli_config.h.

Function Documentation

◆ ec_config_schema_validate()

int ec_config_schema_validate ( const struct ec_config_schema * schema)

Validate a configuration schema array.

Parameters
schemaPointer to the first element of the schema array. The array must be terminated by a sentinel entry (type == EC_CONFIG_TYPE_NONE).
Returns
0 if the schema is valid, or -1 on error (errno is set).

◆ ec_config_schema_dump()

void ec_config_schema_dump ( FILE * out,
const struct ec_config_schema * schema )

Dump a configuration schema array.

Parameters
outOutput stream on which the dump will be sent.
schemaPointer to the first element of the schema array. The array must be terminated by a sentinel entry (type == EC_CONFIG_TYPE_NONE).

◆ ec_config_schema_lookup()

const struct ec_config_schema * ec_config_schema_lookup ( const struct ec_config_schema * schema,
const char * key )

Find a schema entry matching the key.

Browse the schema array and lookup for the given key.

Parameters
schemaPointer to the first element of the schema array. The array must be terminated by a sentinel entry (type == EC_CONFIG_TYPE_NONE).
keySchema key name.
Returns
The schema entry if it matches a key, or NULL if not found.

◆ ec_config_schema_type()

enum ec_config_type ec_config_schema_type ( const struct ec_config_schema * schema_elt)

Get the type of a schema entry.

Parameters
schema_eltPointer to an element of the schema array.
Returns
The type of the schema entry.

◆ ec_config_schema_sub()

const struct ec_config_schema * ec_config_schema_sub ( const struct ec_config_schema * schema_elt)

Get the subschema of a schema entry.

Parameters
schema_eltPointer to an element of the schema array.
Returns
The subschema if any, or NULL.

◆ ec_config_key_is_reserved()

bool ec_config_key_is_reserved ( const char * name)

Check if a key name is reserved in a config dict.

Some key names are reserved and should not be used in configs.

Parameters
nameThe name of the key to test.
Returns
True if the key name is reserved and must not be used, else false.

◆ ec_config_get_type()

enum ec_config_type ec_config_get_type ( const struct ec_config * config)

Get the type of the configuration.

Parameters
configThe configuration.
Returns
The configuration type.

◆ ec_config_bool()

struct ec_config * ec_config_bool ( bool boolean)

Create a boolean configuration value.

Parameters
booleanThe boolean value to be set.
Returns
The configuration object, or NULL on error (errno is set).

◆ ec_config_i64()

struct ec_config * ec_config_i64 ( int64_t i64)

Create a signed integer configuration value.

Parameters
i64The signed integer value to be set.
Returns
The configuration object, or NULL on error (errno is set).

◆ ec_config_u64()

struct ec_config * ec_config_u64 ( uint64_t u64)

Create an unsigned configuration value.

Parameters
u64The unsigned integer value to be set.
Returns
The configuration object, or NULL on error (errno is set).

◆ ec_config_string()

struct ec_config * ec_config_string ( const char * string)

Create a string configuration value.

Parameters
stringThe string value to be set. The string is copied into the configuration object.
Returns
The configuration object, or NULL on error (errno is set).

◆ ec_config_node()

struct ec_config * ec_config_node ( struct ec_node * node)

Create a node configuration value.

Parameters
nodeThe node pointer to be set. The node is "consumed" by the function and should not be used by the caller, even on error. The caller can use ec_node_clone() to keep a reference on the node.
Returns
The configuration object, or NULL on error (errno is set).

◆ ec_config_dict()

struct ec_config * ec_config_dict ( void )

Create a hash table configuration value.

Returns
A configuration object containing an empty hash table, or NULL on error (errno is set).

◆ ec_config_list()

struct ec_config * ec_config_list ( void )

Create a list configuration value.

Returns
The configuration object containing an empty list, or NULL on error (errno is set).

◆ ec_config_list_add()

int ec_config_list_add ( struct ec_config * list,
struct ec_config * value )

Add a config object into a list.

Parameters
listThe list configuration in which the value will be added.
valueThe value configuration to add in the list. The value object will be freed when freeing the list object. On error, the value object is also freed.
Returns
0 on success, else -1 (errno is set).

◆ ec_config_list_del()

int ec_config_list_del ( struct ec_config * list,
struct ec_config * config )

Remove an element from a list.

The element is freed and should not be accessed.

Parameters
listThe list configuration.
configThe element to remove from the list.
Returns
0 on success, -1 on error (errno is set).

◆ ec_config_count()

ssize_t ec_config_count ( const struct ec_config * config)

Count the number of elements in a list or dict.

Parameters
configThe configuration that must be a list or a dict.
Returns
The number of elements, or -1 on error (errno is set).

◆ ec_config_validate()

int ec_config_validate ( const struct ec_config * dict,
const struct ec_config_schema * schema )

Validate a configuration.

Parameters
dictA hash table configuration to validate.
schemaPointer to the first element of the schema array. The array must be terminated by a sentinel entry (type == EC_CONFIG_TYPE_NONE).
Returns
0 on success, -1 on error (errno is set).

◆ ec_config_dict_set()

int ec_config_dict_set ( struct ec_config * dict,
const char * key,
struct ec_config * value )

Set a value in a hash table configuration

Parameters
dictA hash table configuration to validate.
keyThe key to update.
valueThe value to set. The value object will be freed when freeing the dict object. On error, the value object is also freed.
Returns
0 on success, -1 on error (errno is set).

◆ ec_config_dict_del()

int ec_config_dict_del ( struct ec_config * dict,
const char * key )

Remove an element from a hash table configuration.

The element is freed and should not be accessed.

Parameters
dictA hash table configuration to validate.
keyThe key of the configuration to delete.
Returns
0 on success, -1 on error (errno is set).

◆ ec_config_cmp()

int ec_config_cmp ( const struct ec_config * config1,
const struct ec_config * config2 )

Compare two configurations.

Compare two configurations.

Returns
0 if the configurations are equal, else -1.

◆ ec_config_dict_get()

struct ec_config * ec_config_dict_get ( const struct ec_config * config,
const char * key )

Get configuration value.

◆ ec_config_list_first()

struct ec_config * ec_config_list_first ( struct ec_config * list)

Get the first element of a list.

Example of use:

for (config = ec_config_list_iter(list); config != NULL; config = ec_config_list_next(list, config)) { ... }

Parameters
listThe list configuration to iterate.
Returns
The first configuration element, or NULL on error (errno is set).

◆ ec_config_list_next()

struct ec_config * ec_config_list_next ( struct ec_config * list,
struct ec_config * config )

Get next element in list.

Parameters
listThe list configuration beeing iterated.
configThe current configuration element.
Returns
The next configuration element, or NULL if there is no more element.

◆ ec_config_free()

void ec_config_free ( struct ec_config * config)

Free a configuration.

Parameters
configThe element to free.

◆ ec_config_dup()

struct ec_config * ec_config_dup ( const struct ec_config * config)

Duplicate a configuration.

Parameters
configThe configuration to duplicate.
Returns
The duplicated configuration, or NULL on error (errno is set).

◆ ec_config_dump()

void ec_config_dump ( FILE * out,
const struct ec_config * config )

Dump a configuration.

Parameters
outOutput stream on which the dump will be sent.
configThe configuration to dump.

◆ ec_node_config_node_list_to_table()

struct ec_node ** ec_node_config_node_list_to_table ( const struct ec_config * config,
size_t * len )

Build a node table from a node list in a ec_config.

The function takes a node configuration as parameter, which must be a node list. From it, a node table is built. A reference is taken for each node.

On error, no reference is taken.

Parameters
configThe configuration (type must be a list of nodes). If it is NULL, an error is returned.
lenThe length of the allocated table on success, or 0 on error.
Returns
The allocated node table, that must be freed by the caller: each entry must be freed with ec_node_free() and the table with ec_free(). On error, NULL is returned and errno is set.

◆ ec_node_config_node_list_from_vargs()

struct ec_config * ec_node_config_node_list_from_vargs ( va_list ap)

Build a list of config nodes from variable arguments.

The va_list argument is a list of pointer to ec_node structures, terminated with EC_VA_END.

This helper is used by nodes that contain a list of nodes, like "seq", "or", ...

Parameters
apList of pointer to ec_node structures, terminated with EC_VA_END.
Returns
A pointer to an ec_config structure. In this case, the nodes will be freed when the config structure will be freed. On error, NULL is returned (and errno is set), and the nodes are freed.

Variable Documentation

◆ ec_config_reserved_keys

const char* ec_config_reserved_keys[]
extern

Array of reserved key names.