[statechart] handling unexpected events

I'm attempting to use StateChart to model a simple socket protocol and I'm having difficulty understanding how to handle protocol errors. I've read the sections on Error handling and two phase exit without gaining much insight. Those sections seem to be concerned with user-written code that cannot complete and thus must throw an exception. The type of error I'm currently concerned with is an unexpected event. For example, in this simple protocol we must first receive a hello before being ready to handle requests. A request returns data and must be followed by a commit, which completes the transaction and returns us to the ready state. (start state) (hello event) -> (ready state) (ready state) (get event) -> (data delivered) (data delivered) (commit event) -> (ready state) My problem is this: how do I detect and recover when I'm in the (data delivered) state and the next event is not a (commit event)? The only thing I can see is that the unconsumed_event() function is called with the unexpected event object. What I'd like to do in this function is: 1. Abort my transaction and force the state machine back to the Ready state. I'm not sure how to do this. 2. Reprocess the unexpected event if it is a hello or get, discard it otherwise. I'm not sure how to do this, either. At a more abstract level, it seems that unconsumed_event() is the only way to deal with an unexpected event and to try to reset the state machine. Is this true? Thanks, -- Robert

From: Andreas Huber
Subject: RE: [Boost-users] [statechart] handling unexpected events To: "Robert Mecklenburg" Date: Monday, September 22, 2008, 7:11 PM Hi Robert
Sorry for the long delay, I'm currently on holiday. I seems your problem is best solved by defining the following reactions for the data_delivered state:
1. An ordinary transition to the ready state (triggered by the commit event) 2. A transition to the ready state, triggered by event_base, with a transition action that simply calls post_event, passing the event.
If you don't need to do anything special with the commit event, you could even omit the first transition.
Please let me know whether that works for you. I'll have limited internet access for another 24 hours, after that I might not be able to answer for a few days.
Please don't forward this to the NG, I'll do so myself when I return. Thanks!
HTH,
Andreas
-- 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
-
Robert Mecklenburg