|
rad 6.2.0
|
#include <config.hpp>
Public Member Functions | |
| Config (const std::string &name=LOGGER_NAME, const std::string &log_level="ERROR") | |
| Config (const Config &cfg) | |
| virtual | ~Config () |
| Config & | operator= (const Config &cfg) |
| const elt::configng::CiiConfigDocument & | GetConfigDoc () const |
| bpo::options_description & | GetOptionsDesc () |
| bpo::variables_map & | GetOptionsMap () |
| const std::string & | GetOldbPrefixAppenderKey () |
| void | SetOldbPrefixAppenderKey (const std::string &key) |
| std::string | BuildOldbPrefix () |
| virtual bool | ParseOptions (int argc, char *argv[]) |
| virtual void | LoadConfig (const std::string &filename="") |
| virtual void | ConfigureLogging (const std::string &filename="") |
| virtual void | ApplyCmdLineOptions () |
| void | CheckConfig () const |
| virtual void | ValidateConfig (const std::vector< std::string > &keys, const Config &cfg) const |
| void | MergeConfig (const elt::configng::CiiConfigDocument &cfg_doc) |
| void | CreateDefaultConfig (const std::string &default_cfg) |
| template<typename T > | |
| void | AddParam (const std::string &key, const T &value) |
| bool | HasParam (const std::string &key) const |
| template<typename T > | |
| T | GetParam (const std::string &key) const |
| template<typename T > | |
| void | SetParam (const std::string &key, const T &value) |
| const std::string | GetConfigAsString () const |
| std::vector< std::string > | SetConfigAsString (const std::string &config) |
| std::string | PrintNode (const elt::configng::CiiConfigInstanceNode &node, const std::string &indentation) const |
| std::string | Print (const elt::configng::CiiConfigInstanceNamespace &instances) const |
| std::string | Print () const |
This class provide access to the command line options and the configuration parameters stored in the configuration file.
|
explicit |
Default constructor.
Initialize application configuration attributes by
| name | Module name used for the default log filename and default logger name. |
| log_level | startup log level for the root logger. |
| rad::Config::Config | ( | const Config & | cfg | ) |
Copy constructor.
Makes a deep copy of the configuration including command line options from a source configuration.
| cfg | Source configuration. |
|
virtual |
Default destructor.
Reimplemented in exciiserver::Config, and rad::utest::Config.
| void rad::Config::AddParam | ( | const std::string & | key, |
| const T & | value ) |
Add a configuration parameter to the stream which will be used to create the initial CiiConfigDocument.
| key | Fully qualified key (e.g. 'cfg.version'). |
| value | Value associated to the key. |
|
virtual |
This method override the configuration loaded from file by re-applying the command line options.
| std::string rad::Config::BuildOldbPrefix | ( | ) |
| void rad::Config::CheckConfig | ( | ) | const |
This method uses CII config-ng to check whether the CII configuration document complies with the schema/specification. In case of error(s) an exception is thrown and the error(s) logged. In case of warnings they are all logged.
In case of invalid parameter, an exception is/should be thrown to stop applying the configuration.
|
virtual |
This method load from a log.properties file the logging configuration and it applies it.
If no filename is passed, it uses the one defined in the application configuration file.
| [in] | filename | Log properties filename. |
| void rad::Config::CreateDefaultConfig | ( | const std::string & | default_cfg | ) |
Create the initial applications configuration (CiiConfigDocument) from a given string.
| default_cfg | Configuration following YAML syntax. |
| const std::string rad::Config::GetConfigAsString | ( | ) | const |
This method returns the current configuration in a string.
|
inline |
|
inline |
|
inline |
|
inline |
| T rad::Config::GetParam | ( | const std::string & | key | ) | const |
Return the value associated to a configuration parameter.
| key | Identifier of the configuration parameter in OLDB format. |
| bool rad::Config::HasParam | ( | const std::string & | key | ) | const |
Check whether a given parameter is part of the configuration.
| key | Key to convert using a src separator. |
|
virtual |
This method load from a configuration file the application configuration overriding the initialization done in the constructor and the command line options.
| [in] | filename | Application configuration filename. If empty, it reloads the last or default one. |
| void rad::Config::MergeConfig | ( | const elt::configng::CiiConfigDocument & | cfg_doc | ) |
This method merges the given configuration (loaded from file or string) with the main one stored in this class. TODO: This method could/should be provided by CII.
| [in] | config_node | Configuration to merge into the current one. |
Assignment operator.
Makes a deep copy of the configuration including command line options (with the exception of BOOST options_description which cannot be assigned) from the given source document.
| cfg | Source configuration. |
|
virtual |
This method parses the command line parameters overriding the initialization done in the constructor.
| [in] | argc | Number of command line options. |
| [in] | argv | Pointer to the array of command line options. |
| std::string rad::Config::Print | ( | ) | const |
Helper method to print the current application configuration.
| std::string rad::Config::Print | ( | const elt::configng::CiiConfigInstanceNamespace & | instances | ) | const |
| std::string rad::Config::PrintNode | ( | const elt::configng::CiiConfigInstanceNode & | node, |
| const std::string & | indentation ) const |
Helper method to print a CII configuration node. TODO this should be provided by CII via << operator.
| std::vector< std::string > rad::Config::SetConfigAsString | ( | const std::string & | config | ) |
This method merges the given configuration with the one currently stored in the Config object. If the configuration is given as a 'key: value'
Note that for the merging to succeed the given configuration must be conistent in terms of data types with one stored.
| config | Configuration to be applied in textual YAML format. |
|
inline |
Sets the key identifier to be used to retrieve from the configuration part of the OLDB prefix.
| key | Configuration key (e.g. KEY_CONFIG_MODNAME or KEY_CONFIG_PROCNAME) to be used when building the OLDB prefix path. |
| void rad::Config::SetParam | ( | const std::string & | key, |
| const T & | value ) |
Set the value of a configuration parameter.
| key | Identifier of the configuration parameter in OLDB format. |
| value | The value of a configuration parameter. |
|
virtual |
This method allows an application to verify the given configuration before it is merged with the actual/main configuration. In case of invalid parameter, an exception is/should be thrown to stop applying the configuration.
The method can be specialized to verify application specific parameters.
| keys | Parameters to be validated. |
| cfg | Configuration values to be validated. |
Reimplemented in MyConfig.