ADTF_DISPLAY_TOOLBOX  3.8.0 (ADTF 3.14.3)
runtimeconfig.h
Go to the documentation of this file.
1 
7 #pragma once
8 
9 #include <adtf_platform_inc.h>
10 #include <adtf_base.h>
11 
15 class cRuntimeConfigFile : public adtf::ucom::object<adtf::base::configuration<>>
16 {
17 protected:
19  adtf_util::cFilename m_strConfigFile;
20 
21 public:
27  cRuntimeConfigFile(const adtf_util::cFilename &strConfigFile);
28 
29 
30 
31 
32  virtual ~cRuntimeConfigFile();
33 
39  tResult Load();
40 
46  tResult Save();
47 
53  tResult ClearAllProperties();
54 
61  tVoid SetConfigFile(const adtf_util::cFilename &strFilename);
62 
68  adtf_util::cFilename GetConfigFile();
69 
70 private:
79  tResult StoreProperty(adtf_util::cString strPrefix, adtf_util::cDOMElement* pConfig);
80 };
81 
82 
83 
84 
89 {
90 public:
97  virtual tResult SaveConfiguration(adtf::base::IConfiguration* pRuntimeConfig) = 0;
98 
106  virtual tResult LoadConfiguration(adtf::base::IConfiguration* pRuntimeConfig) = 0;
107 };
108 
109 
122 template <typename T>
124  public T,
126 {
127 
128 protected:
130  adtf::base::property_variable<adtf_util::cFilename> m_strConfigFile;
133 
134 public:
137 
143  tResult SaveRuntimeConfigFile();
149  tResult LoadRuntimeConfigFile();
150 
151 protected:
160  virtual tResult SaveConfiguration(adtf::base::IConfiguration* pRuntimeConfig) = 0;
161 
171  virtual tResult LoadConfiguration(adtf::base::IConfiguration* pRuntimeConfig) = 0;
172 
173 private:
179  adtf_util::cString GetConfigFile();
180 };
181 
182 
183 
184 
185 
186 template <typename T>
188  m_strConfigFile("$(ADTF_GRAPH_DIR)/$(THIS_OBJECT_FULL_NAME)"),
189  // config file cant be set at creation because property will be resolved later
190  m_oRuntimeConfig("")
191 {
192  m_strConfigFile.SetDescription("Path to configuration file for runtime settings.");
193  T::RegisterPropertyVariable("runtime_config_file_path", m_strConfigFile);
194 }
195 
196 template <typename T>
198 {
199 
200 }
201 
202 template <typename T>
204 {
205  return static_cast<adtf_util::cFilename>(m_strConfigFile).MakeNativeSlashes();
206 }
207 
208 template <typename T>
210 {
211  if (m_oRuntimeConfig.GetConfigFile().Empty)
212  {
213  m_oRuntimeConfig.SetConfigFile(GetConfigFile());
214  }
215 
216  RETURN_IF_FAILED(m_oRuntimeConfig.ClearAllProperties());
217 
218  RETURN_IF_FAILED(this->SaveConfiguration(&m_oRuntimeConfig));
219  if IS_FAILED(m_oRuntimeConfig.Save())
220  {
221  RETURN_AND_LOG_ERROR_STR(ERR_FAILED, "Runtime configuration could not be stored");
222  }
223  else
224  {
225  LOG_INFO("Runtime configuration was stored to file");
226  }
227  RETURN_NOERROR;
228 }
229 
230 template <typename T>
232 {
233  if (!adtf_util::cFileSystem::Exists(GetConfigFile()))
234  {
235  RETURN_ERROR_DESC(ERR_FILE_NOT_FOUND,
236  "Runtime configuration file '%s' does not exist", static_cast<adtf_util::cString>(m_strConfigFile).GetPtr());
237  }
238 
239  if (m_oRuntimeConfig.GetConfigFile().Empty)
240  {
241  m_oRuntimeConfig.SetConfigFile(GetConfigFile());
242  }
243 
244  RETURN_IF_FAILED(m_oRuntimeConfig.Load());
245 
246  if IS_FAILED(this->LoadConfiguration(&m_oRuntimeConfig))
247  {
248  RETURN_ERROR_DESC(ERR_FAILED, "Runtime configuration could not be read");
249  }
250 
251  RETURN_NOERROR;
252 }
Interface for loading and storing runtime configuration properties to and from passed adtf::base::ICo...
Definition: runtimeconfig.h:89
virtual tResult LoadConfiguration(adtf::base::IConfiguration *pRuntimeConfig)=0
Implementation has to get all properties from pRuntimeConfig (contains all loaded properties from run...
virtual tResult SaveConfiguration(adtf::base::IConfiguration *pRuntimeConfig)=0
Implementation has to add all properties to be written to runtime configuration file to pRuntimeConfi...
Class is a adtf::base::configuration that allows the storing and loading of all contained properties ...
Definition: runtimeconfig.h:16
tResult Save()
Saves all properties of this instance to the configured xml file.
tResult ClearAllProperties()
Clears all properties currently stored in cRuntimeConfigFile.
adtf_util::cFilename m_strConfigFile
path to the xml file
Definition: runtimeconfig.h:19
cRuntimeConfigFile(const adtf_util::cFilename &strConfigFile)
Constructor.
tVoid SetConfigFile(const adtf_util::cFilename &strFilename)
Setter for xml config file to load and store runtime configuration.
adtf_util::cFilename GetConfigFile()
Setter for xml config file to load and store runtime configuration.
tResult StoreProperty(adtf_util::cString strPrefix, adtf_util::cDOMElement *pConfig)
Stores all properties of this instance in DOM pConfig.
tResult Load()
Loads all properties from the configured xml file and stores it to this instance.
Template class enables the loading and storing of runtime configuration data.
adtf::base::property_variable< adtf_util::cFilename > m_strConfigFile
CE property_variable storing path of runtime configuration file.
adtf_util::cString GetConfigFile()
Getter for path of configuration file.
virtual tResult LoadConfiguration(adtf::base::IConfiguration *pRuntimeConfig)=0
Callback to be implemented by user of runtime_configuration.
tResult SaveRuntimeConfigFile()
Saves all properties to the file configured with adtf-property runtime_config_file_path.
tResult LoadRuntimeConfigFile()
Loads all properties from the file configured with adtf-property runtime_config_file_path.
virtual tResult SaveConfiguration(adtf::base::IConfiguration *pRuntimeConfig)=0
Callback to be implemented by user of runtime_configuration.
cRuntimeConfigFile m_oRuntimeConfig
actual runtime configuration