/src/Fast-DDS/include/fastdds/statistics/rtps/StatisticsCommon.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2021 Proyectos y Sistemas de Mantenimiento SL (eProsima). |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | |
15 | | /** |
16 | | * @file StatisticsCommon.hpp |
17 | | */ |
18 | | |
19 | | #ifndef FASTDDS_STATISTICS_RTPS__STATISTICSCOMMON_HPP |
20 | | #define FASTDDS_STATISTICS_RTPS__STATISTICSCOMMON_HPP |
21 | | |
22 | | #include <memory> |
23 | | #include <type_traits> |
24 | | |
25 | | #include <fastdds/rtps/common/Guid.hpp> |
26 | | #include <fastdds/rtps/common/SampleIdentity.hpp> |
27 | | #include <fastdds/rtps/common/Time_t.hpp> |
28 | | #include <fastdds/statistics/IListeners.hpp> |
29 | | #include <fastdds/utils/TimedMutex.hpp> |
30 | | |
31 | | |
32 | | namespace eprosima { |
33 | | |
34 | | namespace fastdds { |
35 | | namespace rtps { |
36 | | |
37 | | class RTPSMessageGroup; |
38 | | |
39 | | } // rtps |
40 | | |
41 | | namespace statistics { |
42 | | |
43 | | #ifdef FASTDDS_STATISTICS |
44 | | |
45 | | // Members are private details |
46 | | struct StatisticsAncillary; |
47 | | |
48 | | class StatisticsListenersImpl |
49 | | { |
50 | | std::unique_ptr<StatisticsAncillary> members_; |
51 | | |
52 | | protected: |
53 | | |
54 | | /** |
55 | | * Create a class A auxiliary structure |
56 | | * @return true if successfully created |
57 | | */ |
58 | | template<class A> |
59 | | void init_statistics() |
60 | 0 | { |
61 | 0 | static_assert( |
62 | 0 | std::is_base_of<StatisticsAncillary, A>::value, |
63 | 0 | "Auxiliary structure must derive from StatisticsAncillary"); |
64 | |
|
65 | 0 | if (!members_) |
66 | 0 | { |
67 | 0 | members_.reset(new A); |
68 | 0 | } |
69 | 0 | } Unexecuted instantiation: void eprosima::fastdds::statistics::StatisticsListenersImpl::init_statistics<eprosima::fastdds::statistics::StatisticsReaderAncillary>() Unexecuted instantiation: void eprosima::fastdds::statistics::StatisticsListenersImpl::init_statistics<eprosima::fastdds::statistics::StatisticsWriterAncillary>() |
70 | | |
71 | | /** |
72 | | * Returns the auxiliary members |
73 | | * @return The specialized auxiliary structure for each class |
74 | | */ |
75 | | StatisticsAncillary* get_aux_members() const; |
76 | | |
77 | | /** |
78 | | * Add a listener to receive statistics backend callbacks |
79 | | * @param listener |
80 | | * @return true if successfully added |
81 | | */ |
82 | | bool add_statistics_listener_impl( |
83 | | std::shared_ptr<fastdds::statistics::IListener> listener); |
84 | | |
85 | | /** |
86 | | * Remove a listener from receiving statistics backend callbacks |
87 | | * @param listener |
88 | | * @return true if successfully removed |
89 | | */ |
90 | | bool remove_statistics_listener_impl( |
91 | | std::shared_ptr<fastdds::statistics::IListener> listener); |
92 | | |
93 | | /** |
94 | | * @brief Set the enabled statistics writers mask |
95 | | * |
96 | | * @param enabled_writers The new mask to set |
97 | | */ |
98 | | void set_enabled_statistics_writers_mask_impl( |
99 | | uint32_t enabled_writers); |
100 | | |
101 | | /** |
102 | | * @brief Check whether the statistics writers in the input mask are enabled |
103 | | * |
104 | | * @param checked_enabled_writers The mask of writers to check |
105 | | * @return True if all enabled, false otherwise |
106 | | */ |
107 | | bool are_statistics_writers_enabled( |
108 | | uint32_t checked_enabled_writers); |
109 | | |
110 | | /** |
111 | | * Lambda function to traverse the listener collection |
112 | | * @param f function object to apply to each listener |
113 | | * @return function object after being applied to each listener |
114 | | */ |
115 | | template<class Function> |
116 | | Function for_each_listener( |
117 | | Function f); |
118 | | |
119 | | /** |
120 | | * Retrieve endpoint mutexes from derived class |
121 | | * @return defaults to the endpoint mutex |
122 | | */ |
123 | | virtual fastdds::RecursiveTimedMutex& get_statistics_mutex() = 0; |
124 | | |
125 | | /** |
126 | | * Retrieve the GUID_t from derived class |
127 | | * @return endpoint GUID_t |
128 | | */ |
129 | | virtual const fastdds::rtps::GUID_t& get_guid() const = 0; |
130 | | }; |
131 | | |
132 | | // Members are private details |
133 | | struct StatisticsWriterAncillary; |
134 | | |
135 | | class StatisticsWriterImpl |
136 | | : protected StatisticsListenersImpl |
137 | | { |
138 | | friend class fastdds::rtps::RTPSMessageGroup; |
139 | | |
140 | | /** |
141 | | * Create the auxiliary structure |
142 | | * @return nullptr on failure |
143 | | */ |
144 | | StatisticsWriterAncillary* get_members() const; |
145 | | |
146 | | /** |
147 | | * Retrieve endpoint mutexes from derived class |
148 | | * @return defaults to the endpoint mutex |
149 | | */ |
150 | | fastdds::RecursiveTimedMutex& get_statistics_mutex() final; |
151 | | |
152 | | /** |
153 | | * Retrieve the GUID_t from derived class |
154 | | * @return endpoint GUID_t |
155 | | */ |
156 | | const fastdds::rtps::GUID_t& get_guid() const final; |
157 | | |
158 | | protected: |
159 | | |
160 | | /** |
161 | | * Constructor. Mandatory member initialization. |
162 | | */ |
163 | | StatisticsWriterImpl(); |
164 | | |
165 | | // TODO: methods for listeners callbacks |
166 | | |
167 | | /** |
168 | | * @brief Report a change on the number of DATA / DATAFRAG submessages sent for a specific sample. |
169 | | * @param sample_identity SampleIdentity of the affected sample. |
170 | | * @param num_sent_submessages Current total number of submessages sent for the affected sample. |
171 | | */ |
172 | | void on_sample_datas( |
173 | | const fastdds::rtps::SampleIdentity& sample_identity, |
174 | | size_t num_sent_submessages); |
175 | | |
176 | | /** |
177 | | * @brief Report that a HEARTBEAT message is sent |
178 | | * @param current count of heartbeats |
179 | | */ |
180 | | void on_heartbeat( |
181 | | uint32_t count); |
182 | | |
183 | | /** |
184 | | * @brief Report that a DATA / DATA_FRAG message is generated |
185 | | * @param num_destinations number of locators to which the message will be sent |
186 | | */ |
187 | | void on_data_generated( |
188 | | size_t num_destinations); |
189 | | |
190 | | /// Notify listeners of DATA / DATA_FRAG counts |
191 | | void on_data_sent(); |
192 | | |
193 | | /** |
194 | | * @brief Reports publication throughtput based on last added sample to writer's history |
195 | | * @param payload size of the message sent |
196 | | */ |
197 | | void on_publish_throughput( |
198 | | uint32_t payload); |
199 | | |
200 | | /// Report that a GAP message is sent |
201 | | void on_gap(); |
202 | | |
203 | | /* |
204 | | * @brief Report that several changes are marked for redelivery |
205 | | * @param number of changes to redeliver |
206 | | */ |
207 | | void on_resent_data( |
208 | | uint32_t to_send); |
209 | | }; |
210 | | |
211 | | // Members are private details |
212 | | struct StatisticsReaderAncillary; |
213 | | |
214 | | class StatisticsReaderImpl |
215 | | : protected StatisticsListenersImpl |
216 | | { |
217 | | friend class fastdds::rtps::RTPSMessageGroup; |
218 | | |
219 | | /** |
220 | | * Create the auxiliary structure |
221 | | * @return nullptr on failure |
222 | | */ |
223 | | StatisticsReaderAncillary* get_members() const; |
224 | | |
225 | | /** |
226 | | * Retrieve endpoint mutexes from derived class |
227 | | * @return defaults to the endpoint mutex |
228 | | */ |
229 | | fastdds::RecursiveTimedMutex& get_statistics_mutex() final; |
230 | | |
231 | | /** |
232 | | * Retrieve the GUID_t from derived class |
233 | | * @return endpoint GUID_t |
234 | | */ |
235 | | const fastdds::rtps::GUID_t& get_guid() const final; |
236 | | |
237 | | protected: |
238 | | |
239 | | /** |
240 | | * Constructor. Mandatory member initialization. |
241 | | */ |
242 | | StatisticsReaderImpl(); |
243 | | |
244 | | // TODO: methods for listeners callbacks |
245 | | |
246 | | /** |
247 | | * @brief Report that a sample has been notified to the user. |
248 | | * @param writer_guid GUID of the writer from where the sample was received. |
249 | | * @param source_timestamp Source timestamp received from the writer for the sample being notified. |
250 | | */ |
251 | | void on_data_notify( |
252 | | const fastdds::rtps::GUID_t& writer_guid, |
253 | | const fastdds::rtps::Time_t& source_timestamp); |
254 | | |
255 | | /** |
256 | | * @brief Report that an ACKNACK message is sent |
257 | | * @param count current count of ACKNACKs |
258 | | */ |
259 | | void on_acknack( |
260 | | int32_t count); |
261 | | |
262 | | /** |
263 | | * @brief Report that a NACKFRAG message is sent |
264 | | * @param count current count of NACKFRAGs |
265 | | */ |
266 | | void on_nackfrag( |
267 | | int32_t count); |
268 | | |
269 | | /** |
270 | | * @brief Reports subscription throughtput based on last added sample to reader's history |
271 | | * @param payload size of the message received |
272 | | */ |
273 | | void on_subscribe_throughput( |
274 | | uint32_t payload); |
275 | | }; |
276 | | |
277 | | #else // when FASTDDS_STATISTICS is not defined a dummy implementation is used |
278 | | |
279 | | class StatisticsWriterImpl |
280 | | { |
281 | | friend class fastdds::rtps::RTPSMessageGroup; |
282 | | |
283 | | protected: |
284 | | |
285 | | // TODO: methods for listeners callbacks |
286 | | |
287 | | /** |
288 | | * @brief Report a change on the number of DATA / DATAFRAG submessages sent for a specific sample. |
289 | | * Parameter: SampleIdentity of the affected sample. |
290 | | * Parameter: Current total number of submessages sent for the affected sample. |
291 | | */ |
292 | | inline void on_sample_datas( |
293 | | const fastdds::rtps::SampleIdentity&, |
294 | | size_t) |
295 | | { |
296 | | } |
297 | | |
298 | | /** |
299 | | * @brief Report that a HEARTBEAT message is sent |
300 | | * Parameter: current count of heartbeats |
301 | | */ |
302 | | inline void on_heartbeat( |
303 | | uint32_t) |
304 | | { |
305 | | } |
306 | | |
307 | | /** |
308 | | * @brief Report that a DATA / DATA_FRAG message is generated |
309 | | * Parameter: number of locators to which the message will be sent |
310 | | */ |
311 | | inline void on_data_generated( |
312 | | size_t) |
313 | | { |
314 | | } |
315 | | |
316 | | /// Notify listeners of DATA / DATA_FRAG counts |
317 | | inline void on_data_sent() |
318 | | { |
319 | | } |
320 | | |
321 | | /** |
322 | | * @brief Reports publication throughtput based on last added sample to writer's history |
323 | | * Parameter: size of the message sent |
324 | | */ |
325 | | inline void on_publish_throughput( |
326 | | uint32_t) |
327 | | { |
328 | | } |
329 | | |
330 | | /// Report that a GAP message is sent |
331 | | inline void on_gap() |
332 | | { |
333 | | } |
334 | | |
335 | | /* |
336 | | * @brief Report that several changes are marked for redelivery |
337 | | * Parameter: number of changes to redeliver |
338 | | */ |
339 | | inline void on_resent_data( |
340 | | uint32_t) |
341 | | { |
342 | | } |
343 | | |
344 | | }; |
345 | | |
346 | | class StatisticsReaderImpl |
347 | | { |
348 | | friend class fastdds::rtps::RTPSMessageGroup; |
349 | | |
350 | | protected: |
351 | | |
352 | | // TODO: methods for listeners callbacks |
353 | | |
354 | | /** |
355 | | * @brief Report that a sample has been notified to the user. |
356 | | * Parameter: GUID of the writer from where the sample was received. |
357 | | * Parameter: Source timestamp received from the writer for the sample being notified. |
358 | | */ |
359 | | inline void on_data_notify( |
360 | | const fastdds::rtps::GUID_t&, |
361 | | const fastdds::rtps::Time_t&) |
362 | | { |
363 | | } |
364 | | |
365 | | /** |
366 | | * @brief Report that an ACKNACK message is sent |
367 | | * Parameter: current count of ACKNACKs |
368 | | */ |
369 | | inline void on_acknack( |
370 | | int32_t) |
371 | | { |
372 | | } |
373 | | |
374 | | /** |
375 | | * @brief Report that a NACKFRAG message is sent |
376 | | * Parameter: current count of NACKFRAGs |
377 | | */ |
378 | | inline void on_nackfrag( |
379 | | int32_t) |
380 | | { |
381 | | } |
382 | | |
383 | | /** |
384 | | * @brief Reports subscription throughtput based on last added sample to reader's history |
385 | | * Parameter: size of the message received |
386 | | */ |
387 | | inline void on_subscribe_throughput( |
388 | | uint32_t) |
389 | | { |
390 | | } |
391 | | |
392 | | }; |
393 | | |
394 | | #endif // FASTDDS_STATISTICS |
395 | | |
396 | | } // namespace statistics |
397 | | } // namespace fastdds |
398 | | } // namespace eprosima |
399 | | |
400 | | #endif // FASTDDS_STATISTICS_RTPS__STATISTICSCOMMON_HPP |