ifw-daq  3.0.0-pre2
IFW Data Acquisition modules
configManager.hpp
Go to the documentation of this file.
1 /**
2  * @file
3  * @ingroup daq_dpm_server
4  * @copyright (c) Copyright ESO 2022
5  * All Rights Reserved
6  * ESO (eso.org) is an Intergovernmental Organisation, and therefore special legal conditions apply.
7  *
8  * @brief DPM server config
9  */
10 #ifndef DAQ_DPM_SERVER_CONFIGMANAGER_HPP
11 #define DAQ_DPM_SERVER_CONFIGMANAGER_HPP
12 
13 #include <daq/config/manager.hpp>
14 
15 #include <boost/numeric/conversion/cast.hpp>
16 
17 #include <daq/dpm/config.hpp>
18 
19 namespace daq::dpm {
20 
21 /**
22  * DPM Server specific configuration manager.
23  *
24  * Main responsibilities:
25  * - Update configuration from various sources.
26  * - Publish updates to OLDB.
27  */
29 public:
30  ConfigManager(log4cplus::Logger logger);
31 
32  Configuration const& GetConfig() const {
33  return m_config;
34  }
35  /**
36  * Parse configuration from command line arguments.
37  *
38  * @param[in] argc Number of command line options.
39  * @param[in] argv Pointer to the array of command line options.
40  * @return false if the help option has been invoked, true otherwise.
41  */
42  bool ParseArguments(int argc, char* argv[]);
43 
44  /**
45  * Load configuration file and update configuration.
46  */
47  void LoadConfig();
48  /**
49  * Visit all configuration parameters.
50  */
51  template <class Func>
52  void Visit(Func&& func) {
53  m_mgr.Visit(std::forward<Func>(func));
54  }
55 
56 private:
57  /**
58  * Helper that use canonical name to look up config.
59  */
60  template <class AttrType, class T>
61  void UpdateFromConfig(T* ptr,
62  elt::configng::CiiConfigInstanceNode const& node,
63  config::OriginInfo const& origin) {
64  auto info = m_mgr.Get(ptr);
66  if (auto value = GetParamAs<AttrType>(info.metadata.canonical_name, node); value) {
67  if constexpr (std::is_same_v<T, std::uint16_t>) {
68  m_mgr.Update(ptr, boost::numeric_cast<std::uint16_t>(*value), origin);
69  } else if constexpr (std::is_same_v<T, std::chrono::seconds>) {
70  m_mgr.Update(ptr, T{*value}, origin);
71  } else {
72  m_mgr.Update(ptr, *value, origin);
73  }
74  }
75  }
76  log4cplus::Logger m_logger;
77  Configuration m_config;
79 };
80 
81 } // namespace daq::dpm
82 #endif // DAQ_DPM_SERVER_CONFIGMANAGER_HPP
Maintains the associativity of configuration attributes with metadata and value origin/priority.
Definition: manager.hpp:148
void Visit(Func &&func)
Visit each registered parameter.
Definition: manager.hpp:217
bool Update(AttrType *ptr, T const &value, OriginInfo const &origin)
Update configuration value taking into account the origin of the change.
Definition: manager.hpp:280
CurrentValue< AttrType > Get(AttrType *ptr) const
Get current configuration value and associated metadata and origin.
DPM Server specific configuration manager.
Configuration const & GetConfig() const
ConfigManager(log4cplus::Logger logger)
void LoadConfig()
Load configuration file and update configuration.
bool ParseArguments(int argc, char *argv[])
Parse configuration from command line arguments.
void Visit(Func &&func)
Visit all configuration parameters.
daq::config::Manager and associated types.
DPM server config.
@ Configuration
Configuration file.
std::optional< T > GetParamAs(std::string const &query, elt::configng::CiiConfigInstanceNode const &node)
Performs lookup of parameters in the form root/node/leaf relative to the provided node.
Definition: manager.hpp:337
Mutable metadata about a configuration attribute that describes where a value comes from.
Definition: manager.hpp:116
Represents active configuration.
Definition: config.hpp:33