design_pattern_for_c
V 1.00
|
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"
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_t * | StateManagerStateInfo |
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... | |
Implement of State design petten library API, defined in state_manager.h, only care state_manager class.
Definition in file state_manager.c.
typedef struct state_manager_state_info_t* StateManagerStateInfo |
Definition at line 20 of file state_manager.c.
|
static |
Add new state.
Definition at line 46 of file state_manager.c.
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.
StateManagerStateInfo state_manager_find_state | ( | StateManager | this, |
int | state | ||
) |
Find state.
Definition at line 60 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.