<code>#include <hierarchical_state_machine.h></code>
collaboration diagram for hierarchical_state_machine:
[legend]
list of all members.
this is an example of state machine implementation using hierarchical state machines.
for details refer to the article on
hierarchical state machines
in conventional state machine design, all states are considered at the same level. the design does not capture the commonality that exists among states. in real life, many states handle most messages in similar fashion and differ only in handling of few
key messages. even when the actual handling differs, there is still some commonality. hierarchical state machine design captures the commonality by organizing the states as a hierarchy. the states at the higher level in hierarchy perform the common message
handling, while the lower level states inherit the commonality from higher level ones and perform the state specific functions. this examples explores hierarchichal state machines using an example of a hardware unit that can be in the following states:
inservice state
active state
standby state
out_of_service
suspect state
failed state
definition at line
32 of file
hierarchical_state_machine.h.
void
on_message (const message *p_message)
receive methods and invoke the handler for the currently active state.
next_state (unit_state
&r_state)
this private method changes the state for the state machine.
unit_state *
p_current_state
pointer to the current state.
active
active_state
static declaration of
active state. static declarations share the same states across multiple instances.
standby
standby_state
standby state.
suspect
suspect_state
suspect state.
failed
failed_state
failed state.
void hierarchical_state_machine::next_state
(
unit_state &
r_state
)
<code>[private]</code>
the p_current_state variable is updated with the new state
<dl>
<dt>
parameters: </dt>
<dd>
r_state
reference to the desired next state
</dd>
</dl>
169 of file
void hierarchical_state_machine::on_message
const message *
p_message
note that p_current_state has already been set to the current state.
p_message
pointer to the message being processed.
17 of file
hierarchical_state_machine.cpp.