design_pattern_for_c  V 1.00
state_manager.c File Reference

Implement of State design petten library API, defined in state_manager.h, only care state_manager class. More...

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "state_manager.h"
#include "dp_util.h"
Include dependency graph for state_manager.c:

Go to the source code of this file.

Data Structures

struct  state_manager_state_info_t
 state info definition. More...
 
struct  state_manager_t
 StateManager class member definition, detail is defined in C file. More...
 

Typedefs

typedef struct state_manager_state_info_tStateManagerStateInfo
 

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...
 
private API for state_manager_t
static int state_manager_add_new_state (StateManager this, const state_info_t *state)
 Add new state. More...
 
StateManagerStateInfo state_manager_find_state (StateManager this, int state)
 Find state. More...
 

Detailed Description

Implement of State design petten library API, defined in state_manager.h, only care state_manager class.

Definition in file state_manager.c.

Typedef Documentation

◆ StateManagerStateInfo

Definition at line 20 of file state_manager.c.

Function Documentation

◆ state_manager_add_new_state()

static int state_manager_add_new_state ( StateManager  this,
const state_info_t state 
)
static

Add new state.

Definition at line 46 of file state_manager.c.

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

◆ 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_find_state()

StateManagerStateInfo state_manager_find_state ( StateManager  this,
int  state 
)

Find state.

Definition at line 60 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: