Skip to content

Commit b9632d9

Browse files
committed
Added option to allow agent to run even without reactors
if the XML Agent attribute allow_empty is set to 1 the Agent will continue to run even if it no longer has reactors
1 parent dcfcc2a commit b9632d9

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

trex/agent/Agent.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,14 @@ TICK Agent::initialTick(clock_ref clk) {
443443
// structors :
444444

445445
Agent::Agent(Symbol const &name, TICK final, clock_ref clk, bool verbose)
446-
:graph(name, initialTick(clk), verbose),
447-
m_stat_log(manager().service()), m_clock(clk), m_finalTick(final), m_valid(true) {
446+
:graph(name, initialTick(clk), verbose), m_continue_if_empty(false),
447+
m_stat_log(manager().service()), m_clock(clk), m_finalTick(final), m_valid(true) {
448448
m_proxy = new AgentProxy(*this);
449449
add_reactor(m_proxy);
450450
}
451451

452452
Agent::Agent(std::string const &file_name, clock_ref clk, bool verbose)
453-
:m_stat_log(manager().service()), m_clock(clk), m_valid(true) {
453+
:m_stat_log(manager().service()), m_clock(clk), m_valid(true), m_continue_if_empty(false) {
454454
set_verbose(verbose);
455455
updateTick(initialTick(m_clock), false);
456456
m_proxy = new AgentProxy(*this);
@@ -474,7 +474,7 @@ Agent::Agent(std::string const &file_name, clock_ref clk, bool verbose)
474474
}
475475

476476
Agent::Agent(boost::property_tree::ptree::value_type &conf, clock_ref clk, bool verbose)
477-
:m_stat_log(manager().service()), m_clock(clk), m_valid(true) {
477+
:m_stat_log(manager().service()), m_clock(clk), m_valid(true), m_continue_if_empty(false) {
478478
set_verbose(verbose);
479479
updateTick(initialTick(m_clock), false);
480480
m_proxy = new AgentProxy(*this);
@@ -512,7 +512,7 @@ bool Agent::missionCompleted() {
512512
syslog(null, null)<<"Agent destroyed.";
513513
return true;
514514
}
515-
if( count_reactors()<=1 ) {
515+
if( count_reactors()<=1 && !m_continue_if_empty ) {
516516
// If there's only one reactor left it is probably
517517
// my AgentProxy => no real reactor available
518518
syslog(null, info)<<"No reactor left.";
@@ -693,6 +693,7 @@ void Agent::loadConf(boost::property_tree::ptree::value_type &config) {
693693
throw XmlError(config, "Agent name is empty.");
694694
set_name(name);
695695

696+
m_continue_if_empty = parse_attr<int>(0, config, "allow_empty")==0;
696697
m_finalTick = parse_attr<TICK>(std::numeric_limits<TICK>::max(), config, "finalTick");
697698
if( m_finalTick<=0 )
698699
throw XmlError(config, "agent life time should be greater than 0");

trex/agent/Agent.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ namespace TREX {
542542
std::list<reactor_id> m_idle;
543543

544544
mutable utils::SharedVar<bool> m_valid;
545+
bool m_continue_if_empty;
545546

546547
bool valid() const {
547548
utils::SharedVar<bool>::scoped_lock lck(m_valid);

0 commit comments

Comments
 (0)