ifw-ccf  1.0.0
configBase.hpp
Go to the documentation of this file.
1 
5 #ifndef CCF_COMMON_CONFIG_BASE_HPP_H_
6 #define CCF_COMMON_CONFIG_BASE_HPP_H_
7 
8 #include <yaml-cpp/yaml.h>
9 
10 #include <dit/did/Did.hpp>
11 
12 #include <ccf/common/base.hpp>
13 
14 namespace ccf::common {
15 
17  const std::string CFG_DEF_LOGLEVEL = "INFO";
18 
20  const std::string CFG_PRIM_DID = "dit/stddid/primary.did";
21 
23  // @{
24  const std::string CFG_SYS_NAME = "sys.name";
25  const std::string CFG_SYS_DID = "sys.did%d";
26  const std::string CFG_SYS_REQ_ENDPOINT = "sys.req.endpoint";
27  const std::string CFG_SYS_DB_ENDPOINT = "sys.db.endpoint";
28  const std::string CFG_SYS_DB_TIMEOUT_SEC = "sys.db.timeout.sec";
29  const std::string CFG_SYS_DB_PREFIX = "sys.db.prefix";
30  const std::string CFG_SYS_SM_SCXML = "sys.sm.scxml";
31  const std::string CFG_SYS_LOG_LEVEL = "sys.log.level";
32  const std::string CFG_SYS_LOG_PROPERTIES = "sys.log.properties";
33  const std::string CFG_SYS_PUB_SUB_ENDPOINT = "sys.pub_sub.endpoint";
34 
35  const std::string CFG_SYS_REQ_HIST_SIZE = "sys.req.hist.size"; // Number lf elements in recoding history.
36  const std::string CFG_SYS_REQ_HIST_EXP = "sys.req.hist.expiration"; // Expiration time in seconds of elements in the rec hist.
37 
38  const std::string CFG_SYS_SIMULATION = "sys.simulation";
39  // @}
40 
42  // @{
43  const std::string CFG_MON_PERIOD = "mon.period";
44  const std::string CFG_MON_NB_OF_SAMPLES = "mon.nb_of_samples";
45  // @}
46 
48  // @{
49  const std::string CFG_CAM_NAME = "cam.name";
50  const std::string CFG_CAM_ID = "cam.id";
51  const std::string CFG_CAM_MODEL = "cam.model";
52  const std::string CFG_CAM_CHIP_MODEL = "cam.chip.model";
53  const std::string CFG_CAM_TYPE = "cam.type";
54  const std::string CFG_CAM_MANUFACTURER = "cam.manufacturer";
55  const std::string CFG_CAM_ADAPTER_PROTOCOL = "cam.adapter.protocol";
56  const std::string CFG_CAM_ADAPTER_MAPPING = "cam.adapter.mapping";
57  const std::string CFG_CAM_ADAPTER_API = "cam.adapter.api";
58  const std::string CFG_CAM_ADAPTER_ADDRESS = "cam.adapter.address";
59  const std::string CFG_CAM_ADAPTER_SIM_ADDRESS = "cam.adapter.sim_address";
60  const std::string CFG_CAM_ADAPTER_PROPERTY = "cam.adapter.property%d";
61  const std::string CFG_CAM_CHIP_WIDTH = "cam.chip.width";
62  const std::string CFG_CAM_CHIP_HEIGHT = "cam.chip.height";
63  const std::string CFG_CAM_CHIP_MAX_RES = "cam.chip.max_resolution";
64  const std::string CFG_CAM_CHIP_RESOLUTION = "cam.chip.resolution";
65  // @}
66 
68  // @{
69  const std::string CFG_ACQ_LOST_FRAMES = "acq.allow_lost_frames";
70  const std::string CFG_ACQ_FRAME_SKIPPING = "acq.allow_frame_skipping";
71  const std::string CFG_ACQ_PRIORITY = "acq.priority";
72  // @}
73 
75  const std::string CFG_PROC_SKIP_FRAMES = "proc%d.allow_frame_skipping";
76 
77  const std::string CFG_PROC_PRIORITY = "proc%d.priority";
78 
79  const std::string CFG_PUB_PRIORITY = "proc%d.pub%d.priority";
80 
84  class ConfigBase: public Base {
85  public:
86 
87  // Singleton instance.
89 
91  static ConfigBase& Instance();
92 
93  ~ConfigBase();
94 
96  void Load(const std::string& filename);
97 
99  const std::string& GetFilename() const;
100 
103  template <class TYPE> bool HasPar(const std::string& name,
104  TYPE& value) const {
105  CCFTRACE;
106  return m_config.HasPar(name, value);
107  }
108 
110  template <class TYPE> TYPE GetValue(const std::string& name) const {
111  CCFTRACE;
112  TYPE tmp_value;
113  m_config.GetValue(name, tmp_value, true);
114  return tmp_value;
115  }
116 
118  const dit::did::Did& GetDictionary() const;
119 
121  uint32_t GetMaxFrameSize();
122 
125  virtual uint32_t GetMaxFrameSizeUser();
126 
129  template <class TYPE>
130  bool HasAdapterProperty(const std::string& property,
131  TYPE& value) {
132  CCFTRACE;
133  std::string tmp_value;
134  if (_HasAdapterProperty(property, tmp_value)) {
135  ctd::conversion::Convert(tmp_value, value);
136  return true;
137  } else {
138  return false;
139  }
140  }
141 
142  protected:
143  bool _HasAdapterProperty(const std::string& property,
144  std::string& value);
145 
146  private:
147  ConfigBase();
148  ctd::file::Yaml m_config;
149  std::string m_config_filename;
150  dit::did::Did m_dictionary;
151  };
152 
154  inline ConfigBase& GetCfg() {
155  return ConfigBase::Instance();
156  }
157 
158 }
159 
160 #endif // CCF_COMMON_CONFIG_BASE_HPP_H_
ccf::common::CFG_CAM_ID
const std::string CFG_CAM_ID
Definition: configBase.hpp:50
ccf::common::CFG_CAM_CHIP_WIDTH
const std::string CFG_CAM_CHIP_WIDTH
Definition: configBase.hpp:61
ccf::common::ConfigBase::HasPar
bool HasPar(const std::string &name, TYPE &value) const
Definition: configBase.hpp:103
ccf::common::CFG_ACQ_LOST_FRAMES
const std::string CFG_ACQ_LOST_FRAMES
Definition: configBase.hpp:69
ccf::common::CFG_SYS_REQ_ENDPOINT
const std::string CFG_SYS_REQ_ENDPOINT
Definition: configBase.hpp:26
ccf::common::CFG_MON_PERIOD
const std::string CFG_MON_PERIOD
Definition: configBase.hpp:43
ccf::common::ConfigBase::GetMaxFrameSizeUser
virtual uint32_t GetMaxFrameSizeUser()
Definition: configBase.cpp:90
ccf::common::ConfigBase
Config class for CCF applications.
Definition: configBase.hpp:84
ccf::common::CFG_SYS_REQ_HIST_EXP
const std::string CFG_SYS_REQ_HIST_EXP
Definition: configBase.hpp:36
ccf::common::CFG_SYS_SM_SCXML
const std::string CFG_SYS_SM_SCXML
Definition: configBase.hpp:30
ccf::common::CFG_PROC_PRIORITY
const std::string CFG_PROC_PRIORITY
Definition: configBase.hpp:77
ccf::common::CFG_CAM_MODEL
const std::string CFG_CAM_MODEL
Definition: configBase.hpp:51
ccf::common::CFG_SYS_PUB_SUB_ENDPOINT
const std::string CFG_SYS_PUB_SUB_ENDPOINT
Definition: configBase.hpp:33
ccf::common::ConfigBase::Load
void Load(const std::string &filename)
Load the given configuration file.
Definition: configBase.cpp:29
ccf::common::CFG_SYS_DB_ENDPOINT
const std::string CFG_SYS_DB_ENDPOINT
Definition: configBase.hpp:27
ccf::common::ConfigBase::GetFilename
const std::string & GetFilename() const
Get the complete name of the configuration file currently loaded.
Definition: configBase.cpp:75
ccf::common::Base
Class to be used as parent all CCF classes.
Definition: base.hpp:93
ccf::common::CFG_SYS_LOG_PROPERTIES
const std::string CFG_SYS_LOG_PROPERTIES
Definition: configBase.hpp:32
ccf::common::CFG_CAM_ADAPTER_MAPPING
const std::string CFG_CAM_ADAPTER_MAPPING
Definition: configBase.hpp:56
ccf::common::CFG_ACQ_PRIORITY
const std::string CFG_ACQ_PRIORITY
Definition: configBase.hpp:71
ccf::common::CFG_CAM_NAME
const std::string CFG_CAM_NAME
Definition: configBase.hpp:49
ccf::common::CFG_SYS_DID
const std::string CFG_SYS_DID
Definition: configBase.hpp:25
ccf::common::ConfigBase::GetMaxFrameSize
uint32_t GetMaxFrameSize()
Return the maximum frame size in bytes with the associated camera/configuration.
Definition: configBase.cpp:85
ccf::common::CFG_SYS_SIMULATION
const std::string CFG_SYS_SIMULATION
Definition: configBase.hpp:38
ccf::common::CFG_DEF_LOGLEVEL
const std::string CFG_DEF_LOGLEVEL
Default logging level.
Definition: configBase.hpp:17
ccf::common::CFG_CAM_CHIP_RESOLUTION
const std::string CFG_CAM_CHIP_RESOLUTION
Definition: configBase.hpp:64
ccf::common::CFG_CAM_CHIP_MAX_RES
const std::string CFG_CAM_CHIP_MAX_RES
Definition: configBase.hpp:63
ccf::common::GetCfg
ConfigBase & GetCfg()
Return reference to the singleton instance of the configuration.
Definition: configBase.hpp:154
ccf::common::CFG_CAM_CHIP_MODEL
const std::string CFG_CAM_CHIP_MODEL
Definition: configBase.hpp:52
ccf::common::ConfigBase::s_instance
static ConfigBase * s_instance
Definition: configBase.hpp:88
ccf::common::ConfigBase::~ConfigBase
~ConfigBase()
Definition: configBase.cpp:25
ccf::common::ConfigBase::GetDictionary
const dit::did::Did & GetDictionary() const
Return reference to the Dictionary object in which all Dictionaries specified in cfg are contained.
Definition: configBase.cpp:80
ccf::common::ConfigBase::HasAdapterProperty
bool HasAdapterProperty(const std::string &property, TYPE &value)
Definition: configBase.hpp:130
ccf::common::CFG_SYS_NAME
const std::string CFG_SYS_NAME
Definition: configBase.hpp:24
ccf::common::CFG_CAM_ADAPTER_SIM_ADDRESS
const std::string CFG_CAM_ADAPTER_SIM_ADDRESS
Definition: configBase.hpp:59
ccf::common::CFG_ACQ_FRAME_SKIPPING
const std::string CFG_ACQ_FRAME_SKIPPING
Definition: configBase.hpp:70
ccf::common::CFG_CAM_MANUFACTURER
const std::string CFG_CAM_MANUFACTURER
Definition: configBase.hpp:54
ccf::common::ConfigBase::_HasAdapterProperty
bool _HasAdapterProperty(const std::string &property, std::string &value)
Definition: configBase.cpp:99
ccf::common::CFG_CAM_ADAPTER_PROPERTY
const std::string CFG_CAM_ADAPTER_PROPERTY
Definition: configBase.hpp:60
base.hpp
ccf::common::CFG_SYS_LOG_LEVEL
const std::string CFG_SYS_LOG_LEVEL
Definition: configBase.hpp:31
ccf::common::CFG_CAM_TYPE
const std::string CFG_CAM_TYPE
Definition: configBase.hpp:53
ccf::common::CFG_SYS_DB_TIMEOUT_SEC
const std::string CFG_SYS_DB_TIMEOUT_SEC
Definition: configBase.hpp:28
ccf::common
Definition: appBase.cpp:8
ccf::common::CFG_SYS_REQ_HIST_SIZE
const std::string CFG_SYS_REQ_HIST_SIZE
Definition: configBase.hpp:35
ccf::common::CFG_PROC_SKIP_FRAMES
const std::string CFG_PROC_SKIP_FRAMES
Cfg par to allow silent frame skipping, i.e. no error reported, but frames skipped registered in stat...
Definition: configBase.hpp:75
ccf::common::CFG_SYS_DB_PREFIX
const std::string CFG_SYS_DB_PREFIX
Definition: configBase.hpp:29
ccf::common::ConfigBase::GetValue
TYPE GetValue(const std::string &name) const
Get a parameter value from the configuration.
Definition: configBase.hpp:110
ccf::common::CFG_MON_NB_OF_SAMPLES
const std::string CFG_MON_NB_OF_SAMPLES
Definition: configBase.hpp:44
CCFTRACE
#define CCFTRACE
TRACE log macro. Includes the location ("CCFLOC") in the log message.
Definition: base.hpp:403
ccf::common::CFG_CAM_CHIP_HEIGHT
const std::string CFG_CAM_CHIP_HEIGHT
Definition: configBase.hpp:62
ccf::common::ConfigBase::Instance
static ConfigBase & Instance()
Return reference to unique instance of the configuration class.
Definition: configBase.cpp:13
ccf::common::CFG_CAM_ADAPTER_ADDRESS
const std::string CFG_CAM_ADAPTER_ADDRESS
Definition: configBase.hpp:58
ccf::common::CFG_CAM_ADAPTER_API
const std::string CFG_CAM_ADAPTER_API
Definition: configBase.hpp:57
ccf::common::CFG_PRIM_DID
const std::string CFG_PRIM_DID
Name of primary dictionary.
Definition: configBase.hpp:20
ccf::common::CFG_PUB_PRIORITY
const std::string CFG_PUB_PRIORITY
Definition: configBase.hpp:79
ccf::common::CFG_CAM_ADAPTER_PROTOCOL
const std::string CFG_CAM_ADAPTER_PROTOCOL
Definition: configBase.hpp:55