Boost logo

Boost Users :

Subject: Re: [Boost-users] How do you handle state-independent events efficiently in MSM?
From: Christophe Henry (christophe.j.henry_at_[hidden])
Date: 2011-08-30 17:48:19


>I have a state machine that has a large number of event types but only a few different states. Some of the events can be received regardless of the

> state and the same action is taken regardless of which state the machine is in, so the event is really unrelated to the state. I there an efficient way

> of handling the events that are state independent rather than defining a transition from every possible state for each state independent event?

Clearly, this would be pretty ugly.

>A number of the events do transition the state machine and depend on the current state, so a transition is necessary. But if no state change is

> required for the event and the current state is not important, I'm not sure how to define event handling without defining a transition from all

> possible states. This winds up creating a much larger number of transitions than I really need, and a much longer compile time than I would like. I am

> looking for some way to handle these states that would still give me good run time speed, put not pay the penalty that defining a large number of

> transitions would impose.

There are 2 ways. The most evident would be to define internal transitions in your fsm. This means that they are taken (or not, depending on your guards and transition conflicts) whatever state currently is active. For example, you could add to the fsm:

struct internal_transition_table : mpl::vector<

Internal < internal_event , internal_fct,internal_guard >

> {};

This will cost you 1 transition / event, so in your case, much less compile-time.

Except, that I just tried before I send this and it works on submachines but not on the outer state machine :(

I will check this asap, but in the meantime, we will move to plan B. Define a second region in your fsm, with only one dummy state, then add for every event you want to process independently of your "regular" states a transition in the fsm from this dummy state to itself (or give this state an internal transition table).

As every region gets a chance to process any event, you will get the same effect and the reduced compilation time.

In the meantime I'll check why the internal table does not behave like advertised.

>Thanks!

>Peter Gissel

HTH,

Christophe



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