Skip to content

Commit dcfcc2a

Browse files
committed
Added API to python in order to load reactors/plugins on the fly
method add_to_agent receives an xml tag that is parsed the same way as what is done in the Agent constructor allowing to add new reactors, plugins or goals on the fly based on XML NOTE: this need to be tested in multithreaded setup
1 parent 1b1d686 commit dcfcc2a

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

trex/agent/Agent.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,16 @@ void Agent::subConf(boost::property_tree::ptree &conf,
672672
sendRequests(conf);
673673
}
674674

675+
void Agent::add_to_agent(boost::property_tree::ptree::value_type &config) {
676+
if( !config.second.empty() ) {
677+
// TODO: may need to make it hread safe
678+
syslog(null, info)<<"Modifying agent based on additional XML";
679+
subConf(config.second, "");
680+
syslog(null, info)<<"End of modification";
681+
}
682+
}
683+
684+
675685
void Agent::loadConf(boost::property_tree::ptree::value_type &config) {
676686
if( !is_tag(config, "Agent") )
677687
throw XmlError(config, "Not an Agent node");

trex/agent/Agent.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ namespace TREX {
247247
return m_clock;
248248
}
249249

250+
void add_to_agent(boost::property_tree::ptree::value_type &config);
251+
250252
/** @brief run the agent
251253
*
252254
* This method runs the agent until its completes. It is just a

trex/python/agent_decls.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,10 @@ void export_agent() {
202202
"complete agent initialization.\n\n"
203203
"Raises:\n"
204204
" agent_exception: something went wrong during initialization.")
205+
.def("add_to_agent", &ta::Agent::add_to_agent, args("self", "xml"),
206+
" add new components to the agent.\n"
207+
"Raises:\n"
208+
" agent_exception: something went wrong during initialization.")
205209
.def("run", &ta::Agent::run, arg("self"),
206210
"run the agent until completion.\n\n"
207211
"Note: run calls initialize on its own so you do not need to\n\n"

0 commit comments

Comments
 (0)