Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_ipc.c
Go to the documentation of this file.
1
10
12
14
17static const sapi_ipc_backend_t *s_backend = NULL;
18
20
22
23
26{
27 sapi_status_t lifecycle_status;
28
29 if (backend == NULL)
30 {
32 }
33 /* REQ-LIFECYCLE-001 (ADR-026): registering a backend is a setup-only
34 * action - refuse once the application's setup phase has been locked. */
35 lifecycle_status = sapi_lifecycle_check_setup_allowed();
36 if (lifecycle_status != SAPI_STATUS_OK)
37 {
38 return lifecycle_status;
39 }
40 s_backend = backend;
41 return SAPI_STATUS_OK;
42}
43
44sapi_status_t sapi_ipc_create(sapi_ipc_storage_t *storage,
45 const sapi_ipc_config_t *config,
46 sapi_ipc_handle_t *out_handle)
47{
48 if ((storage == NULL) || (config == NULL) || (out_handle == NULL))
49 {
51 }
52 if ((config->message_size == 0U) || (config->queue_depth == 0U))
53 {
55 }
56 *out_handle = NULL;
57 if (s_backend == NULL)
58 {
60 }
61 if (s_backend->create == NULL)
62 {
64 }
65 return s_backend->create(storage, config, out_handle);
66}
67
69 const void *message,
70 size_t message_size,
71 sapi_duration_ms_t timeout_ms)
72{
73 if ((handle == NULL) || (message == NULL) || (message_size == 0U))
74 {
76 }
77 if (s_backend == NULL)
78 {
80 }
81 if (s_backend->send == NULL)
82 {
84 }
85 return s_backend->send(handle, message, message_size, timeout_ms);
86}
87
89 void *out_message,
90 size_t buffer_size,
91 sapi_duration_ms_t timeout_ms)
92{
93 if ((handle == NULL) || (out_message == NULL) || (buffer_size == 0U))
94 {
96 }
97 if (s_backend == NULL)
98 {
100 }
101 if (s_backend->receive == NULL)
102 {
104 }
105 return s_backend->receive(handle, out_message, buffer_size, timeout_ms);
106}
107
109{
110 if (handle == NULL)
111 {
113 }
114 if (s_backend == NULL)
115 {
117 }
118 if (s_backend->destroy == NULL)
119 {
121 }
122 return s_backend->destroy(handle);
123}
sapi_status_t sapi_ipc_register_backend(const sapi_ipc_backend_t *backend)
Registers the backend implementation used by every sapi_ipc_* call (ADR-005 section 2....
Definition sapi_ipc.c:25
sapi_status_t sapi_ipc_create(sapi_ipc_storage_t *storage, const sapi_ipc_config_t *config, sapi_ipc_handle_t *out_handle)
Creates a bounded message channel.
Definition sapi_ipc.c:44
struct sapi_ipc_impl_s * sapi_ipc_handle_t
Opaque handle to a created IPC channel, returned by sapi_ipc_create().
Definition sapi_ipc.h:34
sapi_status_t sapi_ipc_receive(sapi_ipc_handle_t handle, void *out_message, size_t buffer_size, sapi_duration_ms_t timeout_ms)
Receives one message, blocking at most timeout_ms.
Definition sapi_ipc.c:88
sapi_status_t sapi_ipc_destroy(sapi_ipc_handle_t handle)
Destroys a message channel.
Definition sapi_ipc.c:108
sapi_status_t sapi_ipc_send(sapi_ipc_handle_t handle, const void *message, size_t message_size, sapi_duration_ms_t timeout_ms)
Sends one message, blocking at most timeout_ms.
Definition sapi_ipc.c:68
sapi_status_t sapi_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
sapi_status_t
Common result/status codes.
Definition sapi_status.h:27
@ SAPI_STATUS_NOT_SUPPORTED
Definition sapi_status.h:34
@ SAPI_STATUS_INVALID_PARAM
Definition sapi_status.h:29
@ SAPI_STATUS_NOT_INITIALIZED
Definition sapi_status.h:30
@ SAPI_STATUS_OK
Definition sapi_status.h:28
uint32_t sapi_duration_ms_t
Definition sapi_types.h:27
static const sapi_clocksync_backend_t * s_backend
OS Abstraction Layer - Inter-process/inter-task communication service.
OS-backend adaptation surface for the IPC service (ADR-005, ADR-021).
Process-wide application setup-phase lock (ADR-026).
Backend vtable: an integrator's implementation of the IPC service for a specific OS/RTOS (ADR-005)....
sapi_status_t(*) send(sapi_ipc_handle_t handle, const void *message, size_t message_size, sapi_duration_ms_t timeout_ms)
Backend implementation of sapi_ipc_send(). May be NULL.
sapi_status_t(*) receive(sapi_ipc_handle_t handle, void *out_message, size_t buffer_size, sapi_duration_ms_t timeout_ms)
Backend implementation of sapi_ipc_receive(). May be NULL.
sapi_status_t(*) create(sapi_ipc_storage_t *storage, const sapi_ipc_config_t *config, sapi_ipc_handle_t *out_handle)
Backend implementation of sapi_ipc_create(). May be NULL.
sapi_status_t(*) destroy(sapi_ipc_handle_t handle)
Backend implementation of sapi_ipc_destroy(). May be NULL.
Configuration for sapi_ipc_create().
Definition sapi_ipc.h:38
size_t message_size
Definition sapi_ipc.h:40
size_t queue_depth
Definition sapi_ipc.h:41