From dee86bd16eba1a6e80292da346964703bca3c134 Mon Sep 17 00:00:00 2001 From: Jerome Jutteau Date: Tue, 5 Mar 2013 19:48:42 +0100 Subject: digital/ai/src/fsm: new return system --- digital/ai/src/fsm/angfsm_generic.h | 54 ++++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 16 deletions(-) (limited to 'digital/ai/src/fsm/angfsm_generic.h') diff --git a/digital/ai/src/fsm/angfsm_generic.h b/digital/ai/src/fsm/angfsm_generic.h index 4e1c589f..f2840beb 100644 --- a/digital/ai/src/fsm/angfsm_generic.h +++ b/digital/ai/src/fsm/angfsm_generic.h @@ -1,6 +1,6 @@ /* AngFSM - Almost Non Generated Finite State Machine - Copyright 2011, 2012 Jerome Jutteau + Copyright 2011-2013 Jerome Jutteau This file is part of AngFSM. @@ -50,9 +50,7 @@ /** Disable dot generation. */ #define ANGFSM_GEN_DOT(fsm, output) -/** Disable state defining - * - * Define states of the fsm, can be called several times to add other states. */ +/** Disable state defining */ #define ANGFSM_STATES(states...) /** Disable event defining */ @@ -62,28 +60,52 @@ #define ANGFSM_START_WITH(starters...) #define ANGFSM_TRANS(state, event, output_branches...) \ - ANGFSM_PASTE3_EXPAND (angfsm_, ANGFSM_NAME,_branch_t) \ - ANGFSM_PASTE3_EXPAND (angfsm_, ANGFSM_NAME,_trans_func_##state##_##event) () + IFELSE_ARG1(void, ANGFSM_PASTE3_EXPAND (angfsm_, ANGFSM_NAME,_branch_t), output_branches) ANGFSM_PASTE3_EXPAND (angfsm_, ANGFSM_NAME,_trans_func_##state##_##event) () -#define ANGFSM_NEXT(state, event, branch...) \ - ANGFSM_PASTE3_EXPAND (angfsm_BRANCH_, ANGFSM_NAME,_##state##_##event##_##branch) +/** Transform an event in a numeric value. */ +#define ANGFSM_EVENT(event) (ANGFSM_PASTE3_EXPAND (angfsm_EVENT_,ANGFSM_NAME,_##event)) +#define ANGFSM_EVENT_F(fsm, event) angfsm_EVENT_##fsm##_##event -/** Transform an event in uint16_t. */ -#define ANGFSM_EVENT(fsm, event) angfsm_EVENT_##fsm##_##event +/** Transform a state in a numeric value. */ +#define ANGFSM_STATE(state) (ANGFSM_PASTE3_EXPAND (angfsm_STATE_,ANGFSM_NAME,_##state)) +#define ANGFSM_STATE_F(fsm, state) angfsm_STATE_##fsm##_##state -/** Handle event from uint16_t. */ +/** Transform a branch in a numeric value. */ +#define ANGFSM_BRANCH(branch) (ANGFSM_PASTE3_EXPAND (angfsm_BRANCH_,ANGFSM_NAME,_##branch)) +#define ANGFSM_BRANCH_F(fsm, branch) angfsm_BRANCH_##fsm##_##branch + +/** Handle event from numeric event. */ #define ANGFSM_HANDLE_VAR(fsm, event) angfsm_##fsm##_handle (event) -/* Can we handle event from uint16_t ? */ +/* Can we handle event from numeric event ? */ #define ANGFSM_CAN_HANDLE_VAR(fsm, event) angfsm_##fsm##_can_handle (event) /* Time out macros. */ #define ANGFSM_TRANS_TIMEOUT(state, timeout, output_branches...) \ ANGFSM_TRANS (state, state##_TIMEOUT, output_branches) -#define ANGFSM_NEXT_TIMEOUT(state, branch...) \ - ANGFSM_NEXT (state, state##_TIMEOUT, branch) - #define ANGFSM_HANDLE_TIMEOUT(fsm_name) angfsm_##fsm_name##_handle_timeout () -#endif \ No newline at end of file +/* Callback for transitions. */ +#define ANGFSM_TRANS_CALLBACK(cb) \ + ANGFSM_PASTE3_EXPAND (angfsm_, ANGFSM_NAME,_trans_callback) = cb; + +/* Get state string. + * This macro is disabled if strings has no been embedded. + */ +#define ANGFSM_STATE_STR(state) \ + ((char *) ANGFSM_PASTE3_EXPAND (angfsm_, ANGFSM_NAME,_get_state_str (state))) + +/* Get event string. + * This macro is disabled if strings has no been embedded. + */ +#define ANGFSM_EVENT_STR(event) \ + ((char *) ANGFSM_PASTE3_EXPAND (angfsm_, ANGFSM_NAME,_get_event_str (event))) + +/* Get branch string. + * This macro is disabled if strings has no been embedded. + */ +#define ANGFSM_BRANCH_STR(branch) \ + ((char *) ANGFSM_PASTE3_EXPAND (angfsm_, ANGFSM_NAME,_get_branch_str (branch))) + +#endif -- cgit v1.2.3