|
State Library
|
state library api More...
Go to the source code of this file.
Typedefs | |
| typedef int(* | StateFunc )(void *data) |
| Default type for a state function. | |
Functions | |
| struct StateMachine * | state_newmachine () |
| state_newmachine instanciate a new empty machine More... | |
| void | state_free (struct StateMachine *p) |
| state_free release resource of a machine allocated with state_newmachine More... | |
| int | state_add_transition (struct StateMachine *machine, StateFunc from, int value, StateFunc to) |
| state_add_transition Add a new transition into the machine More... | |
| int | state_start (struct StateMachine *machine, StateFunc start, void *data) |
| state_start run a state machine More... | |
state library api
The state library is really simple. First you must create a machine using the state_newmachine function. This will return an handler to an empty machine. Then you can register any state and transition using state_add_transition function. A state is a pointer to a function, transition are associated to int. State return value are used to select the next state function that will be run. Finally, you can start your machine by giving the initial state function and a pointer that will be passed to all state function. At last, release the resources associated to the machine using state_free.
state_add_transition Add a new transition into the machine
| machine | a pointer obtained with state_newmachine |
| from | the current machine state |
| value | the value return by from |
| to | the state run after from, NULL if the machine must exit |
| void state_free | ( | struct StateMachine * | p | ) |
state_free release resource of a machine allocated with state_newmachine
| p | a pointer returned by state_newmachine |
| struct StateMachine* state_newmachine | ( | ) |
state_newmachine instanciate a new empty machine
| int state_start | ( | struct StateMachine * | machine, |
| StateFunc | start, | ||
| void * | data | ||
| ) |
state_start run a state machine
| machine | a pointer to the state machine |
| start | the first state that will be run |
| data | a pointer that will be passed to all states |