Boost logo

Boost Users :

Subject: [Boost-users] [Statechart] question about event processing rules in orthogonal states.
From: Ernesto Rodriguez Reina (erreina_at_[hidden])
Date: 2015-11-25 13:31:54


Hi everyone,

The event processing order of a normal (non-orthogonal) state is first the
innermost and if not handled (or forwarded) then it parent, and that
behaviour is repeated upward until the event is discarded (or deferred).
But when we are in the presence of orthogonal states, then the behaviour I
am getting is a bit different, for example given the following statechart:

<code>
struct EvTest : sc::event< EvTest > {};

struct Test;
struct Inner1;
struct Inner2;

struct Machine : sc::state_machine< Machine, Test > {};

struct Test : sc::simple_state<Test, Machine, mpl::list<Inner1, Inner2> >{
  typedef sc::custom_reaction< EvTest > reactions;

  sc::result react( const EvTest){
    std::cout << "Test" << std::endl;
// return discard_event();
    return forward_event();
  }
};

struct Inner1 : sc::simple_state<Inner1, Test::orthogonal< 0 > >{};

struct Inner2 : sc::simple_state<Inner2, Test::orthogonal< 1 > >{
  typedef sc::custom_reaction< EvTest > reactions;

  sc::result react( const EvTest){
    std::cout << "Inner2" << std::endl;
    return forward_event();
  }
};
</code>

When received the event "EvTest" the output I am getting is:

<output>
Test
Inner2
Test
</output>

That means that the handler in the state "Test" is called twice. If in the
handler at test we discard instead of forwarding then we get that only the
handler of "Test" is called.

I thought that without taking into account if the children are orthogonal
or not, the event will be processed first by the children (all of them in
the case of orthogonal state until one discard or defer the event), and
event is not discarded (or deferred) then the parent process the event. It
is that OK? If so why I am getting that weird behaviour in my example?

Any thoughts and comments are more than welcome.

Best,

Ernesto Rodriguez Reina



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net