Boost logo

Boost Users :

Subject: [Boost-users] [MSM] Use events twice
From: Sebastian Redl (sebastian.redl_at_[hidden])
Date: 2011-04-08 12:04:11


Hi,

I'm using MSM to implement a client for a simple network application. Basically, the server sends messages and the client changes state and responds to them as appropriate.

One of these messages is THROW. THROW gets two arguments: an identifier (0-3) and a value. My client is supposed to sum up the values for consecutive THROW events with the same identifier, and on a change of identifier, store the sum somewhere and start over for the new identifier.

So I have three states (id0, id1, id2 - there's some special handling, which is why they're separate states) and an event Throw(id, value). The transitions for idN are:
Throw(my id, value) -> no switch, state.sum += value
Throw(other id, value) -> switch to state of other id, reprocess event, storing the sum is handled by the exit action

In other words, I want the next state to immediately handle the event as well, because there's a value there I need to store. The question is, how do I do this?

Here's a sequence of events and actions that could occur:
E1: [init] Throw(0, 4) -> [id0: ?]
Entry [id0: ?] -> [id0: 0]
[id0: 0] reprocess E1 -> [id0: 4]
E2: [id0: 4] Throw(0, 8) -> [id0: 12]
E3: [id0: 12] Throw(1, 7) -> [id1: ?]
Exit [id0: 12] -> save 12
Entry [id1: ?] -> [id1: 0]
[id1: 0] reprocess E3 -> [id1: 7]

I hope I was clear enough.
Sebastian


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