5 #ifndef CCF_COMMON_SETUP_HPP_H_
6 #define CCF_COMMON_SETUP_HPP_H_
8 #include <yaml-cpp/yaml.h>
10 #include <config-ng/ciiConfigApi.hpp>
36 elt::configng::CiiConfigInstanceNode&
GetNode(
const std::vector<std::string>& names);
39 elt::configng::CiiConfigInstanceNode&
GetStagingNode(
const std::vector<std::string>& names);
42 elt::configng::CiiConfigInstanceNode&
GetNode(
const elt::configng::CiiConfigDocument* doc,
43 const std::vector<std::string>& names);
51 bool HasPar(
const std::vector<std::string>& names, TYPE& value) {
52 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
53 auto tmp_names = _CheckNodeNames(names);
58 auto tmp_node =
GetNode(tmp_names);
59 value = tmp_node.As<TYPE>();
70 bool HasStagingPar(
const std::vector<std::string>& names, TYPE& value) {
71 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
72 auto tmp_names = _CheckNodeNames(names);
76 auto it = s_staging_setup_map.find(tmp_name);
77 if (it != s_staging_setup_map.end()) {
78 core::utils::conversion::Convert(it->second, value);
84 value = tmp_node.As<TYPE>();
98 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
99 auto tmp_name = _CheckNodeName(name);
100 auto it = s_staging_setup_map.find(tmp_name);
101 if (it != s_staging_setup_map.end()) {
102 core::utils::conversion::Convert(it->second, value);
107 value = tmp_node.As<TYPE>();
121 template <
class TYPE>
123 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
124 std::string tmp_name = _CheckNodeName(name);
125 LOG4CPLUS_INFO(
Logger(), fmt::format(
"Handling Staging Setup Parameter: |{}|=|{}|...",
128 if (m_ref_setup_doc.get() ==
nullptr) {
129 CCFTHROW(
"Must load an Init Setup as reference before submitting setup parameters");
135 CCFTHROW(fmt::format(
"Parameter: |{}| not defined for this instance", name));
140 std::stringstream tmp_val;
143 node = tmp_val.str();
144 m_ref_setup_doc.get()->Check();
145 auto issues = m_ref_setup_doc.get()->Check();
148 m_ref_setup_doc = std::make_unique<elt::configng::CiiConfigDocument>
149 (elt::configng::CiiConfigClient::Load(m_staging_setup_file));
150 for (
auto issue : issues) {
151 auto err = fmt::format(
"Value: {} provided with parameter: {} not valid: {}", name,
152 tmp_val.str(), issue.GetMessageWithOrigin());
153 LOG4CPLUS_WARN(
Logger(), err);
158 s_staging_setup_map[tmp_name] = tmp_val.str();
159 LOG4CPLUS_INFO(
Logger(), fmt::format(
"Added Staging Setup Parameter: |{}|=|{}|", tmp_name,
167 void GetPars(std::map<std::string, std::string>& pars,
168 const std::string& pattern =
"*");
171 template <
class TYPE>
172 TYPE
GetValue(
const std::vector<std::string>& names) {
173 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
174 auto tmp_names = _CheckNodeNames(names);
176 if (
HasPar(tmp_names, tmp_value)) {
184 template <
class TYPE>
186 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
187 auto tmp_name = _CheckNodeName(name);
192 CCFTHROW(
"Setup parameter requested not defined: " + tmp_name);
208 std::string m_root_node_name;
209 std::string m_staging_setup_file;
211 std::vector<std::string> _CheckNodeNames(
const std::vector<std::string>& names)
const;
212 std::string _CheckNodeName(
const std::string& name)
const;
217 std::unique_ptr<elt::configng::CiiConfigDocument> m_staging_setup_doc;
221 std::unique_ptr<elt::configng::CiiConfigDocument> m_ref_setup_doc;
227 static std::map<std::string, std::string> s_staging_setup_map;
230 std::unique_ptr<elt::configng::CiiConfigDocument> m_setup_doc;
#define CCFTHROW(msg)
Guard for TRACE logs. Ensures log text is only generated when the given log level is enabled.
Definition: base.hpp:489
Class to be used as parent all CCF classes.
Definition: base.hpp:151
Global setup class for CCF applications. An Initialisation Setup, containing all the parameters shall...
Definition: setup.hpp:21
bool HasStagingParKey(const std::string &name, TYPE &value)
Definition: setup.hpp:97
bool HasStagingNodeKey(const std::string &name)
Probe if a given parameter is defined among the Setup Staging Parameters.
Definition: setup.cpp:180
bool HasPar(const std::vector< std::string > &names, TYPE &value)
Definition: setup.hpp:51
static Setup * s_instance
Singleton instance.
Definition: setup.hpp:25
static Setup & Instance()
Return reference to unique instance of the application class.
Definition: setup.cpp:13
TYPE GetValueKey(const std::string &name)
Get value from either the 1) Staging Setup, or 2) Installed Setup from the SPF key.
Definition: setup.hpp:185
void AcceptStagingSetup()
Merge the parameters in the Staging Setup into the Installed Setup set of parameters.
Definition: setup.cpp:137
void AddStagingPar(const std::string &name, const TYPE value)
Definition: setup.hpp:122
const std::map< std::string, std::string > & GetCmdStagingPars()
Return list of staging pars, provided via the Setup command.
Definition: setup.cpp:132
void ResetStagingSetup()
Reset the internal Staging Setup.
Definition: setup.cpp:62
TYPE GetValue(const std::vector< std::string > &names)
Get value from either the 1) Staging Setup, or 2) Installed Setup.
Definition: setup.hpp:172
std::string SetupFileToString() const
Return string representation of the setup file loaded.
Definition: setup.cpp:190
Setup()
Definition: setup.cpp:22
bool HasStagingPar(const std::vector< std::string > &names, TYPE &value)
Definition: setup.hpp:70
elt::configng::CiiConfigInstanceNode & GetStagingNode(const std::vector< std::string > &names)
Get the reference to a specific node in the Staging Setup.
Definition: setup.cpp:38
const std::string & GetRootNodeName() const
Return the name of the setup document root node name.
Definition: setup.cpp:199
elt::configng::CiiConfigInstanceNode & GetNode(const std::vector< std::string > &names)
Get the reference to a specific node in the Installed Setup.
Definition: setup.cpp:33
void GetPars(std::map< std::string, std::string > &pars, const std::string &pattern="*")
Return map with all parameters in the object. Staging pars take precedence.
Definition: setup.cpp:106
~Setup()
Definition: setup.cpp:29
void LoadStagingSetup(const std::string &filename)
Load a Setup File into the Staging Setup object.
Definition: setup.cpp:68
Definition: appBase.cpp:8
Setup & GetSetup()
Definition: setup.hpp:233
std::string BuildKey(const std::vector< std::string > &elements)
Build a concatenated key from a number of elements (<el1>.<el2.>...).
Definition: base.cpp:218
log4cplus::Logger & Logger()
Definition: base.cpp:9
std::vector< std::string > SplitKey(const std::string &key)
Split up a concatenated key.
Definition: base.cpp:222