Skip to content
Open
Show file tree
Hide file tree
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
20 changes: 17 additions & 3 deletions Fsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ Fsm::Transition Fsm::create_transition(State* state_from, State* state_to,
return t;
}

void Fsm::trigger(int event)
/* param immidiate = true will make state change while calling this function
param immediate=false will schedule state chage for next run_machine call
default is immidiate=true for backwards compability
*/
void Fsm::trigger(int event, bool immidiate)
{
if (m_initialized)
{
Expand All @@ -101,7 +105,12 @@ void Fsm::trigger(int event)
if (m_transitions[i].state_from == m_current_state &&
m_transitions[i].event == event)
{
Fsm::make_transition(&(m_transitions[i]));
if(immidiate){
Fsm::make_transition(&(m_transitions[i]));
}else{
// queue state cha
Fsm::m_synchronous_transition = &(m_transitions[i]);
}
return;
}
}
Expand Down Expand Up @@ -143,7 +152,12 @@ void Fsm::run_machine()

if (m_current_state->on_state != NULL)
m_current_state->on_state();


if(Fsm::m_synchronous_transition != NULL){
Fsm::make_transition(m_synchronous_transition);
m_synchronous_transition = NULL;
}

Fsm::check_timed_transitions();
}

Expand Down
3 changes: 2 additions & 1 deletion Fsm.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Fsm

void check_timed_transitions();

void trigger(int event);
void trigger(int event, bool immidiate=true);
void run_machine();

private:
Expand All @@ -73,6 +73,7 @@ class Fsm

private:
State* m_current_state;
Transition* m_synchronous_transition;
Transition* m_transitions;
int m_num_transitions;

Expand Down