Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_netlink.c
Go to the documentation of this file.
1
11
13
15
18static const sapi_netlink_backend_t *s_backend = NULL;
19
21
23
24
27{
28 sapi_status_t lifecycle_status;
29
30 if (backend == NULL)
31 {
33 }
34 /* REQ-LIFECYCLE-001 (ADR-026): registering a backend is a setup-only
35 * action - refuse once the application's setup phase has been locked. */
36 lifecycle_status = sapi_lifecycle_check_setup_allowed();
37 if (lifecycle_status != SAPI_STATUS_OK)
38 {
39 return lifecycle_status;
40 }
41 s_backend = backend;
42 return SAPI_STATUS_OK;
43}
44
45sapi_status_t sapi_netlink_open(sapi_netlink_storage_t *storage,
46 const sapi_netlink_config_t *config,
47 sapi_netlink_handle_t *out_handle)
48{
49 if ((storage == NULL) || (config == NULL) || (out_handle == NULL))
50 {
52 }
53 if (config->message_size == 0U)
54 {
56 }
57 if ((config->role == SAPI_NETLINK_ROLE_CONNECT) && (config->host == NULL))
58 {
60 }
61 *out_handle = NULL;
62 if (s_backend == NULL)
63 {
65 }
66 if (s_backend->open == NULL)
67 {
69 }
70 return s_backend->open(storage, config, out_handle);
71}
72
74 const void *message,
75 size_t message_size,
76 sapi_duration_ms_t timeout_ms)
77{
78 if ((handle == NULL) || (message == NULL) || (message_size == 0U))
79 {
81 }
82 if (s_backend == NULL)
83 {
85 }
86 if (s_backend->send == NULL)
87 {
89 }
90 return s_backend->send(handle, message, message_size, timeout_ms);
91}
92
94 void *out_message,
95 size_t buffer_size,
96 sapi_duration_ms_t timeout_ms)
97{
98 if ((handle == NULL) || (out_message == NULL) || (buffer_size == 0U))
99 {
101 }
102 if (s_backend == NULL)
103 {
105 }
106 if (s_backend->receive == NULL)
107 {
109 }
110 return s_backend->receive(handle, out_message, buffer_size, timeout_ms);
111}
112
114{
115 if (handle == NULL)
116 {
118 }
119 if (s_backend == NULL)
120 {
122 }
123 if (s_backend->close == NULL)
124 {
126 }
127 return s_backend->close(handle);
128}
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
Process-wide application setup-phase lock (ADR-026).