7 #include "fwServices/helper/ConfigLauncher.hpp" 9 #include <fwServices/macros.hpp> 11 #include <fwData/Composite.hpp> 12 #include <fwData/String.hpp> 14 #include <fwDataCamp/getObject.hpp> 16 #include <fwTools/fwID.hpp> 18 #include <boost/property_tree/xml_parser.hpp> 27 const std::string ConfigLauncher::s_SELF_KEY =
"self";
28 const std::string ConfigLauncher::s_GENERIC_UID_KEY =
"GENERIC_UID";
33 m_configIsRunning(false)
46 const ::fwServices::IService::sptr& service)
48 ::fwServices::IService::ConfigType srvCfg;
49 const ::fwServices::IService::ConfigType* curConfig = &config;
51 const ::fwServices::IService::ConfigType& oldConfig = config;
52 SLM_ASSERT(
"There must be only one <appConfig/> element.", oldConfig.count(
"appConfig") == 1 );
54 const ::fwServices::IService::ConfigType& appConfig = oldConfig.get_child(
"appConfig");
55 const std::string appCfgId = appConfig.get<std::string>(
"<xmlattr>.id");
57 srvCfg.add(
"config.appConfig.<xmlattr>.id", appCfgId);
58 ::fwServices::IService::ConfigType& newCfg = srvCfg.get_child(
"config.appConfig");
61 auto inoutsCfg = oldConfig.equal_range(
"inout");
62 for (
auto itCfg = inoutsCfg.first; itCfg != inoutsCfg.second; ++itCfg)
64 ::fwServices::IService::ConfigType parameterCfg;
66 const std::string key = itCfg->second.get<std::string>(
"<xmlattr>.key");
67 SLM_ASSERT(
"[" + appCfgId +
"] Missing 'key' tag.", !key.empty());
69 const std::string uid = itCfg->second.get<std::string>(
"<xmlattr>.uid");
70 SLM_ASSERT(
"[" + appCfgId +
"] Missing 'uid' tag.", !uid.empty());
72 parameterCfg.add(
"<xmlattr>.replace", key);
74 const std::string strOptional = itCfg->second.get<std::string>(
"<xmlattr>.optional",
"no");
75 const bool optional = strOptional ==
"yes" ?
true :
false;
80 parameterCfg.add(
"<xmlattr>.uid", uid);
84 SLM_ASSERT(
"Object key '" + key +
"'with uid '" + uid +
"' does not exist.", obj);
85 parameterCfg.add(
"<xmlattr>.uid", obj->getID());
88 newCfg.add_child(
"parameters.parameter", parameterCfg);
93 auto paramsCfg = oldConfig.equal_range(
"parameter");
94 for (
auto itCfg = paramsCfg.first; itCfg != paramsCfg.second; ++itCfg)
96 ::fwServices::IService::ConfigType parameterCfg;
98 const std::string replace = itCfg->second.get<std::string>(
"<xmlattr>.replace");
99 SLM_ASSERT(
"[" + appCfgId +
"] Missing 'replace' tag.", !replace.empty());
101 parameterCfg.add(
"<xmlattr>.replace", replace);
103 if(itCfg->second.get_child(
"<xmlattr>").count(
"uid") == 1)
105 const std::string uid = itCfg->second.get<std::string>(
"<xmlattr>.uid");
106 parameterCfg.add(
"<xmlattr>.uid", uid);
110 const std::string by = itCfg->second.get<std::string>(
"<xmlattr>.by");
111 parameterCfg.add(
"<xmlattr>.by", by);
114 newCfg.add_child(
"parameters.parameter", parameterCfg);
117 SLM_ASSERT(
"There must be only one <config/> element.", curConfig->count(
"config") == 1 );
119 const ::fwServices::IService::ConfigType& srvconfig = curConfig->get_child(
"config");
121 SLM_ASSERT(
"There must be only one <appConfig/> element.", srvconfig.count(
"appConfig") == 1 );
123 const ::fwServices::IService::ConfigType& appConfigCfg = srvconfig.get_child(
"appConfig");
130 const FieldAdaptorType& optReplaceMap )
132 typedef ::fwActivities::registry::ActivityAppConfig AppConfig;
133 FieldAdaptorType replaceMap(optReplaceMap);
137 replaceMap[ConfigLauncher::s_GENERIC_UID_KEY] = genericUidAdaptor;
139 for(
const AppConfig::ActivityAppConfigParamsType::value_type& param : m_appConfig.parameters)
141 replaceMap[param.replace] = param.by;
146 m_appConfigManager->setConfig( m_appConfig.id, replaceMap );
149 m_appConfigManager->launch();
161 m_appConfigManager->stopAndDestroy();
162 m_appConfigManager.reset();
Namespace fwServices is dedicated to (mimic) the dynamic affectation of methods to (pure data) object...
bool m_configIsRunning
to know if AppConfig is running
virtual FWSERVICES_API ~ConfigLauncher()
Destructor. Do nothing.
virtual FWSERVICES_API void stopConfig()
Stop/destroy AppConfig and disconnect connection with config root object.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
Base class for each data object.
static FWSERVICES_API std::shared_ptr< IAppConfigManager > New()
static FWSERVICES_API std::string getUniqueIdentifier(const std::string &serviceUid="")
Create an unique identifier.
FWSERVICES_API ConfigLauncher()
Constructor. Do nothing.
virtual FWSERVICES_API void parseConfig(const ::fwServices::IService::ConfigType &config, const ::fwServices::IService::sptr &service)
Parse a ConfigLauncher configuration.
virtual FWSERVICES_API void startConfig(std::shared_ptr< ::fwServices::IService > srv, const FieldAdaptorType &optReplaceMap=FieldAdaptorType())
Launch Appconfig.