Statistics
| Branch: | Revision:

urtware / src / urt_subscriber.c @ e360ce71

History | View | Annotate | Download (16.088 KB)

1 1fb06240 skenneweg
/*
2
µRtWare is a lightweight publish/subscribe middleware for real-time
3
applications. It was developed as part of the software habitat for the
4
Autonomous Mini Robot [1] (AMiRo) but can be used for other purposes as well.
5

6
Copyright (C) 2018..2020  Thomas Schöpping et al.
7

8
This program is free software: you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation, either version 3 of the License, or
11
(at your option) any later version.
12

13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
GNU General Public License for more details.
17

18
You should have received a copy of the GNU General Public License
19
along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
*/
21
22 7d9678db skenneweg
#include <urtware.h>
23
24 1fb06240 skenneweg
/******************************************************************************/
25
/* LOCAL DEFINITIONS                                                          */
26
/******************************************************************************/
27
28
/******************************************************************************/
29
/* EXPORTED VARIABLES                                                         */
30
/******************************************************************************/
31
32
/******************************************************************************/
33
/* LOCAL TYPES                                                                */
34
/******************************************************************************/
35
36
/******************************************************************************/
37
/* LOCAL VARIABLES                                                            */
38
/******************************************************************************/
39
40
/******************************************************************************/
41
/* LOCAL FUNCTIONS                                                            */
42
/******************************************************************************/
43
44
/******************************************************************************/
45
/* EXPORTED FUNCTIONS                                                         */
46
/******************************************************************************/
47
48 7d9678db skenneweg
/**
49
 * @brief   Initialize the nrt Subscriber.
50
 *
51 5198dfae skenneweg
 * @param[in] subscriber  The NRT subscriber to initialize. Must not be NULL.
52 7d9678db skenneweg
 */
53
void urtNrtSubscriberInit (urt_nrtsubscriber_t* subscriber) {return;}
54 1fb06240 skenneweg
55 7d9678db skenneweg
/**
56 5198dfae skenneweg
 * @brief  Subscribes the subscriber to a topic.
57 7d9678db skenneweg
 *
58 5198dfae skenneweg
 * @param[in] subscriber  The NRT subscriber which shall subscribe to a topic. Must not be NULL.
59
 * @param[in] topic  The topic to subscribe to. Must not be NULL.
60
 * @param[in] messages  NULL terminated list of messages to contribute to the topic.
61
 *                      Messages must not be associated to another topic.
62
 *                      Once a message has been contributed, it cannot be removed later.
63
 *                      May be NULL(no messages to contribute).
64 7d9678db skenneweg
 *
65 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
66
 *          Returns URT_STATUS_SUBSCRIBE_TOPICSET if the subscriber is already associated to a topic.
67 7d9678db skenneweg
 */
68 1fb06240 skenneweg
urt_status_t urtNrtSubscriberSubscribe (urt_nrtsubscriber_t* subscriber, urt_topic_t* topic, urt_message_t* messages) {
69 7d9678db skenneweg
  return URT_STATUS_OK;
70 1fb06240 skenneweg
}
71
72 7d9678db skenneweg
/**
73 5198dfae skenneweg
 * @brief  Fetches the next message.
74 7d9678db skenneweg
 *
75 5198dfae skenneweg
 * @param[in] subscriber  The NRT subscriber that shall fetch the message. Must not be NULL.
76
 * @param[in] payload  Pointer where to copy the payload to. May be NULL for messages without payload.
77
 * @param[in] bytes  Payload size in bytes.
78
 * @param[in] latency  The latency can be returned by reference. May be NULL.
79 7d9678db skenneweg
 *
80 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
81
 *          Returns URT_STATUS_FETCH_NOTOPIC if the subscriber is not associated to a topic.
82
 *          Retruns URT_STATUS_FETCH_NOMESSAGE if there is no new message to fetch.
83 7d9678db skenneweg
 */
