Boost logo

Boost Users :

From: Tim Milward (tim.milward_at_[hidden])
Date: 2006-05-08 09:39:05

Johan Nilsson wrote:
> 1. For a state, is it possible to specify a method that will be called when
> an event with no defined handlers is received?

Interesting question. Can all events inherit from a common base class,
to which a state could define a (default) reaction, and override this
with reactions to specific event sub-classes?

> 2. Is is somehow possible to reuse state definitions as substates of
> different "higher-level" states?

In boost/libs/statechart/doc/tutorial.html#TransitionActions it says,
"With Boost.Statechart, a transition action can be a member of any
common outer context" and goes on to give some examples. If I've
understood your question correctly then the answer is "Yes".

> - I've got an application that can be either in remote or locally controlled
> mode (this is the highest-level states).
> - Certain events are allowed both in remote and local, while some are not.
> As an example, the "CommandEvent" event should be handled both in remote and
> local - resulting in the "ExecutingCommandState" being entered.
> - I'd like to be able to reuse the definition of ExecutingCommandState
> regardless of the enclosing state being Remote or Local - Possible?

Could you implement this with orthogonal regions?


Here the top state contains two orthogonal regions separated by a dashed
line. The only problem here is that actions (in transitions from say
Idle) that need to be different depending on whether it's in Remote or
Local gain conditional logic. (If that's all Remote and Local are used
for they could just be replaced by a bool member of Top.) If you had


you'd avoid this, at the expense of possibly repeating code in the (only
slightly different) actions of a transition originating from either
RIdle or LIdle. This common code could perhaps be extracted into a
method belonging to the shared super-state, Top.

This sounds like a similar problem to the one I face. Where are you
planning to execute the command? In my application the commands take a
long time, so are not suitable for implementing as an action. UML
provides "Do Activities" that can be used for this purpose. The
statechart docs suggest simulating this "with a separate thread that is
started in the entry action and canceled (!) in the exit action of a
particular state". I quite like that approach.

Tim Milward

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