design_pattern_for_c  V 1.00
state_manager.h
Go to the documentation of this file.
1 
5 #ifndef STATE_MANAGER_
6 #define STATE_MANAGER_
7 
8 
9 #define STATE_MNG_SUCCESS (0)
10 #define STATE_MNG_FAILED (-1)
11 
15 typedef struct state_info_t {
16  int state;
17  char *name;
18  int (*state_method)(void *arg);
19 } state_info_t;
20 
24 #define STATE_MNG_SET_INFO_INIT(instate, fname) {.state=(instate), .name=#fname, .state_method = (fname)}
25 
28 #define STATE_MNG_SET_INFO(info, instate, fname) {(info).state=(instate); (info).name=#fname; (info).state_method = (fname) ; }
29 
33 struct state_manager_t;
35 typedef struct state_manager_t *StateManager;
36 
46 StateManager state_manager_new(size_t state_info_num, const state_info_t * state);
63 void state_manager_set_state(StateManager this, int state);
79 int state_manager_call(StateManager this, void *arg);
94 #endif
int(* state_method)(void *arg)
name, function name defined by macro.
Definition: state_manager.h:18
void state_manager_free(StateManager this)
free StateManager class
StateManager class member definition, detail is defined in C file.
Definition: state_manager.c:30
struct state_info_t state_info_t
void state_manager_set_state(StateManager this, int state)
set state
int state_manager_get_current_state(StateManager this)
get current state
int state_manager_update_method(StateManager this, const state_info_t *state)
update method related to state
Definition: state_manager.c:96
int state_manager_call(StateManager this, void *arg)
call state method
struct state_manager_t * StateManager
StateManager class definition, to management state.
Definition: state_manager.h:35
void state_manager_show(StateManager this)
show current state table
StateManager state_manager_new(size_t state_info_num, const state_info_t *state)
Create StateManager class.
Definition: state_manager.c:74
char * name
state value related function
Definition: state_manager.h:17
state method definition, to know detail, add parameter "name".
Definition: state_manager.h:15