84 1fb06240 skenneweg
urt_status_t urtNrtSubscriberFetchNextMessage (urt_nrtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency) {
85 7d9678db skenneweg
  return URT_STATUS_OK;
86 1fb06240 skenneweg
}
87
88 7d9678db skenneweg
/**
89 5198dfae skenneweg
 * @brief Fetches the lates message.
90 7d9678db skenneweg
 *
91 5198dfae skenneweg
 * @param[in] subscriber  The NRT subscriber that shall fetch the message. Must not be NULL.
92
 * @param[in] payload  Pointer where to copy the payload to. May be NULL for messages without payload.
93
 * @param[in] bytes  Payload size in bytes.
94
 * @param[in] latency  The latency can be returned by reference. May be NULL.
95 7d9678db skenneweg
 *
96 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
97
 *          Returns URT_STATUS_FETCH_NOTOPIC if the subscriber is not associated to a topic.
98
 *          Returns URT_STATUS_FETCH_NOMESSAGE if there is no new message to fetch.
99 7d9678db skenneweg
 */
100 1fb06240 skenneweg
urt_status_t urtNrtSubscriberFetchLatestMessage (urt_nrtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency) {
101 7d9678db skenneweg
  return URT_STATUS_OK;
102 1fb06240 skenneweg
}
103
104 7d9678db skenneweg
/**
105 5198dfae skenneweg
 * @brief  Unsubscribes from a subscriber.
106 7d9678db skenneweg
 *
107 5198dfae skenneweg
 * @param[in] subscriber  The NRT subscriber to be unsubscribed. Must not be NULL.
108 7d9678db skenneweg
 *
109 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on sucess.
110
 *          Returns URT_STATUS_UNSUBSCRIBE_NOTOPIC if the subscriber is not associated to a topic.
111 7d9678db skenneweg
 */
112 1fb06240 skenneweg
urt_status_t urtNrtSubscriberUnsubscribe (urt_nrtsubscriber_t* subscriber) {
113 7d9678db skenneweg
  return URT_STATUS_OK;
114 1fb06240 skenneweg
}
115
116 7d9678db skenneweg
117
/**
118 5198dfae skenneweg
 * @brief  Initialize the srt Subscriber.
119 7d9678db skenneweg
 *
120 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber to initialize. Must not be NULL.
121 7d9678db skenneweg
 */
122
void urtSrtSubscriberInit(urt_srtsubscriber_t* subscriber) {return;}
123
124
/**
125 5198dfae skenneweg
 * @brief  Subscribes the subscriber to a topic.
126
 *
127
 * @param[in] subscriber  The SRT subscriber which shall subscribe to a topic. Must not be NULL.
128
 * @param[in] topic  The topic to subscribe to. Must not be NULL.
129
 * @param[in] message  NULL terminated list of messages to contribute to the topic.
130
 *                     Messages must not be associated to another topic.
131
 *                     Once a message has been contributed, it cannot be removed later.
132
 *                     May be NULL (no messages to contribute)
133
 * @param[in] usefulnesscb  Pointer to a function to calculate usefulness of a message. Must not be NULL.
134
 * @param[in] cbparams  Optional parameters for the usefulness callback.
135
 *                      May be NULL if the callback expects no parameters.
136
 *
137
 * @return  Returns URT_STATUS_OK on success.
138
 *          Returns URT_STATUS_SUBSCRIBE_TOPICSET if the subscriber is already associated to a topic.
139 7d9678db skenneweg
 */
140
urt_status_t urtSrtSubscriberSubscribe(urt_srtsubscriber_t* subscriber, urt_topic_t* topic,
141
                                       urt_message_t* message, urt_srtusefulnessfunc_t* usefulnesscb, void* cbparams) {return URT_STATUS_OK;}
142
143
/**
144 5198dfae skenneweg
 * @brief  Fetches the next message.
145 7d9678db skenneweg
 *
146 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber that shall fetch the message. Must not be NULL.
147
 * @param[in] payload  Pointer where to copy the payload to. May be NULL for messages without payload.
148
 * @param[in] bytes  Payload size in bytes.
149
 * @param[in] latency  The latency can be returned by reference. May be NULL.
150 7d9678db skenneweg
 *
151 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
152
 *          Returns URT_STATUS_FETCH_NOTOPIC if the subscriber is not associated to a topic.
153
 *          Returns URT_STATUS_FETCH_NOMESSAGE if there is no new message to fetch.
154 7d9678db skenneweg
 */
