Struct bl602_sdk::wifi::transition [−][src]
#[repr(C)]pub struct transition { pub eventType: c_int, pub condition: *mut c_void, pub guard: Option<unsafe extern "C" fn(condition: *mut c_void, event: *mut event) -> bool>, pub action: Option<unsafe extern "C" fn(currentStateData: *mut c_void, event: *mut event, newStateData: *mut c_void)>, pub nextState: *const state, }
Expand description
\brief 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’ \ref state::data “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 \ref state::entryAction “entry action” or \ref state::exitAction “exit action”. If there are no transitions for the current event, the state’s parent will be handed the event.
Examples
- An ungarded transition to a state with no action performed:
{ .eventType = Event_timeout, .condition = NULL, .guard = NULL, .action = NULL, .nextState = &mainMenuState, },
- A guarded transition executing an action
{ .eventType = Event_keyboard, .condition = NULL, .guard = &ensureNumericInput, .action = &addToBuffer, .nextState = &awaitingInputState, },
- A guarded transition using a condition
{ .eventType = Event_mouse, .condition = boxLimits, .guard = &coordinatesWithinLimits, },
By using \ref #condition “conditions” a more general guard function can be
used, operating on the supplied argument #condition. In this example,
coordinatesWithinLimits
checks whether the coordinates in the mouse event
are within the limits of the “box”.
\sa event \sa state
Fields
eventType: c_int
\brief The event that will trigger this transition.
condition: *mut c_void
\brief 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.
guard: Option<unsafe extern "C" fn(condition: *mut c_void, event: *mut event) -> bool>
\brief 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 \ref event::data “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.
\param condition event (data) to compare the incoming event against. \param event the event passed to the state machine.
\returns true if the event’s data fulfils the condition, otherwise false.
action: Option<unsafe extern "C" fn(currentStateData: *mut c_void, event: *mut event, newStateData: *mut c_void)>
\brief 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.
\param currentStateData the leaving state’s \ref state::data “data” \param event the event passed to the state machine. \param newStateData the new state’s (the \ref state::entryState “entryState” of any (chain of) parent states, not the parent state itself) \ref state::data “data”
nextState: *const state
\brief 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 \ref stateMachine::errorState “error state”.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
pub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
pub fn from(t: T) -> T
pub fn from(t: T) -> T
Performs the conversion.
pub fn into(self) -> U
pub fn into(self) -> U
Performs the conversion.