Hi,
Interesting case. Indeed there is not built in "On Exit" space within a state.
By this I mean that if you "jump" from one state to another in a given fsm, then your state is exited with no further notification to your actions.
IF your state "transits" to another state, then you can insert a state in between and do your clean up here.
in your case, I would add a new global event referencing the moment you need to clean up, so your state doesn't jumps to the target state, but is first redirected to a clean up state, and then wiat there for the final global event to be fired.
Does that sound like a solution for your case?
the problem with this case is that it's not really the way Finite state machine works in theory,
As I think of it, there is another way, maintain a bool flag called "dirty", and you set to true with you enter a state, if you jump to another state, that state checked for "dirty" and if true, will go trhough a clean up state, and then follow the actually expected procedures. the clean up state mark the "dirty" flag down when proceeding.
bye,
Jean