155
urt_status_t urtSrtSubscriberFetchNextMessage(urt_srtsubscriber_t* subscriber, void* payload,
156
                                              size_t bytes, urt_delay_t* latency){return URT_STATUS_OK;}
157
158
/**
159 5198dfae skenneweg
 * @brief  Fetches the latest message.
160 7d9678db skenneweg
 *
161 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber that shall fetch the message. Must not be NULL.
162
 * @param[in] payload  Pointer where to copy the payload to. May be NULL for messages without payload.
163
 * @param[in] bytes  Payload size in bytes.
164
 * @param[in] latency  The latency can be returned by reference. May be NULL.
165 7d9678db skenneweg
 *
166 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
167
 *          Returns URT_STATUS_FETCH_NOTOPIC if the subscriber is not associated to a topic.
168
 *          Returns URT_STATUS_FETCH_NOMESSAGE if there is no new message to fetch.
169 7d9678db skenneweg
 */
170
urt_status_t urtSrtSubscriberFetchLatestMessage(urt_srtsubscriber_t* subscriber, void* payload,
171
                                                size_t bytes, urt_delay_t* latency){return URT_STATUS_OK;}
172
173
/**
174 5198dfae skenneweg
 * @brief  Calculates the usefulness of the subscriber.
175 7d9678db skenneweg
 *
176 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber that shall fetch the message. Must not be NULL.
177
 * @param[in] latency  Latency (of a message) as argument to calculate usefulness.
178 7d9678db skenneweg
 *
179 5198dfae skenneweg
 * @return  Returns the usefulness as a value within [0,1].
180 7d9678db skenneweg
 */
181 5198dfae skenneweg
float urtSrtSubscriberCalculateUsefulness(urt_srtsubscriber_t* subscriber, urt_delay_t latency){return 0;}
182 7d9678db skenneweg
183
/**
184 5198dfae skenneweg
 * @brief  Unsubscribes from a subscriber.
185 7d9678db skenneweg
 *
186 5198dfae skenneweg
 * @param[in] subscriber  The NRT subscriber to be unsubscribed. Must not be NULL.
187 7d9678db skenneweg
 *
188 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on sucess.
189
 *          Returns URT_STATUS_UNSUBSCRIBE_NOTOPIC if the subscriber is not associated to a topic.
190 7d9678db skenneweg
 */
191
urt_status_t urtSrtSubscriberUnsubscribe(urt_srtsubscriber_t* subscriber){return URT_STATUS_OK;}
192
193
194
/**
195 5198dfae skenneweg
 * @brief  Initialize the FRT Subscriber.
196 7d9678db skenneweg
 *
197 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber to initialize. Must not be NULL.
198 7d9678db skenneweg
 */
199
void urtFrtSubscriberInit(urt_frtsubscriber_t* subscriber){return URT_STATUS_OK;}
200
201
/**
202 5198dfae skenneweg
 * @brief  Subscribes the subscriber to a topic.
203
 *
204
 * @param[in] subscriber  The NRT subscriber which shall subscribe to a topic. Must not be NULL.
205
 * @param[in] topic  The topic to subscribe to. Must not be NULL.
206
 * @param[in] messages  NULL terminated list of messages to contribute to the topic.
207
 *                      Messages must not be associated to another topic.
208
 *                      Once a message has been contributed, it cannot be removed later.
209
 *                      May be NULL(no messages to contribute).
210
 * @param[in] deadline  Maximum latency to consume messages. A value of 0 indicates that latency is of no concern.
211
 * @param[in] jitter  Maximum allowed jitter (difference between maximum and minimum latency) when consuming messages.
212
 *                    A value of 0 indicates that jitter is of no concern.
213
 *
214
 * @return  Returns URT_STATUS_OK on success.
215
 *          Returns URT_STATUS_SUBSCRIBE_TOPICSET if the subscriber is already associated to a topic.
216 7d9678db skenneweg
 */
