Zigbee Protocol Controller 1.6.0
Unify Configuration System

Unify Configuration System. More...

Macros

#define CONFIG_KEY_MQTT_HOST   "mqtt.host"
 
#define CONFIG_KEY_MQTT_PORT   "mqtt.port"
 
#define CONFIG_KEY_MQTT_CLIENT_ID   "mqtt.client_id"
 
#define CONFIG_KEY_MQTT_CAFILE   "mqtt.cafile"
 
#define CONFIG_KEY_MQTT_CERTFILE   "mqtt.certfile"
 
#define CONFIG_KEY_MQTT_KEYFILE   "mqtt.keyfile"
 
#define CONFIG_KEY_LOG_LEVEL   "log.level"
 
#define CONFIG_KEY_LOG_TAG_LEVEL   "log.tag_level"
 
#define DEFAULT_CONFIG_PATH   "/etc/uic/uic.cfg"
 

Enumerations

enum  config_status_t {
  CONFIG_STATUS_OK = 0x0 , CONFIG_STATUS_NOK = 0x1 , CONFIG_STATUS_ERROR = 0x2 , CONFIG_STATUS_INVALID_TYPE = 0x4 ,
  CONFIG_STATUS_DOES_NOT_EXIST = 0x8 , CONFIG_STATUS_INFO_MESSAGE = 0x10
}
 

Functions

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...
 

Detailed Description

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.

Macro Definition Documentation

◆ 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"

Enumeration Type Documentation

◆ 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 

Function Documentation

◆ config_add_bool()

config_status_t config_add_bool ( const char *  name,
const char *  help,
bool  default_value 
)

Add a bool configuration.

Parameters
nameName of the config
helpHelp message (to print to command line)
default_valueDefault 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
nameName of the config
helpHelp message (to print to command line)
default_valueDefault value for the configuration
Returns
config_status_t CONFIG_STATUS_OK if success

◆ config_add_flag()

config_status_t config_add_flag ( const char *  name,
const char *  help 
)

Add a flag configuration.

Parameters
nameName of the config
helpHelp 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
nameName of the config
helpHelp message (to print to command line)
default_valueDefault 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
nameName of the config
helpHelp message (to print to command line)
default_valueDefault value for the configuration
Returns
config_status_t CONFIG_STATUS_OK if success

◆ config_get_as_bool()

config_status_t config_get_as_bool ( const char *  name,
bool *  result 
)

Get the config as bool.

Parameters
nameName 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
nameName of configuration
result[out] value read from configuration.
Returns
config_status_t CONFIG_STATUS_OK if success

◆ config_get_as_int()

config_status_t config_get_as_int ( const char *  name,
int *  result 
)

Get the config as an integer.

Parameters
nameName 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
nameName 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()

config_status_t config_has_flag ( const char *  name)

Check is a config paramter exists.

This is usefull for options which has not arguments, ie flags.

Parameters
nameParamter to find
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
argcArgument count
argvArguments as array of (c) strings
versionVersion string to print if "version" argument is given
Returns
config_status_t CONFIG_STATUS_OK if success

◆ config_reset()

void 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