design_pattern_for_c
V 1.00
|
Implement of StateMachine library API, defined in state_machine.h. More...
#include <stdlib.h>
#include <stdarg.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/eventfd.h>
#include <unistd.h>
#include <errno.h>
#include "state_machine.h"
#include "dp_util.h"
Go to the source code of this file.
Data Structures | |
struct | state_manager_list_data_t |
information of StateMachine, to use as list More... | |
struct | state_machine_msg_list_t |
information of state machine message list More... | |
struct | state_machine_t |
StateMachine class member definition. More... | |
struct | state_machine_msg_t |
message definition for multi thread More... | |
Typedefs | |
typedef struct state_manager_list_data_t * | StateManagerListData |
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... | |
private API for StateMachine | |
static int | state_machine_add_new_states (StateMachine this, const state_event_info_t *event_info) |
Add new state. More... | |
static void | state_machine_free_states_normally (StateMachine this) |
free normally More... | |
StateManagerListData | state_machine_find_states (StateMachine this, int event) |
Find state. More... | |
static int | state_machine_initial_thread (StateMachine this) |
for multi thread, initialize More... | |
static void | state_machine_free_states_multithread (StateMachine this) |
for multi thread, free More... | |
static int | state_machine_call_event_normally (StateMachine this, int event, void *arg, int arglen, void(*response)(int result)) |
for single thread, call event More... | |
static int | state_machine_call_event_normal (StateMachine this, int event, void *arg) |
static int | state_machine_call_event_multithread (StateMachine this, int event, void *arg, int arglen, void(*response)(int result)) |
for multi thread, call event More... | |
static void | state_machine_thread_main (int socketfd, int eventflag, void *event_arg) |
for multi thread, thread main callback for threadpool More... | |
static int | state_machine_open_socket (StateMachine this) |
for multi thread, open socket More... | |
static void | state_machine_close_socket (StateMachine this) |
for multi thread, close socket More... | |
static int | state_machine_get_read (StateMachine this) |
for multi thread, get read sock More... | |
static int | state_machine_write (StateMachine this, state_machine_msg_t *msg) |
for multi thread, write More... | |
private API for state_manager_t | |
#define | SMACHINE_LOCK(this) DPUTIL_LOCK(&this->msglist.lock); |
#define | SMACHINE_UNLOCK DPUTIL_UNLOCK |
typedef struct state_machine_msg_t | state_machine_msg_t |
typedef struct state_machine_msg_t * | StateMachineMsg |
typedef struct state_machine_msg_list_t | state_machine_msg_list_t |
static StateManagerListData | state_machine_manager_list_new (const state_event_info_t *event_info) |
Add new state. More... | |
static void | state_machine_manager_list_free (StateManagerListData this) |
Implement of StateMachine library API, defined in state_machine.h.
Definition in file state_machine.c.
#define SMACHINE_LOCK | ( | this | ) | DPUTIL_LOCK(&this->msglist.lock); |
Definition at line 66 of file state_machine.c.
#define SMACHINE_UNLOCK DPUTIL_UNLOCK |
Definition at line 67 of file state_machine.c.
typedef struct state_machine_msg_list_t state_machine_msg_list_t |
Definition at line 48 of file state_machine.c.
typedef struct state_machine_msg_t state_machine_msg_t |
Definition at line 40 of file state_machine.c.
typedef struct state_machine_msg_t * StateMachineMsg |
Definition at line 40 of file state_machine.c.
typedef struct state_manager_list_data_t* StateManagerListData |
Definition at line 24 of file state_machine.c.
|
static |
Add new state.
Definition at line 147 of file state_machine.c.
int state_machine_call_event | ( | StateMachineInfo | this, |
int | event, | ||
void * | arg, | ||
int | arglen, | ||
void(*)(int result) | response | ||
) |
call event trigger
[in] | this | StateMachineInfo class instance returned at state_machine_new |
[in] | event | event id related to this function |
[in] | arg | event argument |
[in] | arglen | event argument len |
[in] | response | response callback method. If you set is_multithread=true , you must set this response callback, |
return_value | of method if you set by single thread mode |
STATE_MNG_SUCCESS | and result is in callback you set callback if you set by multi thread mode. |
Definition at line 413 of file state_machine.c.
|
static |
for multi thread, call event
Definition at line 227 of file state_machine.c.
|
inlinestatic |
Definition at line 217 of file state_machine.c.
|
static |
for single thread, call event
Definition at line 211 of file state_machine.c.
|
static |
for multi thread, close socket
Definition at line 291 of file state_machine.c.
StateManagerListData state_machine_find_states | ( | StateMachine | this, |
int | event | ||
) |
Find state.
Definition at line 169 of file state_machine.c.
void state_machine_free | ( | StateMachineInfo | this | ) |
free StateMachine class
[in] | this | StateMachine class instance returned at state_machine_new |
Definition at line 438 of file state_machine.c.
|
static |
for multi thread, free
Definition at line 199 of file state_machine.c.
|
static |
free normally
Definition at line 160 of file state_machine.c.
int state_machine_get_current_state | ( | StateMachineInfo | this | ) |
get state
[in] | this | StateMachineInfo class instance returned at state_machine_new |
Definition at line 402 of file state_machine.c.
|
inlinestatic |
for multi thread, get read sock
for multi thread, read
Definition at line 297 of file state_machine.c.
|
static |
for multi thread, initialize
Definition at line 181 of file state_machine.c.
|
static |
Definition at line 131 of file state_machine.c.
|
static |
Add new state.
Definition at line 113 of file state_machine.c.
StateMachineInfo state_machine_new | ( | size_t | event_num, |
const state_event_info_t * | event_infos, | ||
EventTPoolManager | threadpool | ||
) |
Create StateMachineInfo class.
[in] | event_num | event size |
[in] | event_infos | list of event state data |
[in] | threadpool | event threadpool instance by creating event_threadpool API if you want to use state machine in other threads |
!=NULL | this class handle |
NULL | error |
Definition at line 313 of file state_machine.c.
|
inlinestatic |
for multi thread, open socket
Definition at line 284 of file state_machine.c.
void state_machine_set_state | ( | StateMachineInfo | this, |
int | state | ||
) |
set state
[in] | this | StateMachineInfo class instance returned at state_machine_new |
[in] | state | update state, if there is no state in set list, state is changed to latest order. |
Definition at line 388 of file state_machine.c.
void state_machine_show | ( | StateMachineInfo | this | ) |
set state
[in] | this | StateMachine class instance returned at state_machine_new |
Definition at line 425 of file state_machine.c.
|
static |
for multi thread, thread main callback for threadpool
for multi thread, thread main
Definition at line 248 of file state_machine.c.
int state_machine_update_machine | ( | StateMachineInfo | this, |
const state_event_info_t * | event_info | ||
) |
update sate
[in] | this | StateMachineInfo class instance returned at state_machine_new |
[in] | event_info | update list of event state data. |
STATE_MNG_SUCCESS | success |
other | failed |
Definition at line 360 of file state_machine.c.
|
inlinestatic |
for multi thread, write
Definition at line 302 of file state_machine.c.