217
urt_status_t urtFrtSubscriberSubscribe(urt_frtsubscriber_t* subscriber, urt_topic_t* topic,
218
                                       urt_message_t* messages, urt_delay_t deadline, urt_delay_t jitter){return URT_STATUS_OK;}
219
220
/**
221 5198dfae skenneweg
 * @brief  Fetches the next message.
222 7d9678db skenneweg
 *
223 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber that shall fetch the message. Must not be NULL.
224
 * @param[in] payload  Pointer where to copy the payload to. May be NULL for messages without payload.
225
 * @param[in] bytes  Payload size in bytes.
226
 * @param[in] latency  The latency can be returned by reference. May be NULL.
227 7d9678db skenneweg
 *
228 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
229
 *          Returns URT_STATUS_FETCH_NOTOPIC if the subscriber is not associated to a topic.
230
 *          Returns URT_STATUS_FETCH_NOMESSAGE if there is no new message to fetch.
231 7d9678db skenneweg
 */
232
urt_status_t urtFrtSubscriberFetchNextMessage(urt_frtsubscriber_t* subscriber, void* payload,
233
                                              size_t bytes, urt_delay_t* latency){return URT_STATUS_OK;}
234
235
/**
236 5198dfae skenneweg
 * @brief  Fetches the latest message.
237 7d9678db skenneweg
 *
238 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber that shall fetch the message. Must not be NULL.
239
 * @param[in] payload  Pointer where to copy the payload to. May be NULL for messages without payload.
240
 * @param[in] bytes  Payload size in bytes.
241
 * @param[in] latency  The latency can be returned by reference. May be NULL.
242 7d9678db skenneweg
 *
243 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
244
 *          Returns URT_STATUS_FETCH_NOTOPIC if the subscriber is not associated to a topic.
245
 *          Returns URT_STATUS_FETCH_NOMESSAGE if there is no new message to fetch.
246 7d9678db skenneweg
 */
247
urt_status_t urtFrtSubscriberFetchLatestMessage(urt_frtsubscriber_t* subscriber, void* payload,
248
                                                size_t bytes, urt_delay_t* latency){return URT_STATUS_OK;}
249
250
/**
251 5198dfae skenneweg
 * @brief  Calculates the validity from the subscriber.
252 7d9678db skenneweg
 *
253 5198dfae skenneweg
 * @param[in] subscriber  The FRT subscriber to calculate a validity for. Must not be NULL.
254
 * @param[in] latency  Latency (of a message) as argument to calculate validity.
255 7d9678db skenneweg
 *
256 5198dfae skenneweg
 * @return  Returns a boolean indicator whether the latency is fine.
257 7d9678db skenneweg
 */
258
bool urtFrtSubscriberCalculateValidity(urt_frtsubscriber_t* subscriber, urt_delay_t latency){return true;}
259
260
/**
261 5198dfae skenneweg
 * @brief  Unsubscribes from a subscriber.
262 7d9678db skenneweg
 *
263 5198dfae skenneweg
 * @param[in] subscriber  The NRT subscriber to be unsubscribed. Must not be NULL.
264 7d9678db skenneweg
 *
265 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on sucess.
266
 *          Returns URT_STATUS_UNSUBSCRIBE_NOTOPIC if the subscriber is not associated to a topic.
267 7d9678db skenneweg
 */
268
urt_status_t urtFrtSubscriberUnsubscribe(urt_frtsubscriber_t* subscriber){return URT_STATUS_OK;}
269
270
271
/**
272 5198dfae skenneweg
 * @brief  Initialize the HRT Subscriber.
273 7d9678db skenneweg
 *
274 5198dfae skenneweg
 * @param[in] subscriber  The HRT subscriber to initialize. Must not be NULL.
275 7d9678db skenneweg
 */
