Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling the entry/exit action when transitioning to/from group state #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/stateMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,40 @@ int stateM_handleEvent( struct stateMachine *fsm,
while ( nextState->entryState )
nextState = nextState->entryState;

/* Run exit action only if the current state is left (only if it does
/* Run exit actions only if the current state is left (only if it does
* not return to itself): */
if ( nextState != fsm->currentState && fsm->currentState->exitAction )
fsm->currentState->exitAction( fsm->currentState->data, event );
if(nextState != fsm->currentState)
{
if ( fsm->currentState->exitAction )
fsm->currentState->exitAction( fsm->currentState->data, event );

/* Call the current state's parent state exit action if it has one
* and if new parent state is different than the current states parent
* state */
if ( fsm->currentState->parentState && fsm->currentState->parentState->entryAction &&
(nextState->parentState != fsm->currentState->parentState) )
fsm->currentState->parentState->exitAction( fsm->currentState->parentState->data, event );
}

/* Run transition action (if any): */
if ( transition->action )
transition->action( fsm->currentState->data, event, nextState->
data );

/* Call the new state's entry action if it has any (only if state does
/* Call the new state's entry actions if it has any (only if state does
* not return to itself): */
if ( nextState != fsm->currentState && nextState->entryAction )
nextState->entryAction( nextState->data, event );
if(nextState != fsm->currentState)
{
/* Call the new state's parent state entry action if it has one
* and if its parent state is different than the current states parent
* state */
if ( nextState->parentState && nextState->parentState->entryAction &&
(nextState->parentState != fsm->currentState->parentState) )
nextState->parentState->entryAction( nextState->parentState->data, event );

if ( nextState->entryAction )
nextState->entryAction( nextState->data, event );
}

fsm->previousState = fsm->currentState;
fsm->currentState = nextState;
Expand Down