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
rte_redundancy_config.c File Reference

See rte_redundancy_config.h. More...

#include "rte/redundancy/config/rte_redundancy_config.h"
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
Include dependency graph for rte_redundancy_config.c:

Go to the source code of this file.

Functions

rte_status_t rte_redundancy_config_register_capability (rte_redundancy_capability_fn fn, void *context)
 Registers the capability callback rte_redundancy_config_load() consults after successfully parsing a file, before returning RTE_STATUS_OK. Call once at startup, before load(). No callback registered (the default) means load() accepts any successfully-parsed, internally-consistent config - the same behavior this module had before this function existed.
static size_t skip_ws (const char *buf, size_t len, size_t pos)
static rte_status_t find_key_value_pos_bounded (const char *buf, size_t start_pos, size_t end_pos, const char *key, size_t *out_value_pos)
 Find "key" followed by a colon, return the index just past the colon (and any whitespace), i.e. where the value begins.
static rte_status_t find_key_value_pos (const char *buf, size_t len, const char *key, size_t *out_value_pos)
static rte_status_t parse_string_value (const char *buf, size_t len, size_t pos, char *out, size_t out_size, size_t *out_end_pos)
static rte_status_t parse_uint_value (const char *buf, size_t len, size_t pos, uint32_t *out)
static rte_status_t parse_uint32_checked (const char *buf, size_t len, size_t pos, uint32_t *out)
 Checked variant of parse_uint_value(), used for the socket buffer keys (REQ-REDCFG-001). parse_uint_value() wraps modulo 2^32 and accepts a numeric prefix ("12x" -> 12); it is kept unchanged for the older keys. This one rejects instead.
static rte_status_t parse_optional_channel_u32 (const char *buf, size_t obj_start, size_t obj_end, const char *key, uint32_t *out)
 Optional checked unsigned key inside one channel object (REQ-REDCFG-001).
static rte_status_t parse_string_array (const char *buf, size_t len, size_t pos, char out[][RTE_REDUNDANCY_CONFIG_MAX_ROLE_NAME_LEN], uint32_t max_items, uint32_t *out_count)
rte_status_t rte_channel_config_transport_from_string (const char *name, rte_channel_transport_t *out_transport)
 Parse transport name string ("flow", "netlink", "posix", "dds") into enum.
rte_status_t rte_channel_config_role_from_string (const char *name, rte_channel_role_t *out_role)
 Parse channel role name string ("listen", "connect", "publisher", "subscriber") into enum.
static rte_status_t parse_channel_object (const char *buf, size_t obj_start, size_t obj_end, rte_channel_def_t *out_channel)
static rte_status_t parse_channels_array (const char *buf, size_t len, size_t pos, rte_channel_def_t *out_channels, uint32_t max_channels, uint32_t *out_count)
rte_status_t rte_redundancy_config_topology_from_string (const char *name, rte_redundancy_topology_t *out_topology)
 Parse a topology name string ("2oo2", "2oo2_redundant", "2oo3", "nmr") into its enum value.
const char * rte_redundancy_config_topology_to_string (rte_redundancy_topology_t topology)
 Inverse of rte_redundancy_config_topology_from_string() - for logging/diagnostics.
rte_status_t rte_redundancy_config_standby_mode_from_string (const char *name, rte_standby_mode_t *out_mode)
 Parse a standby-mode name string ("hot", "warm", "cold") into its enum value.
const char * rte_redundancy_config_standby_mode_to_string (rte_standby_mode_t mode)
 Inverse of rte_redundancy_config_standby_mode_from_string() - for logging/diagnostics.
static rte_status_t parse_topology_replicas_and_quorum (const char *buf, size_t len, rte_redundancy_config_t *result)
static rte_status_t parse_optional_standby_mode (const char *buf, size_t len, rte_redundancy_config_t *result)
static rte_status_t parse_optional_roles (const char *buf, size_t len, rte_redundancy_config_t *result)
static rte_status_t parse_optional_channels (const char *buf, size_t len, rte_redundancy_config_t *result)
rte_status_t rte_redundancy_config_load (const char *path, rte_redundancy_config_t *out_config)
 Load a redundancy topology config from a JSON file.
