summaryrefslogtreecommitdiff
path: root/cesar/cp2/fsm
diff options
context:
space:
mode:
authorschodet2008-07-11 08:14:08 +0000
committerschodet2008-07-11 08:14:08 +0000
commitcf7441d2e88e7e41783510fa1428e5a279d6d58d (patch)
tree9a050791e2bb37a2d37d8e71fd39355b46db1e09 /cesar/cp2/fsm
parent69b781dbbf9ccdea6687d42323af1345718c7b6b (diff)
* cp2/fsm:
- added transition without action support. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@2596 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/cp2/fsm')
-rw-r--r--cesar/cp2/fsm/src/fsm.c13
-rw-r--r--cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm2
-rw-r--r--cesar/cp2/fsm/test/utest/src/test_fsm.c22
3 files changed, 37 insertions, 0 deletions
diff --git a/cesar/cp2/fsm/src/fsm.c b/cesar/cp2/fsm/src/fsm.c
index c76c14d664..1605dec6f9 100644
--- a/cesar/cp2/fsm/src/fsm.c
+++ b/cesar/cp2/fsm/src/fsm.c
@@ -56,6 +56,7 @@ cp_fsm_handled_event (cp_t *ctx, cp_fsm_event_t *e, uint i)
cp_fsm_transition_table[ctx->fsm.active_states[i]][e->type];
if (t)
{
+ /* Transition with action. */
ctx->fsm.handled_event = e;
ctx->fsm.handled_active_state = i;
e->handler (ctx, e, t);
@@ -74,6 +75,18 @@ cp_fsm_handled_event (cp_t *ctx, cp_fsm_event_t *e, uint i)
ctx->fsm.handled_event = NULL;
}
}
+ else
+ {
+ /* Transition without action. */
+ cp_fsm_state_t to =
+ cp_fsm_only_branch_table[ctx->fsm.active_states[i]][e->type];
+ if (to != CP_FSM_STATE_NB)
+ {
+ dbg_assert (to < CP_FSM_STATE_NB);
+ ctx->fsm.active_states[i] = to;
+ ctx->fsm.handled_event = NULL;
+ }
+ }
}
void
diff --git a/cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm b/cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm
index f59c45cf0b..f3a2fe523b 100644
--- a/cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm
+++ b/cesar/cp2/fsm/test/utest/override/cp2/fsm/src/fsm/cp.fsm
@@ -22,6 +22,7 @@ Events:
test error conditions: branch selected two times
event_mme
event_beacon
+ event_no_action
eventa
eventb
@@ -36,6 +37,7 @@ STATE1:
error_event_dup_branch: branch2 -> .
event_mme -> .
event_beacon -> .
+ event_no_action -> STATE3 [NULL]
eventb -> STATE3
STATE2:
diff --git a/cesar/cp2/fsm/test/utest/src/test_fsm.c b/cesar/cp2/fsm/test/utest/src/test_fsm.c
index 170881a5f3..3f5a88c28e 100644
--- a/cesar/cp2/fsm/test/utest/src/test_fsm.c
+++ b/cesar/cp2/fsm/test/utest/src/test_fsm.c
@@ -141,6 +141,28 @@ test_fsm_basic_test_case (test_t t)
test_fail_unless (cp.fsm.active_states[1] == CP_FSM_STATE_STATEA);
cp_fsm_uninit (&cp);
} test_end;
+ test_begin (t, "no action")
+ {
+ cp_fsm_init (&cp);
+ scenario_entry_t entries[] = {
+ /* STATE1 */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_event_no_action),
+ /* STATE3 */
+ SCENARIO_ACTION (post_and_process,
+ .type = CP_FSM_EVENT_TYPE_event1),
+ SCENARIO_EVENT (cp_fsm__STATE3__event1,
+ .branch = CP_FSM_BRANCH (STATE3, event1, branch1)),
+ /* STATE1 */
+ SCENARIO_END
+ };
+ scenario_globals_t globals = {
+ .cp = &cp,
+ };
+ scenario_run (t, entries, &globals);
+ test_fail_unless (cp.fsm.active_states[0] == CP_FSM_STATE_STATE1);
+ cp_fsm_uninit (&cp);
+ } test_end;
}
void