Configure nodes behavior through generic API.
More...
|
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
} |
|
|
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_schema * | ec_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_schema * | ec_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_config * | ec_config_bool (bool boolean) |
|
struct ec_config * | ec_config_i64 (int64_t i64) |
|
struct ec_config * | ec_config_u64 (uint64_t u64) |
|
struct ec_config * | ec_config_string (const char *string) |
|
struct ec_config * | ec_config_node (struct ec_node *node) |
|
struct ec_config * | ec_config_dict (void) |
|
struct ec_config * | ec_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_config * | ec_config_dict_get (const struct ec_config *config, const char *key) |
|
struct ec_config * | ec_config_list_first (struct ec_config *list) |
|
struct ec_config * | ec_config_list_next (struct ec_config *list, struct ec_config *config) |
|
void | ec_config_free (struct ec_config *config) |
|
struct ec_config * | ec_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_config * | ec_node_config_node_list_from_vargs (va_list ap) |
|
Configure nodes behavior through generic API.
Helpers that are commonly used in nodes.
◆ ec_config_type
The type identifier for a config value.
Definition at line 26 of file ecoli_config.h.
◆ ec_config_schema_validate()
Validate a configuration schema array.
- Parameters
-
schema | Pointer 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
-
out | Output stream on which the dump will be sent. |
schema | Pointer 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()
Find a schema entry matching the key.
Browse the schema array and lookup for the given key.
- Parameters
-
schema | Pointer to the first element of the schema array. The array must be terminated by a sentinel entry (type == EC_CONFIG_TYPE_NONE). |
key | Schema key name. |
- Returns
- The schema entry if it matches a key, or NULL if not found.
◆ ec_config_schema_type()
Get the type of a schema entry.
- Parameters
-
schema_elt | Pointer to an element of the schema array. |
- Returns
- The type of the schema entry.
◆ ec_config_schema_sub()
Get the subschema of a schema entry.
- Parameters
-
schema_elt | Pointer 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
-
name | The 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()
Get the type of the configuration.
- Parameters
-
- Returns
- The configuration type.
◆ ec_config_bool()
struct ec_config * ec_config_bool |
( |
bool | boolean | ) |
|
Create a boolean configuration value.
- Parameters
-
boolean | The 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
-
i64 | The 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
-
u64 | The 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
-
string | The 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()
Create a node configuration value.
- Parameters
-
node | The 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()
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()
Create a list configuration value.
- Returns
- The configuration object containing an empty list, or NULL on error (errno is set).
◆ ec_config_list_add()
Add a config object into a list.
- Parameters
-
list | The list configuration in which the value will be added. |
value | The 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()
Remove an element from a list.
The element is freed and should not be accessed.
- Parameters
-
list | The list configuration. |
config | The 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
-
config | The configuration that must be a list or a dict. |
- Returns
- The number of elements, or -1 on error (errno is set).
◆ ec_config_validate()
Validate a configuration.
- Parameters
-
dict | A hash table configuration to validate. |
schema | Pointer 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
-
dict | A hash table configuration to validate. |
key | The key to update. |
value | The 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
-
dict | A hash table configuration to validate. |
key | The key of the configuration to delete. |
- Returns
- 0 on success, -1 on error (errno is set).
◆ ec_config_cmp()
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 ) |
◆ ec_config_list_first()
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
-
list | The list configuration to iterate. |
- Returns
- The first configuration element, or NULL on error (errno is set).
◆ ec_config_list_next()
Get next element in list.
- Parameters
-
list | The list configuration beeing iterated. |
config | The 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
-
config | The element to free. |
◆ ec_config_dup()
Duplicate a configuration.
- Parameters
-
config | The 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
-
out | Output stream on which the dump will be sent. |
config | The 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
-
config | The configuration (type must be a list of nodes). If it is NULL, an error is returned. |
len | The 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
-
ap | List 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.
◆ ec_config_reserved_keys
const char* ec_config_reserved_keys[] |
|
extern |
Array of reserved key names.