rte_status_t rte_redundancy_config_apply_to_voter (const rte_redundancy_config_t *config, rte_voter_config_t *voter_cfg)
 Copy the resolved quorum from a loaded redundancy config into a rte_voter_config_t, leaving every other field of voter_cfg untouched (compare()/context/timeouts/safestate fields remain the caller's own responsibility to set).
rte_status_t rte_redundancy_config_find_channel_by_name (const rte_redundancy_config_t *config, const char *name, rte_channel_def_t *out_channel)
 Find channel definition by name in the given configuration.
rte_status_t rte_redundancy_config_find_channel_by_id (const rte_redundancy_config_t *config, uint32_t id, rte_channel_def_t *out_channel)
 Find channel definition by ID in the given configuration.
const rte_redundancy_config_t * rte_redundancy_config_get_active (void)
 Get the currently active loaded redundancy/channel configuration (if any).
void rte_redundancy_config_set_active (const rte_redundancy_config_t *config)
 Set the active configuration explicitly (or automatically by rte_redundancy_config_load).

Variables

static rte_redundancy_capability_fn s_capability_fn
static void * s_capability_context
static rte_redundancy_config_t s_active_config
static bool s_has_active_config = false

Detailed Description

See rte_redundancy_config.h.

The parser below is deliberately NOT a general JSON parser - it is a small, bounded scanner for exactly the flat, fixed-key schema documented in the header. stdio (fopen/fread/fclose) is used only at load time, matching the OCORA PI-API's own "stdio.h is init-only" allowance (see docs/rca/RCA-OCORA-PI-API.md Section 3a) - this is deployment-configuration loading, not a cyclic safety operation.

Definition in file rte_redundancy_config.c.

Function Documentation

◆ skip_ws()

size_t skip_ws ( const char * buf,
size_t len,
size_t pos )
static

Skip ASCII whitespace starting at buf[pos], bounded by len.

Definition at line 29 of file rte_redundancy_config.c.

◆ find_key_value_pos_bounded()

rte_status_t find_key_value_pos_bounded ( const char * buf,
size_t start_pos,
size_t end_pos,
const char * key,
size_t * out_value_pos )
static

Find "key" followed by a colon, return the index just past the colon (and any whitespace), i.e. where the value begins.

Returns
RTE_STATUS_OK with *out_value_pos set, or RTE_STATUS_INVALID_STATE if the key is not present.

Definition at line 44 of file rte_redundancy_config.c.

◆ find_key_value_pos()

rte_status_t find_key_value_pos ( const char * buf,
size_t len,
const char * key,
size_t * out_value_pos )
static

Definition at line 82 of file rte_redundancy_config.c.

◆ parse_string_value()

rte_status_t parse_string_value ( const char * buf,
size_t len,
size_t pos,
char * out,
size_t out_size,
size_t * out_end_pos )
static

Parse a quoted string value starting at buf[pos] (must be '"').

Definition at line 88 of file rte_redundancy_config.c.

◆ parse_uint_value()

rte_status_t parse_uint_value ( const char * buf,
size_t len,
size_t pos,
uint32_t * out )
static

Parse an unsigned decimal integer value starting at buf[pos].

Definition at line 116 of file rte_redundancy_config.c.

◆ parse_uint32_checked()

rte_status_t parse_uint32_checked ( const char * buf,
size_t len,
size_t pos,
uint32_t * out )
static

Checked variant of parse_uint_value(), used for the socket buffer keys (REQ-REDCFG-001). parse_uint_value() wraps modulo 2^32 and accepts a numeric prefix ("12x" -> 12); it is kept unchanged for the older keys. This one rejects instead.

Parameters
[in]bufInput buffer.
[in]lenEnd of the value's enclosing object (exclusive).
[in]posIndex of the value's first character.
[out]outWritten only on RTE_STATUS_OK.
Returns
RTE_STATUS_OK: one or more decimal digits, value <= UINT32_MAX, followed (after optional whitespace) by ',' or the end of the object. RTE_STATUS_INVALID_STATE: no leading digit (a string, a sign, ...), a value above UINT32_MAX, or anything else after the digits and any whitespace ('.', 'e', a letter, a second number, ...).

Definition at line 148 of file rte_redundancy_config.c.

◆ parse_optional_channel_u32()

rte_status_t parse_optional_channel_u32 ( const char * buf,
size_t obj_start,
size_t obj_end,
const char * key,
uint32_t * out )
static

Optional checked unsigned key inside one channel object (REQ-REDCFG-001).

Parameters
[in]bufInput buffer.
[in]obj_startIndex of the object's '{'.
[in]obj_endIndex of the object's '}'.
[in]keyKey name without quotes.
[out]outSet when the key is present and valid; left as it is (0 after parse_channel_object()'s memset) when the key is absent.
Returns
RTE_STATUS_OK (absent, or present and valid); RTE_STATUS_INVALID_STATE (present but rejected by parse_uint32_checked()).

Definition at line 195 of file rte_redundancy_config.c.

◆ parse_string_array()

rte_status_t parse_string_array ( const char * buf,
size_t len,
size_t pos,
char out[][RTE_REDUNDANCY_CONFIG_MAX_ROLE_NAME_LEN],
uint32_t max_items,
uint32_t * out_count )
static

Parse a ["a", "b", ...] array of strings starting at buf[pos] (must be '[').

Definition at line 208 of file rte_redundancy_config.c.

◆ parse_channel_object()

rte_status_t parse_channel_object ( const char * buf,
size_t obj_start,
size_t obj_end,
rte_channel_def_t * out_channel )
static

Definition at line 283 of file rte_redundancy_config.c.

◆ parse_channels_array()

rte_status_t parse_channels_array ( const char * buf,
size_t len,
size_t pos,
rte_channel_def_t * out_channels,
uint32_t max_channels,
uint32_t * out_count )
static

Definition at line 375 of file rte_redundancy_config.c.

◆ parse_topology_replicas_and_quorum()

rte_status_t parse_topology_replicas_and_quorum ( const char * buf,
size_t len,
rte_redundancy_config_t * result )
static

Definition at line 521 of file rte_redundancy_config.c.

◆ parse_optional_standby_mode()

rte_status_t parse_optional_standby_mode ( const char * buf,
size_t len,
rte_redundancy_config_t * result )
static

Definition at line 597 of file rte_redundancy_config.c.

◆ parse_optional_roles()

rte_status_t parse_optional_roles ( const char * buf,
size_t len,
rte_redundancy_config_t * result )
static

Definition at line 621 of file rte_redundancy_config.c.

◆ parse_optional_channels()

rte_status_t parse_optional_channels ( const char * buf,
size_t len,
rte_redundancy_config_t * result )
static

Definition at line 642 of file rte_redundancy_config.c.

Variable Documentation

◆ s_capability_fn

rte_redundancy_capability_fn s_capability_fn
static

Definition at line 18 of file rte_redundancy_config.c.

◆ s_capability_context

void* s_capability_context
static

Definition at line 19 of file rte_redundancy_config.c.

◆ s_active_config

rte_redundancy_config_t s_active_config
static

Definition at line 762 of file rte_redundancy_config.c.

◆ s_has_active_config

bool s_has_active_config = false
static

Definition at line 763 of file rte_redundancy_config.c.