design_pattern_for_c
V 1.00
|
This is API for Sate design pattern. More...
Go to the source code of this file.
Data Structures | |
struct | state_info_t |
state method definition, to know detail, add parameter "name". More... | |
Macros | |
#define | STATE_MNG_SUCCESS (0) |
#define | STATE_MNG_FAILED (-1) |
#define | STATE_MNG_SET_INFO_INIT(instate, fname) {.state=(instate), .name=#fname, .state_method = (fname)} |
Macro to initialize state_info_t. More... | |
#define | STATE_MNG_SET_INFO(info, instate, fname) {(info).state=(instate); (info).name=#fname; (info).state_method = (fname) ; } |
Macro to initialize state_info_t after define state_info_t. More... | |
Typedefs | |
typedef struct state_info_t | state_info_t |
typedef struct state_manager_t * | StateManager |
StateManager class definition, to management state. More... | |
Functions | |
StateManager | state_manager_new (size_t state_info_num, const state_info_t *state) |
Create StateManager class. More... | |
int | state_manager_update_method (StateManager this, const state_info_t *state) |
update method related to state More... | |
void | state_manager_set_state (StateManager this, int state) |
set state More... | |
int | state_manager_get_current_state (StateManager this) |
get current state More... | |
int | state_manager_call (StateManager this, void *arg) |
call state method More... | |
void | state_manager_show (StateManager this) |
show current state table More... | |
void | state_manager_free (StateManager this) |
free StateManager class More... | |
This is API for Sate design pattern.
Definition in file state_manager.h.
#define STATE_MNG_FAILED (-1) |
Definition at line 10 of file state_manager.h.
#define STATE_MNG_SET_INFO | ( | info, | |
instate, | |||
fname | |||
) | {(info).state=(instate); (info).name=#fname; (info).state_method = (fname) ; } |
Macro to initialize state_info_t after define state_info_t.
Please use this macro, It set function name of method, so it support to know definition relationsip of state and function.
Definition at line 28 of file state_manager.h.
#define STATE_MNG_SET_INFO_INIT | ( | instate, | |
fname | |||
) | {.state=(instate), .name=#fname, .state_method = (fname)} |
Macro to initialize state_info_t.
Please use this macro, It set function name of method, so it support to know definition relationsip of state and function.
Definition at line 24 of file state_manager.h.
#define STATE_MNG_SUCCESS (0) |
Definition at line 9 of file state_manager.h.
typedef struct state_info_t state_info_t |
typedef struct state_manager_t* StateManager |
StateManager class definition, to management state.
Definition at line 35 of file state_manager.h.
int state_manager_call | ( | StateManager | this, |
void * | arg | ||
) |
call state method
[in] | this | StateManager instance returned at state_manager_new, |
[in] | arg | argument vakue |
STATE_MNG_FAILED | failed |
other | return value of state_method |
Definition at line 129 of file state_manager.c.
void state_manager_free | ( | StateManager | this | ) |
free StateManager class
[in] | this | StateManager instance returned at state_manager_new, |
Definition at line 165 of file state_manager.c.
int state_manager_get_current_state | ( | StateManager | this | ) |
get current state
[in] | this | StateManager instance returned at state_manager_new, |
Definition at line 118 of file state_manager.c.
StateManager state_manager_new | ( | size_t | state_info_num, |
const state_info_t * | state | ||
) |
Create StateManager class.
[in] | state_info_num | num of state_info_t, we can set list of state af this API |
[in] | state | state_info pinters, please define state_info_t's in some function, and set this pointer in here. this library change state method by state_manager_set_state, and call method when using state_manager_call |
!=NULL | this class handle |
NULL | error |
Definition at line 74 of file state_manager.c.
void state_manager_set_state | ( | StateManager | this, |
int | state | ||
) |
set state
[in] | this | StateManager instance returned at state_manager_new, |
[in] | state | state, if there is no state in set list, state is changed to latest order. |
Definition at line 111 of file state_manager.c.
void state_manager_show | ( | StateManager | this | ) |
show current state table
[in] | this | StateManager instance returned at state_manager_new, |
Definition at line 144 of file state_manager.c.
int state_manager_update_method | ( | StateManager | this, |
const state_info_t * | state | ||
) |
update method related to state
[in] | this | StateManager instance returned at state_manager_new, |
[in] | state | info of state. If there is no state, it is add to state list |
STATE_MNG_SUCCESS | success |
other | failed to add |
Definition at line 96 of file state_manager.c.