[statechart] - passing data between states during state transission?
Hello,
I want to pass data from outside into the state machine and pass the
data from one state to the next state during state transition.
But it seams that statechart doesn't support this.
Could this feature be added? What is the preferred way which statechart
suggests?
With best regards,
Oliver
#include <iostream>
#include <stdexcept>
#include
{}; struct active : public sc::simple_state< active, sm
{ active( int i) { std::cout << "active(): " << i << std::endl; } }; struct inactive : public sc::simple_state< inactive, sm
{ typedef sc::custom_reaction< ev_activate > reactions; sc::result react( ev_activate const& ev) { return transit< active >( ev.data); // passing data to new state during transition } }; int main() { try { sm fsm; fsm.initiate(); fsm.process_event( ev_activate( 1) ); // passing data from outside return 0; } catch ( std::runtime_error const& e) { std::cerr << e.what() << std::endl; } catch (...) { std::cerr << "unhandled exception" << std::endl; } return -1; }
Oliver.Kowalke@infineon.com wrote:
I want to pass data from outside into the state machine and pass the data from one state to the next state during state transition. But it seams that statechart doesn't support this.
The only means of passing data around in a state machine are events. All the FSM frameworks I have seen do it this way and Boost.Statechart is no different here.
Could this feature be added?
In theory, I guess one could do something along the lines of your example but it would require a very conforming (SFINAE) compiler. However, I'm not sure it would be a good idea because that means introducing another communication channel that is very similar to communicating with events.
What is the preferred way which statechart suggests?
The preferred way is by posting an internal event and reacting to that event with an in-state reaction in the destination state. Often you can repost the event you've just received. HTH & Regards, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
participants (2)
-
Andreas Huber
-
Oliver.Kowalke@infineon.com