Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
sapi_channel_service.c
Go to the documentation of this file.
1
5
7
9
10static sapi_status_t validate_backend(void)
11{
12 if ((s_backend == NULL) || (s_backend->setup == NULL) || (s_backend->read == NULL) ||
13 (s_backend->send == NULL) || (s_backend->close == NULL))
14 {
16 }
17 return SAPI_STATUS_OK;
18}
19
20sapi_status_t sapi_channel_service_register_backend(const sapi_channel_service_backend_t *backend)
21{
22 if ((backend == NULL) || (backend->setup == NULL) || (backend->read == NULL) ||
23 (backend->send == NULL) || (backend->close == NULL))
24 {
26 }
27 s_backend = backend;
28 return SAPI_STATUS_OK;
29}
30
31sapi_status_t sapi_channel_service_setup(sapi_channel_service_t *storage, const char *channel_name)
32{
33 sapi_status_t status;
34
35 if ((storage == NULL) || (channel_name == NULL))
36 {
38 }
39 status = validate_backend();
40 if (status != SAPI_STATUS_OK)
41 {
42 return status;
43 }
44 return s_backend->setup(storage, channel_name);
45}
46
47sapi_status_t sapi_channel_service_read(sapi_channel_service_t *storage,
48 void *data,
49 size_t data_size,
50 sapi_duration_ms_t timeout_ms)
51{
52 sapi_status_t status;
53
54 if ((storage == NULL) || (data == NULL) || (data_size == 0U))
55 {
57 }
58 status = validate_backend();
59 if (status != SAPI_STATUS_OK)
60 {
61 return status;
62 }
63 return s_backend->read(storage, data, data_size, timeout_ms);
64}
65
66sapi_status_t sapi_channel_service_send(sapi_channel_service_t *storage,
67 const void *data,
68 size_t data_size,
69 sapi_duration_ms_t timeout_ms)
70{
71 sapi_status_t status;
72
73 if ((storage == NULL) || (data == NULL) || (data_size == 0U))
74 {
76 }
77 status = validate_backend();
78 if (status != SAPI_STATUS_OK)
79 {
80 return status;
81 }
82 return s_backend->send(storage, data, data_size, timeout_ms);
83}
84
85sapi_status_t sapi_channel_service_close(sapi_channel_service_t *storage)
86{
87 sapi_status_t status;
88
89 if (storage == NULL)
90 {
91 return SAPI_STATUS_OK;
92 }
93 status = validate_backend();
94 if (status != SAPI_STATUS_OK)
95 {
96 return status;
97 }
98 return s_backend->close(storage);
99}
sapi_status_t
Common result/status codes.
Definition sapi_status.h:27
@ 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
Application-facing named channel service.
sapi_channel_service_storage_t sapi_channel_service_t
Opaque handle to a named channel service instance.
static const sapi_clocksync_backend_t * s_backend
Backend implementation for named channel operations.