|
hlcc 2.0.0-beta2+pre1
|
#include <config.hpp>
Public Member Functions | |
| Config () | |
| virtual | ~Config () |
| std::string | PrintFormat (const elt::configng::CiiConfigInstanceNamespace &instances, const cfghelpers::SerializationFormat &format=cfghelpers::SerializationFormat::YAML) |
| std::string | PrintKeys (const elt::configng::CiiConfigInstanceNode &node, const std::vector< std::string > &keys, const cfghelpers::SerializationFormat &format=cfghelpers::SerializationFormat::YAML) |
| std::vector< std::string > | UpdateConfigFromKeyval (const std::string &keyval, rad::SMAdapter &sm, bool allow_partial_update) |
| std::vector< std::string > | UpdateConfigFromFile (const std::string &file_name, rad::SMAdapter &sm, bool allow_partial_update) |
| std::vector< std::string > | UpdateConfig (elt::configng::CiiConfigDocument &cfg_doc, rad::SMAdapter &sm, bool allow_partial_update) |
| bool | SplitKeyValue (const std::string &keyval, std::string &key, std::string &value) |
| void | SplitVectorStr (const std::string &vector_str, std::string &vector_name, int &vector_index) const |
| std::string | GetComment (const std::string &key) |
| std::string | GetUnits (const std::string &key) |
| template<typename T > | |
| T | GetDefaultValue (const std::string &key) |
| Config (const Config &)=delete | |
| Config & | operator= (const Config &)=delete |
| Disable copy constructor. | |
This class provide access to the command line options and the configuration parameters stored in the configuration file.
| hlcc::eltpk::Config::Config | ( | ) |
Default constructor.
Initialize application configuration attributes by
The rad-app way of building the configuration is as below using the AddParam<> template. Because in hlcc we are supporting metadata in configuration parameters we cannot build the configuration using AddParam<> because this method doesn't support metadata. Using AddParam would loke like the following example entry: AddParam<std::string>(rad::KEY_CONFIG_VERSION, CONFIG_DEFAULT_VERSION);
Because we now support metadata for configuration parameter we build configuration directly by providing a yaml string containing the complete definition for all parameters types. Because all parameters have the 'default' metadata we take advantage of it and during the configuration instantiation below all parameters will be created with default value from 'default' metadata. Below we are replacing all the default placeholders in the definition with the defaults defined in code. This way we just need to change one place if need to modify the default values avoiding ambiguity.
|
virtual |
Default destructor.
|
delete |
| std::string hlcc::eltpk::Config::GetComment | ( | const std::string & | key | ) |
Return the metadata comment of the referred parameter.
| key | Identifier of the configuration parameter in OLDB format. |
| T hlcc::eltpk::Config::GetDefaultValue | ( | const std::string & | key | ) |
Return the metadata default value of the referred parameter.
| key | Identifier of the configuration parameter in OLDB format. |
| std::string hlcc::eltpk::Config::GetUnits | ( | const std::string & | key | ) |
Return the metadata units of the referred parameter.
| key | Identifier of the configuration parameter in OLDB format. |
| std::string hlcc::eltpk::Config::PrintFormat | ( | const elt::configng::CiiConfigInstanceNamespace & | instances, |
| const cfghelpers::SerializationFormat & | format = cfghelpers::SerializationFormat::YAML |
||
| ) |
Helper method to print the whole CII configuration.
| instances | CiiConfigInstanceNamespace, configuration instance |
| format | SerializationFormat, serialization format for the output string |
| std::string hlcc::eltpk::Config::PrintKeys | ( | const elt::configng::CiiConfigInstanceNode & | node, |
| const std::vector< std::string > & | keys, | ||
| const cfghelpers::SerializationFormat & | format = cfghelpers::SerializationFormat::YAML |
||
| ) |
Helper method to print partially the application configuration.
| instances | CiiConfigInstanceNamespace, configuration instance |
| keys | std::vector<std::string>, containing the configuration keys to print. |
| format | SerializationFormat, serialization format for the output string |
| bool hlcc::eltpk::Config::SplitKeyValue | ( | const std::string & | keyval, |
| std::string & | key, | ||
| std::string & | value | ||
| ) |
Split a given key/value string (e.g. "cfg/version: 'alpha'") into key (e.g. "cfg/version") and value (e.g. "alpha").
| keyval | Input string containing the key-value using fully qualified key. |
| key | Output string representing the key. |
| value | Output string representing the value. |
| void hlcc::eltpk::Config::SplitVectorStr | ( | const std::string & | vector_str, |
| std::string & | vector_name, | ||
| int & | vector_index | ||
| ) | const |
Split a vector identifier in name and index. For example "devices[3]" is split into the string "devices" and the index 3. TODO: lcg: There is an implementation of this method in the parent class but it is private so we added it here also so we can use it for the purpose to demonstrate the metadata usage in top of rad-app implementation of the config class. This should be deleted later and probably make the implementation in the parent class public id really needed in the end.
| vector_str | Input string (e.g. "devices[3]") |
| vector_name | Output name of the vector (e.g. "devices") |
| vector_size | Output index of the vector (e.g. 3) a vector. |
| std::vector< std::string > hlcc::eltpk::Config::UpdateConfig | ( | elt::configng::CiiConfigDocument & | cfg_doc, |
| rad::SMAdapter & | sm, | ||
| bool | allow_partial_update | ||
| ) |
Helper method to update configuration partially from a yaml string at runtime This method will make first an assessment of the parameters, checking if it is possible/safe to update.
| [in] | cfg_doc | CiiConfigDocument, with the configuration to update |
| [in] | sm | Reference to the SM Adapter used to inject internal events. |
| [in] | allow_partial_update,if | true it will update the parameter that are allowed if false it will only update if all are allowed |
| ConfigError,if | not possible to update the configuration. |
| std::vector< std::string > hlcc::eltpk::Config::UpdateConfigFromFile | ( | const std::string & | file_name, |
| rad::SMAdapter & | sm, | ||
| bool | allow_partial_update | ||
| ) |
Helper method to update configuration partially from a yaml config file This method will make first an assessment of the parameters, checking if it is possible/safe to update.
| [in] | file_name | string, containing the config yaml file path |
| [in] | sm | Reference to the SM Adapter used to inject internal events. |
| [in] | allow_partial_update,if | true it will update the parameter that are allowed if false it will only update if all are allowed |
| ConfigError,if | not possible to load the string ans config document |
| std::vector< std::string > hlcc::eltpk::Config::UpdateConfigFromKeyval | ( | const std::string & | keyval, |
| rad::SMAdapter & | sm, | ||
| bool | allow_partial_update | ||
| ) |
Helper method to update configuration partially from a yaml string containing key-value at runtime. This method will make first an assessment of the parameters, one by one, checking if it is possible/safe to update. The string format must be Yaml compliant, check the example: '"cfg.rous.timer_period_s: 123\n cfg.ready_for_handover.estimation_period_ms: 456"' The separation between config parameters must be 'newline' character followed by 2 spaces.
| [in] | keyval | string, containing the yaml with parameters to be updated |
| [in] | sm | Reference to the SM Adapter used to inject internal events. |
| [in] | allow_partial_update,if | true it will update the parameter that are allowed if false it will only update if all are allowed |
| ConfigError,if | not possible to load the string ans config document |