urtware / inc / urt_subscriber.h @ 8378a78b
History | View | Annotate | Download (7.4 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 |
#ifndef URTWARE_SUBSCRIBER_H
|
23 |
#define URTWARE_SUBSCRIBER_H
|
24 |
|
25 |
#include <urtware.h> |
26 |
|
27 |
/******************************************************************************/
|
28 |
/* CONSTANTS */
|
29 |
/******************************************************************************/
|
30 |
|
31 |
/******************************************************************************/
|
32 |
/* SETTINGS */
|
33 |
/******************************************************************************/
|
34 |
|
35 |
/******************************************************************************/
|
36 |
/* CHECKS */
|
37 |
/******************************************************************************/
|
38 |
|
39 |
/******************************************************************************/
|
40 |
/* DATA STRUCTURES AND TYPES */
|
41 |
/******************************************************************************/
|
42 |
|
43 |
/**
|
44 |
* @brief Base subscriber
|
45 |
* @details The base subscriber is included in each specialized subscriber
|
46 |
*/
|
47 |
typedef struct urt_basesubscriber |
48 |
{ |
49 |
urt_topic_t* topic; |
50 |
urt_osEventListener_t evtListener; |
51 |
urt_message_t* lastMessage; |
52 |
urt_osTime_t lastMessageTime; |
53 |
#if (URT_CFG_PUBSUB_PROFILING)
|
54 |
uint64_t sumLatencies; |
55 |
uint64_t numMessagesReceived; |
56 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
57 |
}urt_basesubscriber_t; |
58 |
|
59 |
/**
|
60 |
* @brief nrt subscriber
|
61 |
*/
|
62 |
typedef struct urt_nrtsubscriber |
63 |
{ |
64 |
urt_basesubscriber_t base; |
65 |
#if (URT_CFG_PUBSUB_PROFILING)
|
66 |
urt_delay_t minLatency; |
67 |
urt_delay_t maxLatency; |
68 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
69 |
}urt_nrtsubscriber_t; |
70 |
|
71 |
/**
|
72 |
* @brief srt subscriber
|
73 |
*/
|
74 |
typedef struct urt_srtsubscriber |
75 |
{ |
76 |
urt_basesubscriber_t base; |
77 |
void* cbparams;
|
78 |
urt_usefulness_f* usefulnesscb; |
79 |
#if (URT_CFG_PUBSUB_PROFILING)
|
80 |
urt_delay_t minLatency; |
81 |
urt_delay_t maxLatency; |
82 |
#endif /* URT_CFG_PUBSUB_PROFILING */ |
83 |
}urt_srtsubscriber_t; |
84 |
|
85 |
/**
|
86 |
* @brief frt subscriber
|
87 |
*/
|
88 |
typedef struct urt_frtsubscriber |
89 |
{ |
90 |
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 |
}urt_frtsubscriber_t; |
102 |
|
103 |
/**
|
104 |
* @brief nrt subscriber
|
105 |
*/
|
106 |
typedef struct urt_hrtsubscriber |
107 |
{ |
108 |
urt_basesubscriber_t base; |
109 |
struct urt_hrtsubscriber* 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 |
}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 |
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* messages, urt_usefulness_f* 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 |
float urtSrtSubscriberCalculateUsefulness(urt_srtsubscriber_t* subscriber, urt_delay_t latency);
|
149 |
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* messages, 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 |
#if defined(__cplusplus)
|
164 |
} |
165 |
#endif /* defined(__cplusplus) */ |
166 |
|
167 |
/******************************************************************************/
|
168 |
/* INLINE FUNCTIONS */
|
169 |
/******************************************************************************/
|
170 |
|
171 |
#endif /* URTWARE_SUBSCRIBER_H */ |