StateMachine* stateMachine = allocStateMachine("MyStateMachine", "[Pref]"); State * S_1, *S_2, *MS_3, *S_3_1, *S_3_2; allocateSpaceForStates(stateMachine, 3, stateMachine); S_1 = allocateState(stateMachine, "FirstState", stateMachine); S_2 = allocateState(stateMachine, "SecondState", stateMachine); MS_3 = allocateState(stateMachine, "ThirdState", stateMachine); allocateSpaceForStates(MS_3, 2); S_3_1 = allocateState(MS_3, "FirstSubState", stateMachine); S_3_2 = allocateState(MS_3, "SecondSubState", stateMachine); freeStateMachine(stateMachine);
For exemple this code:
#include "StateMachine.h" int main(int argc, char** argv) { StateMachine* stateMachine = allocStateMachine("MyStateMachine", "[Pref]"); State * S_1, *S_2, *MS_3, *S_3_1, *S_3_2; setDbgParam(stateMachine, REALLOC_DBG); allocateSpaceForStates(stateMachine, 3); S_1 = allocateState(stateMachine, "FirstState", stateMachine); S_2 = allocateState(stateMachine, "SecondState", stateMachine); MS_3 = allocateState(stateMachine, "ThirdState", stateMachine); allocateSpaceForStates(MS_3, 2); S_3_1 = allocateState(MS_3, "FirstSubState", stateMachine); S_3_2 = allocateState(MS_3, "SecondSubState", stateMachine); freeStateMachine(stateMachine); }
[Pref] Reallocating space for state machine MyStateMachine from 0 to 3 [Pref] In state machine MyStateMachine, reallocating space for state ThirdState from 0 to 2
allocateSpaceForStates(stateMachine, 3);
allocateSpaceForStates(stateMachine, 2);
[Pref] Reallocating space for state machine MyStateMachine from 0 to 2 [Pref] Reallocating space for state machine MyStateMachine from 2 to 12 [Pref] In state machine MyStateMachine, reallocating space for state ThirdState from 0 to 2
In this section we will consider the following simple state machine:
State Machine 4
StateMachine* stateMachine; State* MS_1, *MS1_1, *S1_2, *S11_1, *S11_2, *S2; stateMachine = allocStateMachine("myOptimizedStateMachine", "[OSM]"); setDbgParam(stateMachine, REALLOC_DBG); MS_1 = allocateState(stateMachine, "MS_1", stateMachine); S2 = allocateState(stateMachine, "S2", stateMachine); MS1_1 = allocateState(MS_1, "MS1_1", stateMachine); S1_2 = allocateState(MS_1, "S1_2", stateMachine); S11_1 = allocateState(MS1_1, "S11_1", stateMachine); S11_2 = allocateState(MS1_1, "S11_2", stateMachine); addTransition(MS1_1, S11_2, 4, 0); addTransition(S11_1, MS1_1, 3, 0); addTransition(MS1_1, S2, 2, 0); addTransition(S11_1, S1_2, 1, 0); addTransition(S11_2, S1_2, 1, 0); addTransition(S1_2, MS_1, 1, 0); addTransition(S2, MS_1, 1, 0);
[OSM] Reallocating space for state machine myOptimizedStateMachine from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for state MS_1 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for state MS1_1 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state MS1_1 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state MS1_1 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_1 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_2 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_1 from 10 to 20 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S11_1 from 0 to 10 [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state MS1_1, system have to relocate transitions to insert the newly allocated one. [OSM] In State machine myOptimizedStateMachine, for state MS1_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_2, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate transitions to insert the newly allocated one. [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_2 from 10 to 20 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S11_2 from 0 to 10 [OSM] In State machine myOptimizedStateMachine, for state S11_2, system have to relocate secondary transitions to insert the new one. [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S1_2 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S1_2 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S2 from 0 to 10 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S2 from 0 to 10
StateMachine* stateMachine; State* MS_1, *MS1_1, *S1_2, *S11_1, *S11_2, *S2; stateMachine = allocStateMachine("myOptimizedStateMachine", "[OSM]"); setDbgParam(stateMachine, REALLOC_DBG); allocateSpaceForStates(stateMachine, 2); //<<<<<<<Added line MS_1 = allocateState(stateMachine, "MS_1", stateMachine); S2 = allocateState(stateMachine, "S2", stateMachine); allocateSpaceForStates(MS_1, 2); //<<<<<<<Added line MS1_1 = allocateState(MS_1, "MS1_1", stateMachine); S1_2 = allocateState(MS_1, "S1_2", stateMachine); allocateSpaceForStates(MS1_1, 2); //<<<<<<<Added line S11_1 = allocateState(MS1_1, "S11_1", stateMachine); S11_2 = allocateState(MS1_1, "S11_2", stateMachine); addTransition(MS1_1, S11_2, 4, 0); addTransition(S11_1, MS1_1, 3, 0); addTransition(MS1_1, S2, 2, 0); addTransition(S11_1, S1_2, 1, 0); addTransition(S11_2, S1_2, 1, 0); addTransition(S1_2, MS_1, 1, 0); addTransition(S2, MS_1, 1, 0);
[OSM] In state machine myOptimizedStateMachine, reallocating space for state MS_1 from 0 to 10
[OSM] In state machine myOptimizedStateMachine, reallocating space for state MS_1 from 0 to 2
StateMachine* stateMachine; State* MS_1, *MS1_1, *S1_2, *S11_1, *S11_2, *S2; stateMachine = allocStateMachine("myOptimizedStateMachine", "[OSM]"); setDbgParam(stateMachine, REALLOC_DBG); allocateSpaceForStates(stateMachine, 2); MS_1 = allocateState(stateMachine, "MS_1", stateMachine); S2 = allocateState(stateMachine, "S2", stateMachine); allocateSpaceForStates(MS_1, 2); MS1_1 = allocateState(MS_1, "MS1_1", stateMachine); S1_2 = allocateState(MS_1, "S1_2", stateMachine); allocateSpaceForStates(MS1_1, 2); S11_1 = allocateState(MS1_1, "S11_1", stateMachine); S11_2 = allocateState(MS1_1, "S11_2", stateMachine); allocateSpaceForTransitions(S11_1, 2); //<<<<<<<Added line allocateSpaceForTransitions(S11_2, 1); //<<<<<<<Added line allocateSpaceForTransitions(S1_2, 1); //<<<<<<<Added line allocateSpaceForTransitions(S2, 1); //<<<<<<<Added line allocateSpaceForTransitions(MS1_1, 2); //<<<<<<<Added line addTransition(MS1_1, S11_2, 4, 0); addTransition(S11_1, MS1_1, 3, 0); addTransition(MS1_1, S2, 2, 0); addTransition(S11_1, S1_2, 1, 0); addTransition(S11_2, S1_2, 1, 0); addTransition(S1_2, MS_1, 1, 0); addTransition(S2, MS_1, 1, 0);
[OSM] Reallocating space for state machine myOptimizedStateMachine from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for state MS_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for state MS1_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S11_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S11_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S1_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S1_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state MS1_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state MS1_1 from 0 to 2 [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state MS1_1, system have to relocate transitions to insert the newly allocated one. [OSM] In State machine myOptimizedStateMachine, for state MS1_1, system have to relocate secondary transitions to insert the new one. [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_1 from 2 to 12 [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_2 from 1 to 11 [OSM] In State machine myOptimizedStateMachine, for state S11_2, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate transitions to insert the newly allocated one. [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_2, system have to relocate secondary transitions to insert the new one.
Simply allocate the space for transition starting with highest level states (states with minimum depth).
So we had this:
allocateSpaceForTransitions(S11_1, 2); allocateSpaceForTransitions(S11_2, 1); allocateSpaceForTransitions(S1_2, 1); allocateSpaceForTransitions(S2, 1); allocateSpaceForTransitions(MS1_1, 2);
allocateSpaceForTransitions(MS1_1, 2); allocateSpaceForTransitions(S2, 1); allocateSpaceForTransitions(S1_2, 1); allocateSpaceForTransitions(S11_2, 1); allocateSpaceForTransitions(S11_1, 2);
[OSM] Reallocating space for state machine myOptimizedStateMachine from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for state MS_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for state MS1_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state MS1_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state MS1_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S1_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S1_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_2 from 0 to 3 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S11_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_1 from 0 to 4 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S11_1 from 0 to 2 [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state MS1_1, system have to relocate transitions to insert the newly allocated one. [OSM] In State machine myOptimizedStateMachine, for state MS1_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_2, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate transitions to insert the newly allocated one. [OSM] In State machine myOptimizedStateMachine, for state S11_1, system have to relocate secondary transitions to insert the new one. [OSM] In State machine myOptimizedStateMachine, for state S11_2, system have to relocate secondary transitions to insert the new one.
addTransition(S11_1, S1_2, 1, 0); //Event #1 first addTransition(S11_2, S1_2, 1, 0); addTransition(S1_2, MS_1, 1, 0); addTransition(S2, MS_1, 1, 0); addTransition(MS1_1, S2, 2, 0); //Then event #2 addTransition(S11_1, MS1_1, 3, 0); //Event #3 addTransition(MS1_1, S11_2, 4, 0); //And finally event #4
[OSM] Reallocating space for state machine myOptimizedStateMachine from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for state MS_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for state MS1_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state MS1_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state MS1_1 from 0 to 2 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S1_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S1_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_2 from 0 to 3 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S11_2 from 0 to 1 [OSM] In state machine myOptimizedStateMachine, reallocating space for global transitions for state S11_1 from 0 to 4 [OSM] In state machine myOptimizedStateMachine, reallocating space for transitions for state S11_1 from 0 to 2
StateMachine* stateMachine; State* MS_1, *MS1_1, *S1_2, *S11_1, *S11_2, *S2; stateMachine = allocStateMachine("myOptimizedStateMachine", "[OSM]"); setDbgParam(stateMachine, REALLOC_DBG); allocateSpaceForStates(stateMachine, 2); MS_1 = allocateState(stateMachine, "MS_1", stateMachine); S2 = allocateState(stateMachine, "S2", stateMachine); allocateSpaceForStates(MS_1, 2); MS1_1 = allocateState(MS_1, "MS1_1", stateMachine); S1_2 = allocateState(MS_1, "S1_2", stateMachine); allocateSpaceForStates(MS1_1, 2); S11_1 = allocateState(MS1_1, "S11_1", stateMachine); S11_2 = allocateState(MS1_1, "S11_2", stateMachine); allocateSpaceForTransitions(MS1_1, 2); allocateSpaceForTransitions(S2, 1); allocateSpaceForTransitions(S1_2, 1); allocateSpaceForTransitions(S11_2, 1); allocateSpaceForTransitions(S11_1, 2); addTransition(S11_1, S1_2, 1, 0); addTransition(S11_2, S1_2, 1, 0); addTransition(S1_2, MS_1, 1, 0); addTransition(S2, MS_1, 1, 0); addTransition(MS1_1, S2, 2, 0); addTransition(S11_1, MS1_1, 3, 0); addTransition(MS1_1, S11_2, 4, 0);
Next: How to build the library.
Previous: How to put the debug system in good use.