Boost logo

Boost Users :

From: B A (ms_username_at_[hidden])
Date: 2021-01-03 12:06:12


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 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