Statistics
| Branch: | Revision:

urtware / src / urt_subscriber.c @ 5198dfae

History | View | Annotate | Download (16.088 KB)

1
/*
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
#include <urtware.h>
23

    
24
/******************************************************************************/
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
/**
49
 * @brief   Initialize the nrt Subscriber.
50
 *
51
 * @param[in] subscriber  The NRT subscriber to initialize. Must not be NULL.
52
 */
53
void urtNrtSubscriberInit (urt_nrtsubscriber_t* subscriber) {return;}
54

    
55
/**
56
 * @brief  Subscribes the subscriber to a topic.
57
 *
58
 * @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
 *
65
 * @return  Returns URT_STATUS_OK on success.
66
 *          Returns URT_STATUS_SUBSCRIBE_TOPICSET if the subscriber is already associated to a topic.
67
 */
68
urt_status_t urtNrtSubscriberSubscribe (urt_nrtsubscriber_t* subscriber, urt_topic_t* topic, urt_message_t* messages) {
69
  return URT_STATUS_OK;
70
}
71

    
72
/**
73
 * @brief  Fetches the next message.
74
 *
75
 * @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
 *
80
 * @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
 */
84
urt_status_t urtNrtSubscriberFetchNextMessage (urt_nrtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency) {
85
  return URT_STATUS_OK;
86
}
87

    
88
/**
89
 * @brief Fetches the lates message.
90
 *
91
 * @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
 *
96
 * @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
 */
100
urt_status_t urtNrtSubscriberFetchLatestMessage (urt_nrtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency) {
101
  return URT_STATUS_OK;
102
}
103

    
104
/**
105
 * @brief  Unsubscribes from a subscriber.
106
 *
107
 * @param[in] subscriber  The NRT subscriber to be unsubscribed. Must not be NULL.
108
 *
109
 * @return  Returns URT_STATUS_OK on sucess.
110
 *          Returns URT_STATUS_UNSUBSCRIBE_NOTOPIC if the subscriber is not associated to a topic.
111
 */
112
urt_status_t urtNrtSubscriberUnsubscribe (urt_nrtsubscriber_t* subscriber) {
113
  return URT_STATUS_OK;
114
}
115

    
116

    
117
/**
118
 * @brief  Initialize the srt Subscriber.
119
 *
120
 * @param[in] subscriber  The SRT subscriber to initialize. Must not be NULL.
121
 */
122
void urtSrtSubscriberInit(urt_srtsubscriber_t* subscriber) {return;}
123

    
124
/**
125
 * @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
 */
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
 * @brief  Fetches the next message.
145
 *
146
 * @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
 *
151
 * @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
 */
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
 * @brief  Fetches the latest message.
160
 *
161
 * @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
 *
166
 * @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
 */
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
 * @brief  Calculates the usefulness of the subscriber.
175
 *
176
 * @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
 *
179
 * @return  Returns the usefulness as a value within [0,1].
180
 */
181
float urtSrtSubscriberCalculateUsefulness(urt_srtsubscriber_t* subscriber, urt_delay_t latency){return 0;}
182

    
183
/**
184
 * @brief  Unsubscribes from a subscriber.
185
 *
186
 * @param[in] subscriber  The NRT subscriber to be unsubscribed. Must not be NULL.
187
 *
188
 * @return  Returns URT_STATUS_OK on sucess.
189
 *          Returns URT_STATUS_UNSUBSCRIBE_NOTOPIC if the subscriber is not associated to a topic.
190
 */
191
urt_status_t urtSrtSubscriberUnsubscribe(urt_srtsubscriber_t* subscriber){return URT_STATUS_OK;}
192

    
193

    
194
/**
195
 * @brief  Initialize the FRT Subscriber.
196
 *
197
 * @param[in] subscriber  The SRT subscriber to initialize. Must not be NULL.
198
 */
199
void urtFrtSubscriberInit(urt_frtsubscriber_t* subscriber){return URT_STATUS_OK;}
200

    
201
/**
202
 * @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
 */
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
 * @brief  Fetches the next message.
222
 *
223
 * @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
 *
228
 * @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
 */
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
 * @brief  Fetches the latest message.
237
 *
238
 * @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
 *
243
 * @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
 */
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
 * @brief  Calculates the validity from the subscriber.
252
 *
253
 * @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
 *
256
 * @return  Returns a boolean indicator whether the latency is fine.
257
 */
258
bool urtFrtSubscriberCalculateValidity(urt_frtsubscriber_t* subscriber, urt_delay_t latency){return true;}
259

    
260
/**
261
 * @brief  Unsubscribes from a subscriber.
262
 *
263
 * @param[in] subscriber  The NRT subscriber to be unsubscribed. Must not be NULL.
264
 *
265
 * @return  Returns URT_STATUS_OK on sucess.
266
 *          Returns URT_STATUS_UNSUBSCRIBE_NOTOPIC if the subscriber is not associated to a topic.
267
 */
268
urt_status_t urtFrtSubscriberUnsubscribe(urt_frtsubscriber_t* subscriber){return URT_STATUS_OK;}
269

    
270

    
271
/**
272
 * @brief  Initialize the HRT Subscriber.
273
 *
274
 * @param[in] subscriber  The HRT subscriber to initialize. Must not be NULL.
275
 */
276
void urtHrtSubscriberInit(urt_hrtsubscriber_t* subscriber){return;}
277

    
278
/**
279
 * @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
 */
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
 * @brief  Fetches the next message.
302
 *
303
 * @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
 *
308
 * @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
 */
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
 * @brief  Fetches the latest message.
318
 *
319
 * @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
 *
324
 * @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
 */
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
 * @brief  Unsubscribes from a subscriber.
333
 *
334
 * @param[in] subscriber  The HRT subscriber to be unsubscribed. Must not be NULL.
335
 *
336
 * @return  Returns URT_STATUS_OK on sucess.
337
 *          Returns URT_STATUS_UNSUBSCRIBE_NOTOPIC if the subscriber is not associated to a topic.
338
 */
339
urt_status_t urtHrtSubscriberUnsubscribe(urt_hrtsubscriber_t* subscriber){return URT_STATUS_OK;}