|
Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
|
Files | |
| file | src/redundancy/channel_link/sapi_channel.c |
| One redundant channel: validates parameters, then dispatches to its configured send/recv callbacks, tracking health as a side effect (ADR-025). | |
Data Structures | |
| struct | sapi_channel_health_t |
| Health statistics for one vital channel. More... | |
| struct | sapi_channel_config_t |
| Configuration for sapi_channel_init(). More... | |
| struct | sapi_channel_storage_t |
| Storage for one vital channel instance (opaque to caller). More... | |
Typedefs | |
| typedef sapi_status_t(*) | sapi_channel_send_fn(void *channel_handle, const void *data, size_t data_size) |
| Backend send callback: transmits on this channel's underlying transport. | |
| typedef sapi_status_t(*) | sapi_channel_recv_fn(void *channel_handle, void *data, size_t data_size, uint32_t timeout_ms) |
| Backend receive callback: reads from this channel's underlying transport. | |
| typedef sapi_channel_storage_t | sapi_channel_t |
| Opaque handle to a vital channel instance. | |
Functions | |
| sapi_status_t | sapi_channel_init (sapi_channel_storage_t *storage, const sapi_channel_config_t *config) |
| Initializes one vital channel over a caller-supplied transport. | |
| sapi_status_t | sapi_channel_send (sapi_channel_t *handle, const void *data, size_t data_size) |
| Sends data on this channel via its backend send callback. | |
| sapi_status_t | sapi_channel_receive (sapi_channel_t *handle, void *data, size_t data_size, uint32_t timeout_ms) |
| Receives data on this channel via its backend receive callback. | |
| sapi_status_t | sapi_channel_get_health (const sapi_channel_t *handle, sapi_channel_health_t *out_health) |
| Queries this channel's health statistics. | |
| const char * | sapi_channel_get_name (const sapi_channel_t *handle) |
| Returns this channel's name, as given in sapi_channel_config_t::name at sapi_channel_init() time. | |
| sapi_status_t | sapi_channel_set_healthy (sapi_channel_t *handle, bool is_healthy) |
| Marks this channel healthy/unhealthy. | |
| sapi_status_t | sapi_channel_destroy (sapi_channel_t *handle) |
| Destroys a vital channel instance. | |
| typedef sapi_status_t(*) sapi_channel_send_fn(void *channel_handle, const void *data, size_t data_size) |
Backend send callback: transmits on this channel's underlying transport.
| [in] | channel_handle | Opaque transport handle (as supplied in sapi_channel_config_t::channel_handle) |
| [in] | data | Data to send |
| [in] | data_size | Size of data in bytes |
Definition at line 67 of file sapi_channel.h.
| typedef sapi_status_t(*) sapi_channel_recv_fn(void *channel_handle, void *data, size_t data_size, uint32_t timeout_ms) |
Backend receive callback: reads from this channel's underlying transport.
| [in] | channel_handle | Opaque transport handle |
| [out] | data | Buffer to receive data |
| [in] | data_size | Size of data buffer |
| [in] | timeout_ms | Timeout in milliseconds |
Definition at line 82 of file sapi_channel.h.
| typedef sapi_channel_storage_t sapi_channel_t |
Opaque handle to a vital channel instance.
Created by sapi_channel_init(); used directly, or registered into a sapi_voter_t (N-way voting) or sapi_cross_comparator_t (2-way comparison) for the redundancy/comparison use case.
Definition at line 127 of file sapi_channel.h.
| sapi_status_t sapi_channel_init | ( | sapi_channel_storage_t * | storage, |
| const sapi_channel_config_t * | config ) |
Initializes one vital channel over a caller-supplied transport.
| [out] | storage | Pre-allocated storage. Must not be NULL. |
| [in] | config | Configuration with send/recv callbacks. Must not be NULL; config->send and config->recv must not be NULL. |
REQ-CHANNEL-001: No dynamic allocation; caller supplies storage. REQ-CHANNEL-002: Rejects a NULL config->send/config->recv.
Local makros Local types declarations Local variables declarations Global variables declarations Local function declarations Global functions
Definition at line 23 of file sapi_channel.c.
| sapi_status_t sapi_channel_send | ( | sapi_channel_t * | handle, |
| const void * | data, | ||
| size_t | data_size ) |
Sends data on this channel via its backend send callback.
| [in] | handle | Vital channel handle. Must not be NULL and must have been initialized. |
| [in] | data | Data to send. Must not be NULL. |
| [in] | data_size | Size of data in bytes. Must be > 0. |
REQ-CHANNEL-003: Dispatches to config->send and updates health counters on every call, regardless of outcome.
Definition at line 56 of file sapi_channel.c.
| sapi_status_t sapi_channel_receive | ( | sapi_channel_t * | handle, |
| void * | data, | ||
| size_t | data_size, | ||
| uint32_t | timeout_ms ) |
Receives data on this channel via its backend receive callback.
| [in] | handle | Vital channel handle. Must not be NULL and must have been initialized. |
| [out] | data | Buffer to receive data. Must not be NULL. |
| [in] | data_size | Size of data buffer. Must be > 0. |
| [in] | timeout_ms | Timeout passed to config->recv(). |
REQ-CHANNEL-003: Dispatches to config->recv and updates health counters on every call, regardless of outcome.
Definition at line 84 of file sapi_channel.c.
| sapi_status_t sapi_channel_get_health | ( | const sapi_channel_t * | handle, |
| sapi_channel_health_t * | out_health ) |
Queries this channel's health statistics.
| [in] | handle | Vital channel handle. Must not be NULL. |
| [out] | out_health | Receives a copy of the current health state. Must not be NULL. |
Definition at line 113 of file sapi_channel.c.
| const char * sapi_channel_get_name | ( | const sapi_channel_t * | handle | ) |
Returns this channel's name, as given in sapi_channel_config_t::name at sapi_channel_init() time.
| [in] | handle | Vital channel handle. Must not be NULL. |
Definition at line 124 of file sapi_channel.c.
| sapi_status_t sapi_channel_set_healthy | ( | sapi_channel_t * | handle, |
| bool | is_healthy ) |
Marks this channel healthy/unhealthy.
Intended for a sapi_voter_t/sapi_cross_comparator_t (or any other owner) to call after deciding, by its own policy, that this channel should stop (or resume) participating - this module itself never changes is_healthy on its own (a single I/O failure alone does not mark a channel unhealthy; that decision belongs to the owner tracking failures across multiple channels).
| [in] | handle | Vital channel handle. Must not be NULL. |
| [in] | is_healthy | New health state. |
REQ-CHANNEL-004: is_healthy defaults true at init and is never cleared automatically by this module - only via this explicit call.
Definition at line 133 of file sapi_channel.c.
| sapi_status_t sapi_channel_destroy | ( | sapi_channel_t * | handle | ) |
Destroys a vital channel instance.
No dynamic memory to free; the underlying transport is NOT closed (caller retains ownership of channel_handle).
| [in] | handle | Vital channel handle. May be NULL. |
Definition at line 144 of file sapi_channel.c.