276
void urtHrtSubscriberInit(urt_hrtsubscriber_t* subscriber){return;}
277
278
/**
279 5198dfae skenneweg
 * @brief  Subscribes the subscriber to a topic.
280
 *
281
 * @param[in] subscriber  The NRT subscriber which shall subscribe to a topic. Must not be NULL.
282
 * @param[in] topic  The topic to subscribe to. Must not be NULL.
283
 * @param[in] messages  NULL terminated list of messages to contribute to the topic.
284
 *                      Messages must not be associated to another topic.
285
 *                      Once a message has been contributed, it cannot be removed later.
286
 *                      May be NULL(no messages to contribute).
287
 * @param[in] deadline  Maximum latency to consume messages. A value of 0 indicates that latency is of no concern.
288
 * @param[in] rate  Expected minimum rate of new messages (= maximum time between consecutive messages).
289
 *                  A value of 0 indicates, that rate is of no concern.
290
 * @param[in] jitter  Maximum allowed jitter (difference between maximum and minimum latency) when consuming messages.
291
 *                    A value of 0 indicates that jitter is of no concern.
292
 *
293
 * @return  Returns URT_STATUS_OK on success.
294
 *          Returns URT_STATUS_SUBSCRIBE_TOPICSET if the subscriber is already associated to a topic.
295 7d9678db skenneweg
 */
296
urt_status_t urtHrtSubscriberSubscribe(urt_hrtsubscriber_t* subscriber, urt_topic_t* topic,
297
                                       urt_message_t* message, urt_delay_t deadline, urt_delay_t rate, urt_delay_t jitter){return URT_STATUS_OK;}
298
299
300
/**
301 5198dfae skenneweg
 * @brief  Fetches the next message.
302 7d9678db skenneweg
 *
303 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber that shall fetch the message. Must not be NULL.
304
 * @param[in] payload  Pointer where to copy the payload to. May be NULL for messages without payload.
305
 * @param[in] bytes  Payload size in bytes.
306
 * @param[in] latency  The latency can be returned by reference. May be NULL.
307 7d9678db skenneweg
 *
308 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
309
 *          Returns URT_STATUS_FETCH_NOTOPIC if the subscriber is not associated to a topic.
310
 *          Returns URT_STATUS_FETCH_NOMESSAGE if there is no new message to fetch.
311 7d9678db skenneweg
 */
312
urt_status_t urtHrtSubscriberFetchNextMessage(urt_hrtsubscriber_t* subscriber, void* payload,
313
                                              size_t bytes, urt_delay_t* latency){return URT_STATUS_OK;}
314
315
316
/**
317 5198dfae skenneweg
 * @brief  Fetches the latest message.
318 7d9678db skenneweg
 *
319 5198dfae skenneweg
 * @param[in] subscriber  The SRT subscriber that shall fetch the message. Must not be NULL.
320
 * @param[in] payload  Pointer where to copy the payload to. May be NULL for messages without payload.
321
 * @param[in] bytes  Payload size in bytes.
322
 * @param[in] latency  The latency can be returned by reference. May be NULL.
323 7d9678db skenneweg
 *
324 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on success.
325
 *          Returns URT_STATUS_FETCH_NOTOPIC if the subscriber is not associated to a topic.
326
 *          Returns URT_STATUS_FETCH_NOMESSAGE if there is no new message to fetch.
327 7d9678db skenneweg
 */
328
urt_status_t urtHrtSubscriberFetchLatestMessage(urt_hrtsubscriber_t* subscriber, void* payload,
329
                                                size_t bytes, urt_delay_t* latency){return URT_STATUS_OK;}
330
331
/**
332 5198dfae skenneweg
 * @brief  Unsubscribes from a subscriber.
333 7d9678db skenneweg
 *
334 5198dfae skenneweg
 * @param[in] subscriber  The HRT subscriber to be unsubscribed. Must not be NULL.
335 7d9678db skenneweg
 *
336 5198dfae skenneweg
 * @return  Returns URT_STATUS_OK on sucess.
337
 *          Returns URT_STATUS_UNSUBSCRIBE_NOTOPIC if the subscriber is not associated to a topic.
338 7d9678db skenneweg
 */
339
urt_status_t urtHrtSubscriberUnsubscribe(urt_hrtsubscriber_t* subscriber){return URT_STATUS_OK;}