RTE RBC 2oo2 Reference Application 0.1.0 build 0006685
SIL 4 2oo2 Dual-Site Fault-Tolerant ERTMS Radio Block Centre Reference Architecture
Loading...
Searching...
No Matches
ab_gp_session_fsm.c File Reference

See ab_gp_session_fsm.h for this table's own design rationale. More...

#include "ab_gp_session_fsm.h"
#include "rte/oal/log/rte_log.h"
#include "rte/utils/string/rte_string.h"
Include dependency graph for ab_gp_session_fsm.c:

Go to the source code of this file.

Macros

#define AB_GP_SESSION_FSM_STATE_COUNT   9U
#define AB_GP_SESSION_FSM_NONE   (-1)

Functions

bool ab_gp_session_fsm_can_handle (ab_gp_ertms_session_state_t from, ab_gp_session_event_t event, ab_gp_ertms_session_state_t *out_to)
 Read-only lookup, no side effect: what event does from a given state produce, if anything.
static const char * state_name (ab_gp_ertms_session_state_t state)
static const char * event_name (ab_gp_session_event_t event)
static void log_event (const ab_gp_ertms_train_context_t *ctx, ab_gp_session_event_t event, bool handled, ab_gp_ertms_session_state_t to)
bool ab_gp_session_fsm_handle_event (ab_gp_ertms_train_context_t *ctx, ab_gp_session_event_t event)
 Applies event to ctx->session_state.

Variables

static const int8_t s_table [AB_GP_SESSION_FSM_STATE_COUNT][AB_GP_SESSION_EVENT_COUNT]
 s_table[from][event] is the resulting state, or AB_GP_SESSION_FSM_NONE if this table defines no outcome for that (state, event) pair (the event does nothing from that state - not an error, just "not applicable here"). Indexed by ab_gp_ertms_session_state_t / ab_gp_session_event_t's own numeric values - keep row/column order in sync with those enums' declaration order if either ever changes (the two _COUNT constants too).

Detailed Description

See ab_gp_session_fsm.h for this table's own design rationale.

Definition in file ab_gp_session_fsm.c.

Macro Definition Documentation

◆ AB_GP_SESSION_FSM_STATE_COUNT

#define AB_GP_SESSION_FSM_STATE_COUNT   9U

Definition at line 11 of file ab_gp_session_fsm.c.

◆ AB_GP_SESSION_FSM_NONE

#define AB_GP_SESSION_FSM_NONE   (-1)

Definition at line 12 of file ab_gp_session_fsm.c.

Function Documentation

◆ ab_gp_session_fsm_can_handle()

bool ab_gp_session_fsm_can_handle ( ab_gp_ertms_session_state_t from,
ab_gp_session_event_t event,
ab_gp_ertms_session_state_t * out_to )

Read-only lookup, no side effect: what event does from a given state produce, if anything.

Parameters
[in]fromCurrent state.
[in]eventEvent to evaluate.
[out]out_toReceives the resulting state on success. Left untouched on failure. May be NULL if the caller only wants the yes/no answer (e.g. a procedure checking whether to bother doing its own work before firing the event for real).
Returns
true and *out_to set if (from, event) has a defined outcome in this table; false (out_to untouched) for an out-of-range state/ event or a combination this table does not define.

Definition at line 211 of file ab_gp_session_fsm.c.

◆ state_name()

const char * state_name ( ab_gp_ertms_session_state_t state)
static

Short, fixed names for log lines only - not used anywhere the table itself is evaluated. Falls back to "UNKNOWN" for an out-of-range value rather than indexing an array, so a corrupted/garbage state can never read out of bounds here.

Definition at line 236 of file ab_gp_session_fsm.c.

◆ event_name()

const char * event_name ( ab_gp_session_event_t event)
static

Definition at line 253 of file ab_gp_session_fsm.c.

◆ log_event()

void log_event ( const ab_gp_ertms_train_context_t * ctx,
ab_gp_session_event_t event,
bool handled,
ab_gp_ertms_session_state_t to )
static

Debug-level line for every ab_gp_session_fsm_handle_event() call, applied or not - the one place this whole table is exercised from, so this is the one place that needs to log to make every real event (not just the ones that produced a transition) observable. Built with rte_string's bounded API (ADR-006), not snprintf. A formatting failure (should not happen: the fixed literals, a 3-digit train_id and two state names always fit storage[]) silently skips the log line rather than risk writing a truncated/garbled one.

Definition at line 281 of file ab_gp_session_fsm.c.

◆ ab_gp_session_fsm_handle_event()

bool ab_gp_session_fsm_handle_event ( ab_gp_ertms_train_context_t * ctx,
ab_gp_session_event_t event )

Applies event to ctx->session_state.

Parameters
[in,out]ctxTrain context whose session_state is (maybe) updated. Must not be NULL.
[in]eventEvent to apply.
Returns
true and ctx->session_state updated to the table's resulting state on success; false and ctx->session_state left UNCHANGED if ctx is NULL or ab_gp_session_fsm_can_handle() would return false for (ctx->session_state, event).

Definition at line 314 of file ab_gp_session_fsm.c.

Variable Documentation

◆ s_table

s_table[from][event] is the resulting state, or AB_GP_SESSION_FSM_NONE if this table defines no outcome for that (state, event) pair (the event does nothing from that state - not an error, just "not applicable here"). Indexed by ab_gp_ertms_session_state_t / ab_gp_session_event_t's own numeric values - keep row/column order in sync with those enums' declaration order if either ever changes (the two _COUNT constants too).

Read a row as "everything event E can do while in state S"; read a column as "every state this event can produce, and from where" - both directly visible without tracing any ertms_procedures/ file.

Definition at line 28 of file ab_gp_session_fsm.c.