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_jru_forward.c
Go to the documentation of this file.
1
5#include "ab_gp_jru_forward.h"
6
10
12
14
16static rte_status_t osadapter_init(void);
17static void osadapter_write(rte_log_level_t level, const char *tag, const char *message);
18
20static const rte_osadapter_log_t s_forward_osadapter = { osadapter_init, osadapter_write };
21static const rte_osadapter_log_t *s_delegate;
23static uint8_t s_source_id;
24static uint8_t s_seq;
28static __thread bool s_in_forward;
29
31
33rte_status_t ab_gp_jru_forward_install(const rte_osadapter_log_t *delegate)
34{
35 rte_status_t status;
36
37 if (delegate == NULL)
38 {
39 status = RTE_STATUS_INVALID_PARAM;
40 }
41 else
42 {
43 s_delegate = delegate;
44 s_handle = NULL;
45 status = rte_osadapter_log_register(&s_forward_osadapter);
46 }
47 return status;
48}
49
51{
52 s_handle = handle;
53 s_source_id = source_id;
54}
55
56/****Local functions ****/
57
58static rte_status_t osadapter_init(void)
59{
60 return (s_delegate != NULL) ? s_delegate->init() : RTE_STATUS_OK;
61}
62
63static void osadapter_write(rte_log_level_t level, const char *tag, const char *message)
64{
65 if (s_delegate != NULL)
66 {
67 s_delegate->write(level, tag, message);
68 }
69
70 /* Forward INFO and above only - DEBUG is high-volume local diagnostic detail, not the kind
71 * of durable external record JRU/diagnostic forwarding exists for. Best-effort: no channel
72 * attached yet (early startup, before ab_gp_jru_forward_set_channel()) or a full relay
73 * queue silently drops the event - never affects the caller of write(), same contract as
74 * every other rte_osadapter_log_t implementation in this workspace. ISS-020: while the
75 * status service is unreachable the UTIL link is not open, and ab_gp_channel_send_relay()
76 * lets this caller start at most one bounded open attempt
77 * (RTE_EXAMPLE_UTIL_OPEN_ATTEMPT_TIMEOUT_MS) per RTE_EXAMPLE_UTIL_REOPEN_BACKOFF_MS; every
78 * other event in that time is dropped without touching the link (ab_gp_util_link_gate.h). */
79 if ((s_handle != NULL) && (level >= RTE_LOG_LEVEL_INFO) && !s_in_forward)
80 {
81 char payload[RBC_UTIL_PAYLOAD_MAX];
82 uint8_t frame[RBC_UTIL_FRAME_SIZE];
83
84 s_in_forward = true;
85 rbc_util_jru_payload_encode(payload, sizeof(payload), level, tag, message);
86 s_seq++;
88 s_seq, payload);
90 (size_t)RBC_UTIL_FRAME_SIZE);
91 s_in_forward = false;
92 }
93}
rte_status_t ab_gp_channel_send_relay(ab_gp_channel_handle_t handle, rte_example_relay_kind_t kind, uint8_t index, const uint8_t *bytes, size_t size)
Sends an envelope over a specific C relay channel.
struct ab_gp_channel_context_s * ab_gp_channel_handle_t
Opaque handle over this component's own static per-process context.
rte_status_t ab_gp_jru_forward_install(const rte_osadapter_log_t *delegate)
Wraps delegate (the real local log OSAdapter, e.g. rte_posix_osadapter_log()) and registers the wrapp...
static ab_gp_channel_handle_t s_handle
void ab_gp_jru_forward_set_channel(ab_gp_channel_handle_t handle, uint8_t source_id)
Attaches the open AB<->C relay channel: from this call on, write() also republishes INFO+ events to G...
static uint8_t s_source_id
static uint8_t s_seq
static const rte_osadapter_log_t * s_delegate
static const rte_osadapter_log_t s_forward_osadapter
static rte_status_t osadapter_init(void)
static __thread bool s_in_forward
static void osadapter_write(rte_log_level_t level, const char *tag, const char *message)
A/B -> Gateway log-event forwarding (Platform_Protocol_JRU/CLAUDE.md's "Wiring" section)....
ADR-038: the wire frame for the A/B<->C util side channel (RTE_EXAMPLE_RELAY_KIND_UTIL) and the C-sid...
static void rbc_util_frame_encode(uint8_t out[RBC_UTIL_FRAME_SIZE], rbc_util_msg_type_t msg_type, uint8_t source_id, uint16_t topic_id, uint8_t seq, const char *payload)
Encodes a util frame into a fixed RBC_UTIL_FRAME_SIZE buffer.
#define RBC_UTIL_FRAME_SIZE
#define RBC_UTIL_PAYLOAD_MAX
@ RBC_UTIL_MSG_PUBLISH
#define RBC_UTIL_TOPIC_JRU_LOG
A/B -> Gateway log-event forwarding (see rbc_util_jru_payload.h). Gateway's status service forwards e...
Wire payload for RBC_UTIL_TOPIC_JRU_LOG publishes: A/B forwarding one local log event to Gateway,...
static void rbc_util_jru_payload_encode(char *out, size_t out_size, rte_log_level_t level, const char *tag, const char *message)
Encodes one forwarded log event into a JRU_LOG publish payload.
West/East site identity and the per-site config derived from it (ports, container host lookup) - see ...
@ RTE_EXAMPLE_RELAY_KIND_UTIL
Definition site_config.h:48