feat: 实现状态机的基本功能 #2
32
fsm.h
32
fsm.h
@@ -3,8 +3,36 @@
|
||||
//
|
||||
#ifndef QF_FSM_FSM_H
|
||||
#define QF_FSM_FSM_H
|
||||
|
||||
struct qf_fsm
|
||||
#include <stdint.h>
|
||||
typedef enum
|
||||
{
|
||||
FSM_OK,
|
||||
FSM_FAIL
|
||||
} fsm_result_e;
|
||||
|
||||
typedef fsm_result_e (*fsm_cb)(void *userdata);
|
||||
typedef struct qf_fsm_state
|
||||
{
|
||||
uint16_t state;
|
||||
fsm_cb on_exit;
|
||||
fsm_cb on_entry;
|
||||
void *user_data;
|
||||
} fsm_state_t;
|
||||
typedef struct qf_fsm_transition
|
||||
{
|
||||
uint16_t state;
|
||||
uint16_t event;
|
||||
fsm_cb on_action;
|
||||
} fsm_transition_t;
|
||||
struct qf_fsm_event
|
||||
{
|
||||
uint16_t event;
|
||||
void *user_data;
|
||||
};
|
||||
typedef struct qf_fsm
|
||||
{
|
||||
uint16_t current_state;
|
||||
fsm_state_t *p_state_list;
|
||||
|
||||
} fsm_handle_t;
|
||||
#endif // QF_FSM_FSM_H
|
||||
|
||||
Reference in New Issue
Block a user