design_pattern_for_c  V 1.00
state_manager.h File Reference

This is API for Sate design pattern. More...

This graph shows which files directly or indirectly include this file:

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_tStateManager
 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...
 

Detailed Description

This is API for Sate design pattern.

Definition in file state_manager.h.

Macro Definition Documentation

◆ STATE_MNG_FAILED

#define STATE_MNG_FAILED   (-1)

Definition at line 10 of file state_manager.h.

◆ STATE_MNG_SET_INFO

#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.

◆ STATE_MNG_SET_INFO_INIT

#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.

◆ STATE_MNG_SUCCESS

#define STATE_MNG_SUCCESS   (0)

Definition at line 9 of file state_manager.h.

Typedef Documentation

◆ state_info_t

typedef struct state_info_t state_info_t

◆ StateManager

typedef struct state_manager_t* StateManager

StateManager class definition, to management state.

Definition at line 35 of file state_manager.h.

Function Documentation

◆ state_manager_call()

int state_manager_call ( StateManager  this,
void *  arg 
)

call state method

Parameters
[in]thisStateManager instance returned at state_manager_new,
[in]argargument vakue
Return values
STATE_MNG_FAILEDfailed
otherreturn value of state_method

Definition at line 129 of file state_manager.c.

Here is the caller graph for this function:

◆ state_manager_free()

void state_manager_free ( StateManager  this)

free StateManager class

Parameters
[in]thisStateManager instance returned at state_manager_new,
Returns
none

Definition at line 165 of file state_manager.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ state_manager_get_current_state()

int state_manager_get_current_state ( StateManager  this)

get current state

Parameters
[in]thisStateManager instance returned at state_manager_new,
Returns
state value or STATE_MNG_FAILED if you don't set state

Definition at line 118 of file state_manager.c.

Here is the caller graph for this function:

◆ state_manager_new()

StateManager state_manager_new ( size_t  state_info_num,
const state_info_t state 
)

Create StateManager class.

Parameters
[in]state_info_numnum of state_info_t, we can set list of state af this API
[in]statestate_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
Return values
!=NULLthis class handle
NULLerror

Definition at line 74 of file state_manager.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ state_manager_set_state()

void state_manager_set_state ( StateManager  this,
int  state 
)

set state

Parameters
[in]thisStateManager instance returned at state_manager_new,
[in]statestate, if there is no state in set list, state is changed to latest order.
Returns
none

Definition at line 111 of file state_manager.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ state_manager_show()

void state_manager_show ( StateManager  this)

show current state table

Parameters
[in]thisStateManager instance returned at state_manager_new,
Returns
none

Definition at line 144 of file state_manager.c.

Here is the caller graph for this function:

◆ state_manager_update_method()

int state_manager_update_method ( StateManager  this,
const state_info_t state 
)

update method related to state

Parameters
[in]thisStateManager instance returned at state_manager_new,
[in]stateinfo of state. If there is no state, it is add to state list
Return values
STATE_MNG_SUCCESSsuccess
otherfailed to add

Definition at line 96 of file state_manager.c.

Here is the call graph for this function: