[boost::fsm] Accessing most recently posted event
Is there a way that an event triggered on entry to a state can access the event that caused that state to be entered? I'm thinking of adding a line to the process_event method in a wrapper class derived from state_machine that stores the event object received as a way of doing this. Marcin Tustin IT Innovation Centre 2 Venture Road Chilworth Science Park Southampton, SO16 7NP, UK tel: +44 23 8076 0834 fax: +44 23 8076 0833 mailto:mt@it-innovation.soton.ac.uk http://www.it-innovation.soton.ac.uk
Hi Marcin
Is there a way that an event triggered on entry to a state can access the event that caused that state to be entered?
No, not currently. I was thinking about providing something like that but postponed it because I've never had the need. Neither have I revceived any other requests in that direction.
I'm thinking of adding a line to the process_event method in a wrapper class derived from state_machine that stores the event object received as a way of doing this.
That works only as long as you don't post any events. I order to catch those events as well you'd need to do the same for state_machine::post_event, which is not part of the documented interface. I don't currently see a proper way how users can implement this themselves (save of changing the library code), if they want to be able to post events. I think the best way is to add the following member function to the simple_state interface: const event_base * current_event() const If the state entry was triggered by an event, current_event() returns a pointer to the event that triggered the transition. Otherwise, it returns 0 (e.g. the state was entered as a result of calling state_machine::initiate(). We could also name this triggering_event()... Thoughts? 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
-
Marcin Tustin