urtware / inc / urt_subscriber.h @ 67844205
History | View | Annotate | Download (7.476 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 | #ifndef URTWARE_SUBSCRIBER_H
|
||
23 | #define URTWARE_SUBSCRIBER_H
|
||
24 | |||
25 | #include <urt_types.h> |
||
26 | 7d9678db | skenneweg | #include <urtware.h> |
27 | 1fb06240 | skenneweg | |
28 | /******************************************************************************/
|
||
29 | /* CONSTANTS */
|
||
30 | /******************************************************************************/
|
||
31 | |||
32 | /******************************************************************************/
|
||
33 | /* SETTINGS */
|
||
34 | /******************************************************************************/
|
||
35 | |||
36 | /******************************************************************************/
|
||
37 | /* CHECKS */
|
||
38 | /******************************************************************************/
|
||
39 | |||
40 | /******************************************************************************/
|
||
41 | /* DATA STRUCTURES AND TYPES */
|
||
42 | /******************************************************************************/
|
||
43 | |||
44 | /**
|
||
45 | * @brief Base subscriber
|
||
46 | * @details The base subscriber is included in each specialized subscriber
|
||
47 | */
|
||
48 | typedef struct urt_basesubscriber |
||
49 | { |
||
50 | cd21e832 | skenneweg | urt_topic_t* topic; |
51 | urt_osEventListener_t evtListener; |
||
52 | urt_message_t* lastMessage; |
||
53 | urt_osTime_t lastMessageTime; |
||
54 | #if (URT_CFG_PUBSUB_PROFILING)
|
||
55 | uint64_t sumLatencies; |
||
56 | uint64_t numMessagesReceived; |
||
57 | #endif /* URT_CFG_PUBSUB_PROFILING */ |
||
58 | 1fb06240 | skenneweg | }urt_basesubscriber_t; |
59 | |||
60 | /**
|
||
61 | * @brief nrt subscriber
|
||
62 | */
|
||
63 | typedef struct urt_nrtsubscriber |
||
64 | { |
||
65 | cd21e832 | skenneweg | urt_basesubscriber_t base; |
66 | #if (URT_CFG_PUBSUB_PROFILING)
|
||
67 | urt_delay_t minLatency; |
||
68 | urt_delay_t maxLatency; |
||
69 | #endif /* URT_CFG_PUBSUB_PROFILING */ |
||
70 | 1fb06240 | skenneweg | }urt_nrtsubscriber_t; |
71 | |||
72 | /**
|
||
73 | * @brief nrt subscriber
|
||
74 | */
|
||
75 | typedef struct urt_srtsubscriber |
||
76 | { |
||
77 | cd21e832 | skenneweg | urt_basesubscriber_t base; |
78 | urt_srtusefulnessfunc_t* usefulnesscb; |
||
79 | #if (URT_CFG_PUBSUB_PROFILING)
|
||
80 | urt_delay_t minLatency; |
||
81 | urt_delay_t maxLatency; |
||
82 | #endif /* URT_CFG_PUBSUB_PROFILING */ |
||
83 | 1fb06240 | skenneweg | }urt_srtsubscriber_t; |
84 | |||
85 | /**
|
||
86 | * @brief nrt subscriber
|
||
87 | */
|
||
88 | typedef struct urt_frtsubscriber |
||
89 | { |
||
90 | cd21e832 | skenneweg | urt_basesubscriber_t base; |
91 | #if (URT_CFG_PUBSUB_QOS_DEADLINECHECKS)
|
||
92 | urt_delay_t deadlineOffset; |
||
93 | #endif /* URT_CFG_PUBSUB_QOS_DEADLINECHECKS */ |
||
94 | #if (URT_CFG_PUBSUB_QOS_JITTERCHECKS)
|
||
95 | urt_delay_t maxJitter; |
||
96 | #endif /* URT_CFG_PUBSUB_QOS_JITTERCHECKS */ |
||
97 | #if (URT_CFG_PUBSUB_QOS_JITTERCHECKS || URT_CFG_PUBSUB_PROFILING)
|
||
98 | urt_delay_t minLatency; |
||
99 | urt_delay_t maxLatency; |
||
100 | #endif /* URT_CFG_PUBSUB_QOS_JITTERCHECKS || URT_CFG_PUBSUB_PROFILING */ |
||
101 | 1fb06240 | skenneweg | }urt_frtsubscriber_t; |
102 | |||
103 | /**
|
||
104 | * @brief nrt subscriber
|
||
105 | */
|
||
106 | typedef struct urt_hrtsubscriber |
||
107 | { |
||
108 | cd21e832 | skenneweg | urt_basesubscriber_t base; |
109 | urt_hrtsubscriber_t* next; |
||
110 | #if (URT_CFG_PUBSUB_QOS_DEADLINECHECKS)
|
||
111 | urt_delay_t deadlineOffset; |
||
112 | urt_osTimer_t qosDeadlineTimer; |
||
113 | #endif /* URT_CFG_PUBSUB_QOS_DEADLINECHECKS */ |
||
114 | #if (URT_CFG_PUBSUB_QOS_JITTERCHECKS)
|
||
115 | urt_delay_t maxJitter; |
||
116 | #endif /* URT_CFG_PUBSUB_QOS_JITTERCHECKS */ |
||
117 | #if (URT_CFG_PUBSUB_QOS_JITTERCHECKS || URT_CFG_PUBSUB_PROFILING)
|
||
118 | urt_delay_t minLatency; |
||
119 | urt_delay_t maxLatency; |
||
120 | #endif /* URT_CFG_PUBSUB_QOS_JITTERCHECKS || URT_CFG_PUBSUB_PROFILING */ |
||
121 | #if (URT_CFG_PUBSUB_QOS_RATECHECKS)
|
||
122 | urt_delay_t expectedRate; |
||
123 | #endif /* URT_CFG_PUBSUB_QOS_RATECHECKS */ |
||
124 | 1fb06240 | skenneweg | }urt_hrtsubscriber_t; |
125 | |||
126 | /******************************************************************************/
|
||
127 | /* MACROS */
|
||
128 | /******************************************************************************/
|
||
129 | |||
130 | /******************************************************************************/
|
||
131 | /* EXTERN DECLARATIONS */
|
||
132 | /******************************************************************************/
|
||
133 | |||
134 | #if defined(__cplusplus)
|
||
135 | extern "C" { |
||
136 | #endif /* defined(__cplusplus) */ |
||
137 | |||
138 | cd21e832 | skenneweg | void urtNrtSubscriberInit(urt_nrtsubscriber_t* subscriber);
|
139 | urt_status_t urtNrtSubscriberSubscribe(urt_nrtsubscriber_t* subscriber, urt_topic_t* topic, urt_message_t* messages); |
||
140 | urt_status_t urtNrtSubscriberFetchNextMessage(urt_nrtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency);
|
||
141 | urt_status_t urtNrtSubscriberFetchLatestMessage(urt_nrtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency);
|
||
142 | urt_status_t urtNrtSubscriberUnsubscribe(urt_nrtsubscriber_t* subscriber); |
||
143 | |||
144 | void urtSrtSubscriberInit(urt_srtsubscriber_t* subscriber);
|
||
145 | urt_status_t urtSrtSubscriberSubscribe(urt_srtsubscriber_t* subscriber, urt_topic_t* topic, urt_message_t* message, urt_srtusefulnessfunc_t* usefulnesscb, void* cbparams);
|
||
146 | urt_status_t urtSrtSubscriberFetchNextMessage(urt_srtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency);
|
||
147 | urt_status_t urtSrtSubscriberFetchLatestMessage(urt_srtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency);
|
||
148 | 5198dfae | skenneweg | float urtSrtSubscriberCalculateUsefulness(urt_srtsubscriber_t* subscriber, urt_delay_t latency);
|
149 | cd21e832 | skenneweg | urt_status_t urtSrtSubscriberUnsubscribe(urt_srtsubscriber_t* subscriber); |
150 | |||
151 | void urtFrtSubscriberInit(urt_frtsubscriber_t* subscriber);
|
||
152 | urt_status_t urtFrtSubscriberSubscribe(urt_frtsubscriber_t* subscriber, urt_topic_t* topic, urt_message_t* messages, urt_delay_t deadline, urt_delay_t jitter); |
||
153 | urt_status_t urtFrtSubscriberFetchNextMessage(urt_frtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency);
|
||
154 | urt_status_t urtFrtSubscriberFetchLatestMessage(urt_frtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency);
|
||
155 | bool urtFrtSubscriberCalculateValidity(urt_frtsubscriber_t* subscriber, urt_delay_t latency);
|
||
156 | urt_status_t urtFrtSubscriberUnsubscribe(urt_frtsubscriber_t* subscriber); |
||
157 | |||
158 | void urtHrtSubscriberInit(urt_hrtsubscriber_t* subscriber);
|
||
159 | urt_status_t urtHrtSubscriberSubscribe(urt_hrtsubscriber_t* subscriber, urt_topic_t* topic, urt_message_t* message, urt_delay_t deadline, urt_delay_t rate, urt_delay_t jitter); |
||
160 | urt_status_t urtHrtSubscriberFetchNextMessage(urt_hrtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency);
|
||
161 | urt_status_t urtHrtSubscriberFetchLatestMessage(urt_hrtsubscriber_t* subscriber, void* payload, size_t bytes, urt_delay_t* latency);
|
||
162 | urt_status_t urtHrtSubscriberUnsubscribe(urt_hrtsubscriber_t* subscriber); |
||
163 | 017b2ac7 | skenneweg | |
164 | float urt_srtusefulnessfunc_t (urt_delay_t dt, void* params); |
||
165 | 1fb06240 | skenneweg | #if defined(__cplusplus)
|
166 | } |
||
167 | #endif /* defined(__cplusplus) */ |
||
168 | |||
169 | /******************************************************************************/
|
||
170 | /* INLINE FUNCTIONS */
|
||
171 | /******************************************************************************/
|
||
172 | |||
173 | #endif /* URTWARE_SUBSCRIBER_H */ |