State machine
 All Classes Files Functions Variables Enumerations Enumerator Groups
Public Attributes | List of all members
transition Struct Reference

Transition between a state and another state. More...

#include <stateMachine.h>

Public Attributes

int eventType
 The event that will trigger this transition.
void * condition
 Condition that event must fulfil.
bool(* guard )(void *condition, struct event *event)
 Check if data passed with event fulfils a condition.
void(* action )(void *currentStateData, struct event *event, void *newStateData)
 Function containing tasks to be performed during the transition.
struct statenextState
 The next state.

Detailed Description

Transition between a state and another state.

All states that are not final must have at least one transition. The transition may be guarded or not. Transitions are triggered by events. If a state has more than one transition with the same type of event (and the same condition), the first transition in the array will be run. An unconditional transition placed last in the transition array of a state can act as a "catch-all". A transition may optionally run an action, which will have the triggering event passed to it as an argument, along with the current and new states' data.

It is perfectly valid for a transition to return to the state it belongs to. Such a transition will not call the state's entry action or exit action. If there are no transitions for the current event, the state's parent will be handed the event.

Examples

See Also
event
state
Examples:
nestedTest.c, and stateMachineExample.c.

Member Data Documentation

void( * transition::action)(void *currentStateData, struct event *event, void *newStateData)

Function containing tasks to be performed during the transition.

The transition may optionally do some work in this function before entering the next state. May be NULL.

Parameters
currentStateDatathe leaving state's data
eventthe event passed to the state machine.
newStateDatathe new state's (the entryState of any (chain of) parent states, not the parent state itself) data
void* transition::condition

Condition that event must fulfil.

This variable will be passed to the guard (if guard is non-NULL) and may be used as a condition that the incoming event's data must fulfil in order for the transition to be performed. By using this variable, the number of guard functions can be minimised by making them more general.

bool( * transition::guard)(void *condition, struct event *event)

Check if data passed with event fulfils a condition.

A transition may be conditional. If so, this function, if non-NULL, will be called. Its first argument will be supplied with condition, which can be compared against the payload in the event. The user may choose to use this argument or not. Only if the result is true, the transition will take place.

Parameters
conditionevent (data) to compare the incoming event against.
eventthe event passed to the state machine.
Returns
true if the event's data fulfils the condition, otherwise false.
Examples:
nestedTest.c.
struct state* transition::nextState

The next state.

This must point to the next state that will be entered. It cannot be NULL. If it is, the state machine will detect it and enter the error state.


The documentation for this struct was generated from the following file: