Safe API Framework
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Toggle main menu visibility
Loading...
Searching...
No Matches
sapi_channel_service.c
Go to the documentation of this file.
1
5
6
#include "
safeapi/redundancy/channel_service/sapi_channel_service.h
"
7
8
static
const
sapi_channel_service_backend_t
*
s_backend
;
9
10
static
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
{
15
return
SAPI_STATUS_NOT_INITIALIZED
;
16
}
17
return
SAPI_STATUS_OK
;
18
}
19
20
sapi_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
{
25
return
SAPI_STATUS_INVALID_PARAM
;
26
}
27
s_backend
= backend;
28
return
SAPI_STATUS_OK
;
29
}
30
31
sapi_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
{
37
return
SAPI_STATUS_INVALID_PARAM
;
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
47
sapi_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
{
56
return
SAPI_STATUS_INVALID_PARAM
;
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
66
sapi_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
{
75
return
SAPI_STATUS_INVALID_PARAM
;
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
85
sapi_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
sapi_status_t
Common result/status codes.
Definition
sapi_status.h:27
SAPI_STATUS_INVALID_PARAM
@ SAPI_STATUS_INVALID_PARAM
Definition
sapi_status.h:29
SAPI_STATUS_NOT_INITIALIZED
@ SAPI_STATUS_NOT_INITIALIZED
Definition
sapi_status.h:30
SAPI_STATUS_OK
@ SAPI_STATUS_OK
Definition
sapi_status.h:28
sapi_duration_ms_t
uint32_t sapi_duration_ms_t
Definition
sapi_types.h:27
sapi_channel_service.h
Application-facing named channel service.
sapi_channel_service_t
sapi_channel_service_storage_t sapi_channel_service_t
Opaque handle to a named channel service instance.
Definition
sapi_channel_service.h:33
s_backend
static const sapi_clocksync_backend_t * s_backend
Definition
sapi_clocksync.c:18
sapi_channel_service_backend_t
Backend implementation for named channel operations.
Definition
sapi_channel_service.h:43
src
redundancy
channel_service
sapi_channel_service.c
Generated by
1.18.0