9#include <adtf_platform_inc.h>
12namespace adtf::disptb::detail
14class cPropertiesToDOMConverter :
public adtf::base::cPropertiesHelper
17 adtf::util::cDOMElement* m_oDomElement;
18 adtf::util::cString m_strPrefix;
21 explicit cPropertiesToDOMConverter(adtf::util::cDOMElement* pConfig, adtf::util::cString strPrefix):
22 m_oDomElement(pConfig), m_strPrefix(strPrefix)
26 tResult SetProperty(
const adtf::base::IProperty& oProperty)
28 adtf::util::cString strKey;
29 oProperty.GetName(adtf_string_intf(strKey));
31 adtf::util::cString strName = m_strPrefix + strKey;
32 adtf::util::cDOMElement* pDOMProp = 0;
33 RETURN_IF_FAILED(m_oDomElement->CreateChild(
"property", pDOMProp));
34 pDOMProp->SetAttribute(
"name", strName);
36 adtf::util::cString strValue;
37 oProperty.GetValue()->ToString(adtf_string_intf(strValue));
39 pDOMProp->SetAttribute(
"value", strValue);
45class cPropertiesNameExtractor :
public adtf::base::cPropertiesHelper
48 adtf::ucom::object_ptr<IProperties> m_oProperties;
49 std::vector<adtf::util::cString>& m_vecKeys;
52 explicit cPropertiesNameExtractor(adtf::ucom::object_ptr<IProperties> pProperties,
53 std::vector<adtf::util::cString>& vecKeys):
54 m_oProperties(pProperties), m_vecKeys(vecKeys)
58 tResult SetProperty(
const adtf::base::IProperty& oProperty)
60 adtf::util::cString strName;
61 RETURN_IF_FAILED(oProperty.GetName(adtf_string_intf(strName)));
62 m_vecKeys.push_back(strName);
68inline tResult clear_properties(adtf::ucom::object_ptr<adtf::base::IProperties> pProperties)
70 std::vector<adtf::util::cString> vecKeys;
72 pProperties->Get(pExtractor);
74 for (
const auto& strName : vecKeys)
76 RETURN_IF_FAILED(pProperties->RemoveProperty(strName));
114 adtf::ucom::object_ptr<adtf::base::IProperties> pProperties;
115 RETURN_IF_FAILED(this->GetProperties(pProperties));
116 RETURN_IF_FAILED(adtf::disptb::detail::clear_properties(pProperties));
118 adtf::util::cDOM oDOM;
121 adtf::util::cDOMElementRefList lstProperties;
122 if (IS_OK(oDOM.FindNodes(
"property", lstProperties)))
124 for (
const auto& prop : lstProperties)
126 adtf::base::property_variable<adtf::util::cString> oPropertyValue(prop->GetAttribute(
"value").GetPtr());
127 RegisterPropertyVariable(prop->GetAttribute(
"name").GetPtr(), oPropertyValue);
141 adtf::util::cDOM oDOM;
155 adtf::ucom::object_ptr<adtf::base::IProperties> pProperties;
156 RETURN_IF_FAILED(this->GetProperties(pProperties));
158 RETURN_IF_FAILED(adtf::disptb::detail::clear_properties(pProperties));
192 tResult
StoreProperty(adtf::util::cString strPrefix, adtf::util::cDOMElement* pConfig)
194 adtf::ucom::object_ptr<adtf::base::IProperties> pProperties;
195 this->GetProperties(pProperties);
199 RETURN_IF_FAILED(pProperties->Get(oConverter));
251 cRuntimeConfiguration();
252 ~cRuntimeConfiguration();
299cRuntimeConfiguration<T>::cRuntimeConfiguration():
300 m_strConfigFile(
"$(ADTF_GRAPH_DIR)/$(THIS_OBJECT_FULL_NAME)"),
304 m_strConfigFile.SetDescription(
"Path to configuration file for runtime settings.");
305 T::RegisterPropertyVariable(
"runtime_config_file_path",
m_strConfigFile);
309cRuntimeConfiguration<T>::~cRuntimeConfiguration()
316 return static_cast<adtf::util::cFilename
>(
m_strConfigFile).MakeNativeSlashes();
332 RETURN_AND_LOG_ERROR_STR(ERR_FAILED,
"Runtime configuration could not be stored");
336 LOG_INFO(
"Runtime configuration was stored to file");
346 RETURN_ERROR_DESC(ERR_FILE_NOT_FOUND,
"Runtime configuration file '%s' does not exist",
359 RETURN_ERROR_DESC(ERR_FAILED,
"Runtime configuration could not be read");
Interface for loading and storing runtime configuration properties to and from passed adtf::base::ICo...
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 ...
tResult Save()
Saves all properties of this instance to the configured xml file.
tResult ClearAllProperties()
Clears all properties currently stored in cRuntimeConfigFile.
cRuntimeConfigFile(const adtf::util::cFilename &strConfigFile)
Constructor.
adtf::util::cFilename m_strConfigFile
path to the xml file
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.
adtf::util::cFilename GetConfigFile()
Setter for xml config file to load and store runtime configuration.
tVoid SetConfigFile(const adtf::util::cFilename &strFilename)
Setter for xml config file to load and store runtime configuration.
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.
adtf::base::property_variable< adtf::util::cFilename > m_strConfigFile
CE property_variable storing path of runtime configuration file.
cRuntimeConfigFile m_oRuntimeConfig
actual runtime configuration