Safe API Framework 0.1.0 build 384e6ae
Layered API framework for safety-related applications (ERTMS RBC reference targeting CENELEC EN 50128 SIL 4)
Loading...
Searching...
No Matches
rte_channel_service.c
Go to the documentation of this file.
1
5
9
11
12static rte_status_t validate_osadapter(void)
13{
14 if ((s_osadapter == NULL) || (s_osadapter->setup == NULL) || (s_osadapter->read == NULL) ||
15 (s_osadapter->send == NULL) || (s_osadapter->close == NULL))
16 {
18 }
19 return RTE_STATUS_OK;
20}
21
23{
24 if ((osadapter == NULL) || (osadapter->setup == NULL) || (osadapter->read == NULL) ||
25 (osadapter->send == NULL) || (osadapter->close == NULL))
26 {
28 }
29 s_osadapter = osadapter;
30 return RTE_STATUS_OK;
31}
32
33rte_status_t rte_channel_service_setup(rte_channel_service_t *storage, const char *channel_name)
34{
35 rte_status_t status;
36
37 if ((storage == NULL) || (channel_name == NULL))
38 {
40 }
41 /* REQ-LIFECYCLE-001/003 (ADR-026, OSA rules): setup-only - refused and reported once the setup phase is locked. */
42 {
44
45 if (lifecycle_status != RTE_STATUS_OK)
46 {
47 return lifecycle_status;
48 }
49 }
50 status = validate_osadapter();
51 if (status != RTE_STATUS_OK)
52 {
53 return status;
54 }
55 return s_osadapter->setup(storage, channel_name);
56}
57
58rte_status_t rte_channel_service_setup_by_id(rte_channel_service_t *storage, uint32_t channel_id)
59{
62 rte_status_t status;
63
64 if (storage == NULL)
65 {
67 }
68 if (active == NULL)
69 {
71 }
72 status = rte_redundancy_config_find_channel_by_id(active, channel_id, &def);
73 if (status != RTE_STATUS_OK)
74 {
75 return status;
76 }
77 return rte_channel_service_setup(storage, def.name);
78}
79
80rte_status_t rte_channel_service_read(rte_channel_service_t *storage,
81 void *data,
82 size_t data_size,
83 rte_duration_ms_t timeout_ms)
84{
85 rte_status_t status;
86
87 if ((storage == NULL) || (data == NULL) || (data_size == 0U))
88 {
90 }
91 status = validate_osadapter();
92 if (status != RTE_STATUS_OK)
93 {
94 return status;
95 }
96 return s_osadapter->read(storage, data, data_size, timeout_ms);
97}
98
100 void *data,
101 size_t data_size,
102 rte_duration_ms_t timeout_ms,
103 size_t *out_actual_size)
104{
105 rte_status_t status;
106
107 if ((storage == NULL) || (data == NULL) || (data_size == 0U) || (out_actual_size == NULL))
108 {
110 }
111 status = validate_osadapter();
112 if (status != RTE_STATUS_OK)
113 {
114 return status;
115 }
116 if (s_osadapter->read_ex != NULL)
117 {
118 return s_osadapter->read_ex(storage, data, data_size, timeout_ms, out_actual_size);
119 }
120 /* OSAdapter has no length-aware read: fall back to the plain one and report the whole
121 * buffer as received, matching every caller's behaviour before this function existed. */
122 status = s_osadapter->read(storage, data, data_size, timeout_ms);
123 if (status == RTE_STATUS_OK)
124 {
125 *out_actual_size = data_size;
126 }
127 return status;
128}
129
131 const void *data,
132 size_t data_size,
133 rte_duration_ms_t timeout_ms)
134{
135 rte_status_t status;
136
137 if ((storage == NULL) || (data == NULL) || (data_size == 0U))
138 {
140 }
141 status = validate_osadapter();
142 if (status != RTE_STATUS_OK)
143 {
144 return status;
145 }
146 return s_osadapter->send(storage, data, data_size, timeout_ms);
147}
148
149rte_status_t rte_channel_service_close(rte_channel_service_t *storage)
150{
151 rte_status_t status;
152
153 if (storage == NULL)
154 {
155 return RTE_STATUS_OK;
156 }
157 status = validate_osadapter();
158 if (status != RTE_STATUS_OK)
159 {
160 return status;
161 }
162 return s_osadapter->close(storage);
163}
rte_status_t rte_lifecycle_check_setup_allowed(void)
Convenience check for a setup-only constructor: call this as one of the first checks in any function ...
rte_status_t
Common result/status codes.
Definition rte_status.h:27
@ RTE_STATUS_OK
Definition rte_status.h:28
@ RTE_STATUS_INVALID_PARAM
Definition rte_status.h:29
@ RTE_STATUS_NOT_INITIALIZED
Definition rte_status.h:30
uint32_t rte_duration_ms_t
Definition rte_types.h:27
const rte_redundancy_config_t * rte_redundancy_config_get_active(void)
Get the currently active loaded redundancy/channel configuration (if any).
rte_status_t rte_redundancy_config_find_channel_by_id(const rte_redundancy_config_t *config, uint32_t id, rte_channel_def_t *out_channel)
Find channel definition by ID in the given configuration.
Application-facing named channel service.
rte_status_t rte_channel_service_send(rte_channel_service_t *storage, const void *data, size_t data_size, rte_duration_ms_t timeout_ms)
Sends data_size bytes of data on the named channel in storage through the registered OSAdapter's send...
rte_channel_service_storage_t rte_channel_service_t
Opaque handle to a named channel service instance.
rte_status_t rte_channel_service_read_ex(rte_channel_service_t *storage, void *data, size_t data_size, rte_duration_ms_t timeout_ms, size_t *out_actual_size)
Same as rte_channel_service_read, but also reports the actual number of bytes received into data (nev...
rte_status_t rte_osadapter_channel_service_register(const rte_osadapter_channel_service_t *osadapter)
Registers the OSAdapter that implements named channels (ADR-005).
static const rte_osadapter_clocksync_t * s_osadapter
Process-wide application setup-phase lock (ADR-026).
Application-level redundancy topology configuration (2oo2 / 2oo2 with redundancy / 2oo3 / NMR),...
OSAdapter implementation for named channel operations.
rte_status_t(*) send(rte_channel_service_storage_t *storage, const void *data, size_t data_size, rte_duration_ms_t timeout_ms)
Sends data_size bytes of data on the channel set up in storage, within timeout_ms.
rte_status_t(*) read_ex(rte_channel_service_storage_t *storage, void *data, size_t data_size, rte_duration_ms_t timeout_ms, size_t *out_actual_size)
Optional: same as read, but also reports the true number of bytes the transport actually received (a ...