Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
ELECTION

Data Structures

struct  rte_election_candidate_t
 One candidate's info for one rte_election_execute() call. The caller builds this array fresh each call from whatever transport it uses to learn about the other replicas - this module does not retain it between calls except via the state recomputed into rte_election_t itself. More...
struct  rte_election_t
 One rte_election_t instance's state. Caller-owned storage; every field is private - reach it only through the functions below. More...
struct  rte_election_config_t
 Configuration for rte_election_init(). More...

Functions

rte_status_t rte_election_init (rte_election_t *election, const rte_election_config_t *config)
 Initializes a rte_election_t. own_last_state starts at RTE_DUAL_STATE_IDLE (never yet evaluated).
rte_status_t rte_election_execute (rte_election_t *election, const rte_election_candidate_t *candidates, uint32_t candidate_count)
 Evaluates one round of election against the caller-supplied candidate snapshot (REQ-ELECTION-002 through -005). Empty snapshot (candidate_count == 0, or this instance's own_id not present in it) yields RTE_DUAL_STATE_UNKNOWN - no quorum to decide anything from, same "report, do not react" posture as rte_dual_negotiator_execute() on a lost peer.
rte_dual_state_t rte_election_get_own_state (const rte_election_t *election)
 Returns this instance's own current rte_dual_state_t, as of the last rte_election_execute() call.
rte_status_t rte_election_get_winner_id (const rte_election_t *election, uint32_t *out_id)
 Returns the last-elected winner's id.

Detailed Description

Function Documentation

◆ rte_election_init()

rte_status_t rte_election_init ( rte_election_t * election,
const rte_election_config_t * config )

Initializes a rte_election_t. own_last_state starts at RTE_DUAL_STATE_IDLE (never yet evaluated).

Parameters
electionCaller-owned storage to initialize. Must not be NULL.
configConfiguration. Must not be NULL.
Returns
RTE_STATUS_OK; RTE_STATUS_INVALID_PARAM otherwise.

Local variables declarations Global functions

Definition at line 21 of file rte_election.c.

◆ rte_election_execute()

rte_status_t rte_election_execute ( rte_election_t * election,
const rte_election_candidate_t * candidates,
uint32_t candidate_count )

Evaluates one round of election against the caller-supplied candidate snapshot (REQ-ELECTION-002 through -005). Empty snapshot (candidate_count == 0, or this instance's own_id not present in it) yields RTE_DUAL_STATE_UNKNOWN - no quorum to decide anything from, same "report, do not react" posture as rte_dual_negotiator_execute() on a lost peer.

Parameters
electionInitialized election. Must not be NULL.
candidatesThis round's snapshot. May be NULL only if candidate_count is 0.
candidate_countNumber of entries in candidates; must not exceed RTE_REDUNDANCY_CONFIG_MAX_REPLICAS (RTE_STATUS_INVALID_PARAM if it does - a caller-side bug, not a runtime condition to degrade gracefully from).
Returns
RTE_STATUS_OK; RTE_STATUS_INVALID_PARAM for a NULL election, an over-long candidate_count, or a NULL candidates with a nonzero candidate_count.

Definition at line 36 of file rte_election.c.

◆ rte_election_get_own_state()

rte_dual_state_t rte_election_get_own_state ( const rte_election_t * election)

Returns this instance's own current rte_dual_state_t, as of the last rte_election_execute() call.

Parameters
electionElection to query. May be NULL (returns RTE_DUAL_STATE_IDLE, defensive default).
Returns
The current own state.

Definition at line 83 of file rte_election.c.

◆ rte_election_get_winner_id()

rte_status_t rte_election_get_winner_id ( const rte_election_t * election,
uint32_t * out_id )

Returns the last-elected winner's id.

Parameters
electionElection to query. May be NULL.
out_idReceives the winner's id. Must not be NULL.
Returns
RTE_STATUS_OK; RTE_STATUS_NOT_INITIALIZED if no round has ever produced a winner yet (e.g. every rte_election_execute() call so far had an empty/self-absent snapshot); RTE_STATUS_INVALID_PARAM if election or out_id is NULL.

Definition at line 92 of file rte_election.c.