The run function for each state handles incoming messages and follows a similar pattern:
- The incoming message is identified by its channel and message type.
- If the module should handle the message in its current state, any relevant actions are performed.
-
To enforce the run-to-completion model, control flow must end in one of three ways:
return SMF_EVENT_HANDLED;to end the message handling without transitioning to a new state.smf_set_state()followed directly byreturn SMF_EVENT_HANDLED;to end the message handling and trigger a state transition.return SMF_EVENT_PROPAGATE;to signal that the message was not handled in the current state.
Important
In SMF, the run function of the current state is executed first, and then the run function of the parent state is executed, unless the child state returns SMF_EVENT_HANDLED to indicate that the event has been handled. Run functions return SMF_EVENT_PROPAGATE to allow the event to propagate to parent states, or SMF_EVENT_HANDLED to stop propagation.