design_pattern_for_c  V 1.00
state_machine.h File Reference

This is API for Sate machine. More...

#include "state_manager.h"
#include "event_threadpool.h"
Include dependency graph for state_machine.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  state_event_info_t
 event ID and related state functions More...
 
struct  state_machine_info
 

Typedefs

typedef struct state_event_info_t state_event_info_t
 
typedef struct state_machine_tStateMachine
 StateMachine class definition. More...
 
typedef struct state_machine_info state_machine_info_t
 
typedef struct state_machine_infoStateMachineInfo
 

Functions

StateMachineInfo state_machine_new (size_t event_num, const state_event_info_t *event_infos, EventTPoolManager threadpool)
 Create StateMachineInfo class. More...
 
int state_machine_update_machine (StateMachineInfo this, const state_event_info_t *event_info)
 update sate More...
 
void state_machine_set_state (StateMachineInfo this, int state)
 set state More...
 
int state_machine_get_current_state (StateMachineInfo this)
 get state More...
 
int state_machine_call_event (StateMachineInfo this, int event, void *arg, int arglen, void(*response)(int result))
 call event trigger More...
 
void state_machine_show (StateMachineInfo this)
 set state More...
 
void state_machine_free (StateMachineInfo this)
 free StateMachine class More...
 

Detailed Description

This is API for Sate machine.

Definition in file state_machine.h.

Typedef Documentation

◆ state_event_info_t

◆ state_machine_info_t

◆ StateMachine

typedef struct state_machine_t* StateMachine

StateMachine class definition.

Definition at line 24 of file state_machine.h.

◆ StateMachineInfo

Function Documentation

◆ state_machine_call_event()

int state_machine_call_event ( StateMachineInfo  this,
int  event,
void *  arg,
int  arglen,
void(*)(int result)  response 
)

call event trigger

Parameters
[in]thisStateMachineInfo class instance returned at state_machine_new
[in]eventevent id related to this function
[in]argevent argument
[in]arglenevent argument len
[in]responseresponse callback method. If you set is_multithread=true , you must set this response callback,
Return values
return_valueof method if you set by single thread mode
STATE_MNG_SUCCESSand result is in callback you set callback if you set by multi thread mode.

Definition at line 413 of file state_machine.c.

◆ state_machine_free()

void state_machine_free ( StateMachineInfo  this)

free StateMachine class

Parameters
[in]thisStateMachine class instance returned at state_machine_new
Returns
none

Definition at line 438 of file state_machine.c.

Here is the caller graph for this function:

◆ state_machine_get_current_state()

int state_machine_get_current_state ( StateMachineInfo  this)

get state

Parameters
[in]thisStateMachineInfo class instance returned at state_machine_new
Returns
state

Definition at line 402 of file state_machine.c.

Here is the call graph for this function:

◆ state_machine_new()

StateMachineInfo state_machine_new ( size_t  event_num,
const state_event_info_t event_infos,
EventTPoolManager  threadpool 
)

Create StateMachineInfo class.

Parameters
[in]event_numevent size
[in]event_infoslist of event state data
[in]threadpoolevent threadpool instance by creating event_threadpool API if you want to use state machine in other threads
Return values
!=NULLthis class handle
NULLerror

Definition at line 313 of file state_machine.c.

Here is the call graph for this function:

◆ state_machine_set_state()

void state_machine_set_state ( StateMachineInfo  this,
int  state 
)

set state

Parameters
[in]thisStateMachineInfo class instance returned at state_machine_new
[in]stateupdate state, if there is no state in set list, state is changed to latest order.
Returns
none

Definition at line 388 of file state_machine.c.

Here is the call graph for this function:

◆ state_machine_show()

void state_machine_show ( StateMachineInfo  this)

set state

Parameters
[in]thisStateMachine class instance returned at state_machine_new
Returns
none

Definition at line 425 of file state_machine.c.

Here is the call graph for this function:

◆ state_machine_update_machine()

int state_machine_update_machine ( StateMachineInfo  this,
const state_event_info_t event_info 
)

update sate

Parameters
[in]thisStateMachineInfo class instance returned at state_machine_new
[in]event_infoupdate list of event state data.
Return values
STATE_MNG_SUCCESSsuccess
otherfailed

Definition at line 360 of file state_machine.c.

Here is the call graph for this function: