Unify Configuration System.
More...
|
config_status_t | config_add_string (const char *name, const char *help, const char *default_value) |
| Add string configuration. More...
|
|
config_status_t | config_add_int (const char *name, const char *help, int default_value) |
| Add an integer configuration. More...
|
|
config_status_t | config_add_double (const char *name, const char *help, double default_value) |
| Add a double configuration. More...
|
|
config_status_t | config_add_bool (const char *name, const char *help, bool default_value) |
| Add a bool configuration. More...
|
|
config_status_t | config_add_flag (const char *name, const char *help) |
| Add a flag configuration. More...
|
|
config_status_t | config_parse (int argc, char **argv, const char *version) |
| Parse command line arguments to the config system. More...
|
|
config_status_t | config_get_as_string (const char *name, const char **result) |
| Get the config as a C-string. More...
|
|
config_status_t | config_get_as_int (const char *name, int *result) |
| Get the config as an integer. More...
|
|
config_status_t | config_get_as_double (const char *name, double *result) |
| Get the config as a double. More...
|
|
config_status_t | config_get_as_bool (const char *name, bool *result) |
| Get the config as bool. More...
|
|
config_status_t | config_has_flag (const char *name) |
| Check is a config paramter exists. More...
|
|
void | config_reset () |
| Reset the config. More...
|
|
Unify Configuration System.
Configuration system for Unify Components/Applications. It supports reading configuration from a YAML config file, as well as from command line (arguments). Command line arguments overrides the configurations from the config file.
Config variables are registered to the config system though the config_add_xxx functions. When all variables have been registed the parsing of command line arguments and the configuration file is done using the function config_parse. After this the value of each configuration variable may be retrived using the config_get_as_xxxx functions.
◆ CONFIG_KEY_LOG_LEVEL
#define CONFIG_KEY_LOG_LEVEL "log.level" |
◆ CONFIG_KEY_LOG_TAG_LEVEL
#define CONFIG_KEY_LOG_TAG_LEVEL "log.tag_level" |
◆ CONFIG_KEY_MQTT_CAFILE
#define CONFIG_KEY_MQTT_CAFILE "mqtt.cafile" |
◆ CONFIG_KEY_MQTT_CERTFILE
#define CONFIG_KEY_MQTT_CERTFILE "mqtt.certfile" |
◆ CONFIG_KEY_MQTT_CLIENT_ID
#define CONFIG_KEY_MQTT_CLIENT_ID "mqtt.client_id" |
◆ CONFIG_KEY_MQTT_HOST
#define CONFIG_KEY_MQTT_HOST "mqtt.host" |
◆ CONFIG_KEY_MQTT_KEYFILE
#define CONFIG_KEY_MQTT_KEYFILE "mqtt.keyfile" |
◆ CONFIG_KEY_MQTT_PORT
#define CONFIG_KEY_MQTT_PORT "mqtt.port" |
◆ DEFAULT_CONFIG_PATH
#define DEFAULT_CONFIG_PATH "/etc/uic/uic.cfg" |
◆ config_status_t
Enumerator |
---|
CONFIG_STATUS_OK | |
CONFIG_STATUS_NOK | |
CONFIG_STATUS_ERROR | |
CONFIG_STATUS_INVALID_TYPE | |
CONFIG_STATUS_DOES_NOT_EXIST | |
CONFIG_STATUS_INFO_MESSAGE | |
◆ config_add_bool()
config_status_t config_add_bool |
( |
const char * |
name, |
|
|
const char * |
help, |
|
|
bool |
default_value |
|
) |
| |
Add a bool configuration.
- Parameters
-
name | Name of the config |
help | Help message (to print to command line) |
default_value | Default value for the configuration |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_add_double()
config_status_t config_add_double |
( |
const char * |
name, |
|
|
const char * |
help, |
|
|
double |
default_value |
|
) |
| |
Add a double configuration.
- Parameters
-
name | Name of the config |
help | Help message (to print to command line) |
default_value | Default value for the configuration |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_add_flag()
Add a flag configuration.
- Parameters
-
name | Name of the config |
help | Help message (to print to command line) |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_add_int()
config_status_t config_add_int |
( |
const char * |
name, |
|
|
const char * |
help, |
|
|
int |
default_value |
|
) |
| |
Add an integer configuration.
- Parameters
-
name | Name of the config |
help | Help message (to print to command line) |
default_value | Default value for the configuration |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_add_string()
config_status_t config_add_string |
( |
const char * |
name, |
|
|
const char * |
help, |
|
|
const char * |
default_value |
|
) |
| |
Add string configuration.
- Parameters
-
name | Name of the config |
help | Help message (to print to command line) |
default_value | Default value for the configuration |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_get_as_bool()
Get the config as bool.
- Parameters
-
name | Name of configuration |
result | [out] value read from configuration. |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_get_as_double()
config_status_t config_get_as_double |
( |
const char * |
name, |
|
|
double * |
result |
|
) |
| |
Get the config as a double.
- Parameters
-
name | Name of configuration |
result | [out] value read from configuration. |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_get_as_int()
Get the config as an integer.
- Parameters
-
name | Name of configuration |
result | [out] value read from configuration. |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_get_as_string()
config_status_t config_get_as_string |
( |
const char * |
name, |
|
|
const char ** |
result |
|
) |
| |
Get the config as a C-string.
- Parameters
-
name | Name of configuration |
result | [out] value read from configuration. The string is allocated in the config internal data structure, that's the reason for it is a const **, in addition after calling config_parse (again), the string is invalid. |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_has_flag()
Check is a config paramter exists.
This is usefull for options which has not arguments, ie flags.
- Parameters
-
- Returns
- config_status_t CONFIG_STATUS_OK if paramter is found
◆ config_parse()
config_status_t config_parse |
( |
int |
argc, |
|
|
char ** |
argv, |
|
|
const char * |
version |
|
) |
| |
Parse command line arguments to the config system.
This must be done before calling any of the config_get functions. In addition all config_add calls shall be done before calling this function.
- Parameters
-
argc | Argument count |
argv | Arguments as array of (c) strings |
version | Version string to print if "version" argument is given |
- Returns
- config_status_t CONFIG_STATUS_OK if success
◆ config_reset()
Reset the config.
This will reset the config, so all added configurations are removed, as well as all parsed configuration variables. This is used in unit-tests, and there shouldn't be a reason to use it elsewhere