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>
38 elt::configng::CiiConfigInstanceNode&
GetNode(
const std::vector<std::string>& names);
41 elt::configng::CiiConfigInstanceNode&
GetStagingNode(
const std::vector<std::string>& names);
44 elt::configng::CiiConfigInstanceNode&
GetNode(
const elt::configng::CiiConfigDocument* doc,
45 const std::vector<std::string>& names);
53 bool HasPar(
const std::vector<std::string>& names, TYPE& value) {
54 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
60 auto tmp_node =
GetNode(tmp_names);
61 value = tmp_node.As<TYPE>();
76 bool HasStagingPar(
const std::vector<std::string>& names, TYPE& value) {
77 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
82 auto it = s_staging_setup_map.find(tmp_name);
83 if (it != s_staging_setup_map.end()) {
84 core::utils::conversion::Convert(it->second, value);
90 value = tmp_node.As<TYPE>();
102 template <
class TYPE>
104 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
106 auto it = s_staging_setup_map.find(tmp_name);
107 if (it != s_staging_setup_map.end()) {
108 core::utils::conversion::Convert(it->second, value);
113 value = tmp_node.As<TYPE>();
127 template <
class TYPE>
129 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
131 LOG4CPLUS_INFO(
Logger(), fmt::format(
"{}: Handling Staging Setup Parameter: |{}|=|{}|...",
132 CCFLOC, tmp_name, value));
134 if (m_ref_setup_doc.get() ==
nullptr) {
135 CCFTHROW(
"Must load an Init Setup as reference before submitting setup parameters");
141 auto err = boost::current_exception_diagnostic_information();
142 CCFTHROW(fmt::format(
"{}: Issue handling parameter: |{}|: {}",
CCFLOC, name, err));
147 std::stringstream tmp_val;
150 node = tmp_val.str();
151 m_ref_setup_doc.get()->Check();
152 auto issues = m_ref_setup_doc.get()->Check();
155 m_ref_setup_doc = std::make_unique<elt::configng::CiiConfigDocument>
156 (elt::configng::CiiConfigClient::Load(m_staging_setup_file));
157 for (
auto issue : issues) {
158 auto err = fmt::format(
"Value: {} provided with parameter: {} not valid",
159 tmp_val.str(), name);
161 LOG4CPLUS_WARN(
Logger(), err);
166 s_staging_setup_map[tmp_name] = tmp_val.str();
167 LOG4CPLUS_INFO(
Logger(), fmt::format(
"Added Staging Setup Parameter: |{}|=|{}|", tmp_name,
175 void GetPars(std::map<std::string, std::string>& pars,
176 const std::string& pattern =
"*");
179 template <
class TYPE>
180 TYPE
GetValue(
const std::vector<std::string>& names) {
181 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
184 if (
HasPar(tmp_names, tmp_value)) {
192 template <
class TYPE>
194 LOG4CPLUS_TRACE_METHOD(
Logger(), __PRETTY_FUNCTION__);
200 CCFTHROW(
"Setup parameter requested not defined: " + tmp_name);
213 std::vector<std::string>
CheckNodeNames(
const std::vector<std::string>& names)
const;
216 const elt::configng::CiiConfigDocument&
GetRefSetup()
const;
221 std::string m_root_node_name;
222 std::string m_staging_setup_file;
226 std::unique_ptr<elt::configng::CiiConfigDocument> m_ref_setup_doc;
233 std::unique_ptr<elt::configng::CiiConfigDocument> m_staging_setup_doc;
239 static std::map<std::string, std::string> s_staging_setup_map;
242 std::unique_ptr<elt::configng::CiiConfigDocument> m_setup_doc;
#define CCFLOC
Macro generating a location identifier: "<file>:<line>:<function>:<thread>".
Definition: base.hpp:387
#define CCFTHROW(msg)
Definition: base.hpp:416
Class to be used as parent all CCF classes.
Definition: base.hpp:107
Global setup class for CCF applications. An Initialisation Setup, containing all the parameters shall...
Definition: setup.hpp:23
bool ParDefined(const std::string &name)
Check if the given parameter is defined in the Reference Setup.
Definition: setup.cpp:200
std::vector< std::string > CheckNodeNames(const std::vector< std::string > &names) const
Definition: setup.cpp:177
const std::map< std::string, std::string > & GetSetupCmdStagingPars()
Return list of staging pars, provided via the Setup command.
Definition: setup.cpp:152
bool HasStagingParKey(const std::string &name, TYPE &value)
Definition: setup.hpp:103
bool HasStagingNodeKey(const std::string &name)
Probe if a given parameter is defined among the Setup Staging Parameters.
Definition: setup.cpp:212
std::string CheckNodeName(const std::string &name) const
Definition: setup.cpp:191
bool HasPar(const std::vector< std::string > &names, TYPE &value)
Definition: setup.hpp:53
static Setup * s_instance
Singleton instance.
Definition: setup.hpp:27
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:193
void AcceptStagingSetup()
Merge the parameters in the Staging Setup into the Installed Setup set of parameters.
Definition: setup.cpp:157
void AddStagingPar(const std::string &name, const TYPE value)
Definition: setup.hpp:128
const elt::configng::CiiConfigDocument & GetRefSetup() const
Definition: setup.cpp:236
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:180
std::string SetupFileToString() const
Return string representation of the setup file loaded.
Definition: setup.cpp:222
Setup()
Definition: setup.cpp:22
bool HasStagingPar(const std::vector< std::string > &names, TYPE &value)
Definition: setup.hpp:76
elt::configng::CiiConfigInstanceNode & GetStagingNode(const std::vector< std::string > &names)
Get the reference to a specific node in the Staging Setup.
Definition: setup.cpp:37
const std::string & GetRootNodeName() const
Return the name of the setup document root node name.
Definition: setup.cpp:231
elt::configng::CiiConfigInstanceNode & GetNode(const std::vector< std::string > &names)
Get the reference to a specific node in the Installed Setup.
Definition: setup.cpp:32
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:128
~Setup()
Definition: setup.cpp:28
void LoadStagingSetup(const std::string &filename)
Load a Setup File into the Staging Setup object.
Definition: setup.cpp:68
Definition: appBase.cpp:8
Definition: appBase.cpp:8
std::string BuildKey(const std::vector< std::string > &elements)
Build a concatenated key from a number of elements (<el1>.<el2.>...).
Definition: base.cpp:238
log4cplus::Logger & Logger()
Definition: base.cpp:11
std::vector< std::string > SplitKey(const std::string &key)
Split up a concatenated key.
Definition: base.cpp:242
ccf::common::Setup & GetSetup()
Return the reference to the CCF DB Singleton instance.
Definition: setup.hpp:249