Boost logo

Boost Users :

From: Andreas Huber (ahd6974-spamgroupstrap_at_[hidden])
Date: 2006-01-21 08:19:42

Oliver.Kowalke_at_[hidden] wrote:
> Hello,
> I try to understand how boost::statechart work - so I have some
> questions.
> If the FSM implements a communication protocol how does the FSM
> interact with the environment?
> 1. Problem: How to passing callback-functions to the FSM?
> * The callback should be invoked if the FSM is in a certain state
> and some conditions are met.
> * Do I have to pass the callback(s) with an event

That's the usual and often the best way, because this ensures that your
FSM can transparently interact with different callers (i.e. senders of
events). Another, less frequently used option is to pass the callback(s)
to the constructor of the FSM.

> which has to be
> injected to the FSM from outside

With "injected" I assume you mean that the callback is a member of the

> and store them in a given state?

Right, if you cannot call the callback immediately (e.g. because you
have to wait for an event from a different sender before calling the
callback) you usually store it in a state or the FSM object itself.

> 2. Problem: How to pass initialization parameter into the FSM?
> * Some states need to be initialized with parameters (for instance
> host and port in order to create a socket).
> * Do I Have to pass the parameters via injected events?

That's one way. Again, another is to pass those parameters to the FSM

> 3. Problem: How to pass data between several states in an FSM?
> * Same as Problem 2?

Data that must be shared between multiple states is usually put into a
common outer state or the FSM object itself. For example, see the
StopWatch example where the elapsedTime_ member inside the Active state
is available to both the Stopped and Running states.

HTH & Regards,

Andreas Huber
When replying by private email, please remove the words spam and trap
from the address shown in the header. 

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at