5#ifndef CCF_COMMON_SETUP_HPP_H_
6#define CCF_COMMON_SETUP_HPP_H_
8#include <boost/exception/diagnostic_information.hpp>
10#include <yaml-cpp/yaml.h>
12#include <config-ng/ciiConfigApi.hpp>
40 elt::configng::CiiConfigInstanceNode&
GetStagingNode(
const std::vector<std::string>& names);
43 elt::configng::CiiConfigInstanceNode&
GetNode(
const elt::configng::CiiConfigDocument* doc,
44 const std::vector<std::string>& names);
51 bool HasCurrentPar(
const std::vector<std::string>& names, TYPE& value) {
52 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
57 value = GetCurrentValue<TYPE>(names);
67 bool HasPar(
const std::vector<std::string>& names, TYPE& value) {
68 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
76 value = GetCurrentValue<TYPE>(tmp_names);
91 bool HasStagingPar(
const std::vector<std::string>& names, TYPE& value) {
92 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
96 std::lock_guard<std::recursive_mutex> lock(m_staging_setup_mtx);
98 auto it = s_staging_setup_map.find(tmp_name);
99 if (it != s_staging_setup_map.end()) {
100 ifw::core::utils::conversion::Convert(it->second, value);
104 if (m_staging_setup_doc.get() ==
nullptr) {
108 if (m_staging_setup_doc.get() ==
nullptr) {
112 value = tmp_node.As<TYPE>();
121 template <
class TYPE>
123 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
125 std::lock_guard<std::recursive_mutex> lock(m_staging_setup_mtx);
126 auto it = s_staging_setup_map.find(tmp_name);
127 if (it != s_staging_setup_map.end()) {
128 ifw::core::utils::conversion::Convert(it->second, value);
132 if (m_staging_setup_doc.get() ==
nullptr) {
136 value = tmp_node.As<TYPE>();
150 template <
class TYPE>
152 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
154 LOG4CPLUS_INFO(
Logger(), fmt::format(
"{}: Handling Staging Setup Parameter: |{}|=|{}|...",
155 IFWLOC, tmp_name, value));
157 if (m_ref_setup_doc.get() ==
nullptr) {
158 CCFTHROW(
"Must load an Init Setup as reference before submitting setup parameters");
164 auto err = boost::current_exception_diagnostic_information();
165 CCFTHROW(fmt::format(
"{}: Issue handling parameter: |{}|: {}", IFWLOC, name, err));
170 std::stringstream tmp_val;
173 node = tmp_val.str();
174 m_ref_setup_doc.get()->Check();
175 auto issues = m_ref_setup_doc.get()->Check();
178 m_ref_setup_doc = std::make_unique<elt::configng::CiiConfigDocument>
179 (elt::configng::CiiConfigClient::Load(m_staging_setup_file));
180 for (
auto issue : issues) {
181 auto err = fmt::format(
"Value: {} provided with parameter: {} not valid",
182 tmp_val.str(), name);
184 LOG4CPLUS_WARN(
Logger(), err);
190 std::lock_guard<std::recursive_mutex> lock(m_staging_setup_mtx);
193 LOG4CPLUS_INFO(
Logger(), fmt::format(
"Added Staging Setup Parameter: |{}|=|{}|", tmp_name,
201 void GetPars(std::map<std::string, std::string>& pars,
202 const std::string& pattern =
"*");
204 template <
class TYPE>
206 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
207 std::lock_guard<std::recursive_mutex> lock(m_current_setup_mtx);
208 auto it = m_current_setup_map.find(name);
209 if (it != m_current_setup_map.end()) {
211 ifw::core::utils::conversion::Convert(it->second, tmp_value);
214 CCFTHROW(fmt::format(
"{}: Parameter: |{}| not defined among Current Setup Parameters",
220 template <
class TYPE>
222 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
227 template <
class TYPE>
228 TYPE
GetValue(
const std::vector<std::string>& names) {
229 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
232 if (
HasPar(tmp_names, tmp_value)) {
240 template <
class TYPE>
242 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
248 CCFTHROW(
"Setup parameter requested not defined: " + tmp_name);
264 std::vector<std::string>
CheckNodeNames(
const std::vector<std::string>& names)
const;
267 const elt::configng::CiiConfigDocument&
GetRefSetup()
const;
270 void StoreStagingPar(
const std::string& name,
const std::string& value);
273 std::string m_root_node_name;
274 std::string m_staging_setup_file;
278 std::unique_ptr<elt::configng::CiiConfigDocument> m_ref_setup_doc;
285 std::unique_ptr<elt::configng::CiiConfigDocument> m_staging_setup_doc;
291 std::recursive_mutex m_staging_setup_mtx;
292 static std::map<std::string, std::string> s_staging_setup_map;
294 std::vector<std::string> m_staging_setup_sequence;
298 std::recursive_mutex m_current_setup_mtx;
299 std::map<std::string, std::string> m_current_setup_map;
#define CCFTHROW(msg)
Definition base.hpp:366
Class to be used as parent all CCF classes.
Definition base.hpp:120
Global setup class for CCF applications. An Initialisation Setup, containing all the parameters shall...
Definition setup.hpp:22
TYPE GetValue(const std::vector< std::string > &names)
Get value from either the 1) Staging Setup, or 2) Installed Setup.
Definition setup.hpp:228
static Setup & Instance()
Return reference to unique instance of the application class.
Definition setup.cpp:13
bool HasCurrentPar(const std::vector< std::string > &names, TYPE &value)
Probe if a given parameter has been processed and accepted already.
Definition setup.hpp:51
elt::configng::CiiConfigInstanceNode & GetNode(const elt::configng::CiiConfigDocument *doc, const std::vector< std::string > &names)
Get the reference to a specific node in the referenced CII Cfg Service doc object.
Definition setup.cpp:60
std::string CheckNodeName(const std::string &name) const
Definition setup.cpp:268
void StoreStagingPar(const std::string &name, const std::string &value)
Definition setup.cpp:158
elt::configng::CiiConfigInstanceNode & GetStagingNode(const std::vector< std::string > &names)
Get the reference to a specific node in the Installed Setup.
Definition setup.cpp:55
bool ParDefined(const std::string &name)
Check if the given parameter is defined in the Reference Setup.
Definition setup.cpp:277
Setup()
Definition setup.cpp:22
bool HasStagingPar(const std::vector< std::string > &names, TYPE &value)
Definition setup.hpp:91
void AddStagingPar(const std::string &name, const TYPE value)
Definition setup.hpp:151
void LoadStagingSetup(const std::string &filename)
Load a Setup File into the Staging Setup object.
Definition setup.cpp:89
std::vector< std::string > GetSetupCmdStagingPars()
Return list of Staging Setup Pars, normally provided via a Setup Command.
Definition setup.cpp:220
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:241
TYPE GetCurrentValue(const std::string &name)
Definition setup.hpp:205
TYPE GetCurrentValue(const std::vector< std::string > &names)
Get value from the Installed Setup.
Definition setup.hpp:221
const elt::configng::CiiConfigDocument & GetRefSetup() const
Definition setup.cpp:317
void ResetStagingSetup()
Reset the internal Staging Setup.
Definition setup.cpp:81
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:190
bool HasStagingParKey(const std::string &name, TYPE &value)
Definition setup.hpp:122
bool HasPar(const std::vector< std::string > &names, TYPE &value)
Definition setup.hpp:67
std::string SetupToString() const
Return string representation of the Setup loaded.
Definition setup.cpp:298
void AcceptStagingSetup()
Merge the parameters in the Staging Setup into the Installed Setup set of parameters.
Definition setup.cpp:227
const std::string & GetRootNodeName() const
Return the name of the setup document root node name.
Definition setup.cpp:312
std::vector< std::string > CheckNodeNames(const std::vector< std::string > &names) const
Definition setup.cpp:254
std::string StagingSetupToString() const
Return string representation of the Staging Setup loaded.
Definition setup.cpp:289
~Setup()
Definition setup.cpp:28
static Setup * s_instance
Singleton instance.
Definition setup.hpp:26
log4cplus::Logger & Logger()
Definition base.cpp:23
ifw::ccf::common::Setup & GetSetup()
Return the reference to the CCF DB Singleton instance.
Definition setup.hpp:306
std::vector< std::string > SplitKey(const std::string &key)
Split up a concatenated key.
Definition base.cpp:244
std::string BuildKey(const std::vector< std::string > &elements)
Build a concatenated key from a number of elements (<el1>.<el2.>...).
Definition base.cpp:240