[statechart] Event dispatching for orthogonal states

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[statechart] Event dispatching for orthogonal states

Boost - Users mailing list
Hello,

I have following code :

/////////////////////////////////////////////

#include <iostream>
#include <boost/mpl/list.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/event.hpp>
#include <boost/statechart/transition.hpp>
#include <boost/statechart/custom_reaction.hpp>

namespace sc = boost::statechart;

struct Event1 : sc::event<Event1> {};
struct Event11 : sc::event<Event11> {};

struct Meta;

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

struct Meta2 : sc::simple_state<Meta2, Machine> {
  Meta2() { std::cout << "Meta2\n"; }
};

struct Inner1;
struct Inner2;
struct Meta : sc::simple_state<Meta, Machine, boost::mpl::list<Inner1, Inner2>> {
  Meta() { std::cout << "Meta\n"; }
  typedef sc::transition<Event1, Meta2> reactions;
};

struct Inner11 : sc::simple_state<Inner11, Meta::orthogonal<0>> {
  Inner11() { std::cout << "Inner11\n"; }
  typedef sc::custom_reaction<Event1> reactions;

  sc::result react(const Event1& ev) {
    std::cout << "Inner1 reaction\n";
    return forward_event();
  }
};

struct Inner1 : sc::simple_state<Inner1, Meta::orthogonal<0>> {
  Inner1() { std::cout << "Inner1\n"; }
  typedef sc::transition<Event11, Inner11> reactions;
};

struct Inner2 : sc::simple_state<Inner2, Meta::orthogonal<1>> {
  Inner2() { std::cout << "Inner2\n"; }
};



int main() {
  Machine m;
  m.initiate();
  m.process_event(Event11());
  m.process_event(Event1());
 
  return 0;
}

////////////////////

That gives me output:

Meta                                                                                                                                                                                          
Inner1                                                                                                                                                                                        
Inner2                                                                                                                                                                                        
Inner11                                                                                                                                                                                      
Meta2      


The goal was to get Event1 processed first in Inner11 state and then forward it to outer state Meta for further processing but looks like event dispatching does not work as expected. 
I can make it work in that way only if I put Event1 handling into Inner1 state.
I'm aware of limitation (https://www.boost.org/doc/libs/1_61_0/libs/statechart/doc/rationale.html#Limitations #Event dispatch to orthogonal regions) but as far I understand that considers that case when both Inner1 and Inner11 have same event processing, please correct me if I'm wrong.

Is current dispatching work correctly for my code?

Regards,
Andrew




_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users