Skip to content

Commit

Permalink
Added option to allow agent to run even without reactors
Browse files Browse the repository at this point in the history
if the XML Agent attribute allow_empty is set to 1 the Agent will
continue to run even if it no longer has reactors
  • Loading branch information
fredpy committed Dec 23, 2016
1 parent dcfcc2a commit b9632d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions trex/agent/Agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -443,14 +443,14 @@ TICK Agent::initialTick(clock_ref clk) {
// structors :

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

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

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

m_continue_if_empty = parse_attr<int>(0, config, "allow_empty")==0;
m_finalTick = parse_attr<TICK>(std::numeric_limits<TICK>::max(), config, "finalTick");
if( m_finalTick<=0 )
throw XmlError(config, "agent life time should be greater than 0");
Expand Down
1 change: 1 addition & 0 deletions trex/agent/Agent.hh
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ namespace TREX {
std::list<reactor_id> m_idle;

mutable utils::SharedVar<bool> m_valid;
bool m_continue_if_empty;

bool valid() const {
utils::SharedVar<bool>::scoped_lock lck(m_valid);
Expand Down

0 comments on commit b9632d9

Please sign in to comment.