-
Notifications
You must be signed in to change notification settings - Fork 942
Expand file tree
/
Copy pathRTPSReader.h
More file actions
536 lines (463 loc) · 17.8 KB
/
Copy pathRTPSReader.h
File metadata and controls
536 lines (463 loc) · 17.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
// Copyright 2016 Proyectos y Sistemas de Mantenimiento SL (eProsima).
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @file RTPSReader.h
*/
#ifndef _FASTDDS_RTPS_READER_RTPSREADER_H_
#define _FASTDDS_RTPS_READER_RTPSREADER_H_
#include <functional>
#include <fastdds/rtps/attributes/ReaderAttributes.h>
#include <fastdds/rtps/builtin/data/WriterProxyData.h>
#include <fastdds/rtps/common/SequenceNumber.h>
#include <fastdds/rtps/common/Time_t.h>
#include <fastdds/rtps/common/VendorId_t.hpp>
#include <fastdds/rtps/Endpoint.h>
#include <fastdds/rtps/history/ReaderHistory.h>
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
#include <fastdds/statistics/rtps/monitor_service/connections_fwd.hpp>
#include <fastdds/statistics/rtps/StatisticsCommon.hpp>
#include <fastrtps/qos/LivelinessChangedStatus.h>
#include <fastrtps/utils/TimedConditionVariable.hpp>
namespace eprosima {
namespace fastrtps {
namespace rtps {
// Forward declarations
class LivelinessManager;
class ReaderListener;
class WriterProxy;
struct CacheChange_t;
struct ReaderHistoryState;
class WriterProxyData;
class IDataSharingListener;
/**
* Class RTPSReader, manages the reception of data from its matched writers.
* @ingroup READER_MODULE
*/
class RTPSReader
: public Endpoint
, public fastdds::statistics::StatisticsReaderImpl
{
friend class ReaderHistory;
friend class RTPSParticipantImpl;
friend class MessageReceiver;
friend class EDP;
friend class WLP;
protected:
RTPSReader(
RTPSParticipantImpl* pimpl,
const GUID_t& guid,
const ReaderAttributes& att,
ReaderHistory* hist,
ReaderListener* listen = nullptr);
RTPSReader(
RTPSParticipantImpl* pimpl,
const GUID_t& guid,
const ReaderAttributes& att,
const std::shared_ptr<IPayloadPool>& payload_pool,
ReaderHistory* hist,
ReaderListener* listen = nullptr);
RTPSReader(
RTPSParticipantImpl* pimpl,
const GUID_t& guid,
const ReaderAttributes& att,
const std::shared_ptr<IPayloadPool>& payload_pool,
const std::shared_ptr<IChangePool>& change_pool,
ReaderHistory* hist,
ReaderListener* listen = nullptr);
virtual ~RTPSReader();
public:
/**
* Add a matched writer represented by its attributes.
* @param wdata Attributes of the writer to add.
* @return True if correctly added.
*/
RTPS_DllAPI virtual bool matched_writer_add(
const WriterProxyData& wdata) = 0;
/**
* Remove a writer represented by its attributes from the matched writers.
* @param writer_guid GUID of the writer to remove.
* @param removed_by_lease Whether the writer is being unmatched due to a participant drop.
* @return True if correctly removed.
*/
RTPS_DllAPI virtual bool matched_writer_remove(
const GUID_t& writer_guid,
bool removed_by_lease = false) = 0;
/**
* Tells us if a specific Writer is matched against this reader.
* @param writer_guid GUID of the writer to check.
* @return True if it is matched.
*/
RTPS_DllAPI virtual bool matched_writer_is_matched(
const GUID_t& writer_guid) = 0;
/**
* Processes a new DATA message. Previously the message must have been accepted by function acceptMsgDirectedTo.
*
* @param change Pointer to the CacheChange_t.
* @return true if the reader accepts messages from the.
*/
RTPS_DllAPI virtual bool processDataMsg(
CacheChange_t* change) = 0;
/**
* Processes a new DATA FRAG message.
*
* @param change Pointer to the CacheChange_t.
* @param sampleSize Size of the complete, assembled message.
* @param fragmentStartingNum Starting number of this particular message.
* @param fragmentsInSubmessage Number of fragments on this particular message.
* @return true if the reader accepts message.
*/
RTPS_DllAPI virtual bool processDataFragMsg(
CacheChange_t* change,
uint32_t sampleSize,
uint32_t fragmentStartingNum,
uint16_t fragmentsInSubmessage) = 0;
/**
* Processes a new HEARTBEAT message.
* @param writerGUID
* @param hbCount
* @param firstSN
* @param lastSN
* @param finalFlag
* @param livelinessFlag
* @param origin_vendor_id
* @return true if the reader accepts messages from the.
*/
RTPS_DllAPI virtual bool processHeartbeatMsg(
const GUID_t& writerGUID,
uint32_t hbCount,
const SequenceNumber_t& firstSN,
const SequenceNumber_t& lastSN,
bool finalFlag,
bool livelinessFlag,
fastdds::rtps::VendorId_t origin_vendor_id = c_VendorId_Unknown) = 0;
/**
* Processes a new GAP message.
* @param writerGUID
* @param gapStart
* @param gapList
* @param origin_vendor_id
* @return true if the reader accepts messages from the.
*/
RTPS_DllAPI virtual bool processGapMsg(
const GUID_t& writerGUID,
const SequenceNumber_t& gapStart,
const SequenceNumberSet_t& gapList,
fastdds::rtps::VendorId_t origin_vendor_id = c_VendorId_Unknown) = 0;
/**
* Method to indicate the reader that some change has been removed due to HistoryQos requirements.
* @param change Pointer to the CacheChange_t.
* @param prox Pointer to the WriterProxy.
* @return True if correctly removed.
*/
RTPS_DllAPI virtual bool change_removed_by_history(
CacheChange_t* change,
WriterProxy* prox = nullptr) = 0;
/**
* Get the associated listener, secondary attached Listener in case it is of compound type
* @return Pointer to the associated reader listener.
*/
RTPS_DllAPI ReaderListener* getListener() const;
/**
* Switch the ReaderListener kind for the Reader.
* If the RTPSReader does not belong to the built-in protocols it switches out the old one.
* If it belongs to the built-in protocols, it sets the new ReaderListener callbacks to be called after the
* built-in ReaderListener ones.
* @param target Pointed to ReaderLister to attach
* @return True is correctly set.
*/
RTPS_DllAPI bool setListener(
ReaderListener* target);
/**
* Reserve a CacheChange_t.
* @param change Pointer to pointer to the Cache.
* @param dataCdrSerializedSize Size of the Cache.
* @return True if correctly reserved.
*/
RTPS_DllAPI bool reserveCache(
CacheChange_t** change,
uint32_t dataCdrSerializedSize);
/**
* Release a cacheChange.
*/
RTPS_DllAPI void releaseCache(
CacheChange_t* change);
/**
* Read the next unread CacheChange_t from the history
* @param change Pointer to pointer of CacheChange_t
* @param wp Pointer to pointer to the WriterProxy
* @return True if read.
*/
RTPS_DllAPI virtual bool nextUnreadCache(
CacheChange_t** change,
WriterProxy** wp) = 0;
/**
* Get the next CacheChange_t from the history to take.
* @param change Pointer to pointer of CacheChange_t.
* @param wp Pointer to pointer to the WriterProxy.
* @return True if read.
*/
RTPS_DllAPI virtual bool nextUntakenCache(
CacheChange_t** change,
WriterProxy** wp) = 0;
RTPS_DllAPI bool wait_for_unread_cache(
const eprosima::fastrtps::Duration_t& timeout);
RTPS_DllAPI uint64_t get_unread_count() const;
RTPS_DllAPI uint64_t get_unread_count(
bool mark_as_read);
/**
* @return True if the reader expects Inline QOS.
*/
RTPS_DllAPI inline bool expectsInlineQos()
{
return m_expectsInlineQos;
}
//! Returns a pointer to the associated History.
RTPS_DllAPI inline ReaderHistory* getHistory()
{
return mp_history;
}
//! @return The content filter associated to this reader.
RTPS_DllAPI eprosima::fastdds::rtps::IReaderDataFilter* get_content_filter() const
{
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
return data_filter_;
}
//! Set the content filter associated to this reader.
//! @param filter Pointer to the content filter to associate to this reader.
RTPS_DllAPI void set_content_filter(
eprosima::fastdds::rtps::IReaderDataFilter* filter)
{
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
data_filter_ = filter;
}
/*!
* @brief Returns there is a clean state with all Writers.
* It occurs when the Reader received all samples sent by Writers. In other words,
* its WriterProxies are up to date.
* @return There is a clean state with all Writers.
*/
virtual bool isInCleanState() = 0;
//! The liveliness changed status struct as defined in the DDS
LivelinessChangedStatus liveliness_changed_status_;
inline void enableMessagesFromUnkownWriters(
bool enable)
{
m_acceptMessagesFromUnkownWriters = enable;
}
void setTrustedWriter(
const EntityId_t& writer)
{
m_acceptMessagesFromUnkownWriters = false;
m_trustedWriterEntityId = writer;
}
/**
* Assert the liveliness of a matched writer.
* @param writer GUID of the writer to assert.
*/
virtual void assert_writer_liveliness(
const GUID_t& writer) = 0;
/**
* Called just before a change is going to be deserialized.
* @param [in] change Pointer to the change being accessed.
* @param [out] wp Writer proxy the @c change belongs to.
* @param [out] is_future_change Whether the change is in the future (i.e. there are
* earlier unreceived changes from the same writer).
*
* @return Whether the change is still valid or not.
*/
virtual bool begin_sample_access_nts(
CacheChange_t* change,
WriterProxy*& wp,
bool& is_future_change) = 0;
/**
* Called after the change has been deserialized.
* @param [in] change Pointer to the change being accessed.
* @param [in] wp Writer proxy the @c change belongs to.
* @param [in] mark_as_read Whether the @c change should be marked as read or not.
*/
virtual void end_sample_access_nts(
CacheChange_t* change,
WriterProxy*& wp,
bool mark_as_read) = 0;
/**
* Called when the user has retrieved a change from the history.
* @param change Pointer to the change to ACK
* @param writer Writer proxy of the \c change.
* @param mark_as_read Whether the \c change should be marked as read or not
*/
virtual void change_read_by_user(
CacheChange_t* change,
WriterProxy* writer,
bool mark_as_read = true) = 0;
/**
* Checks whether the sample is still valid or is corrupted.
*
* @param data Pointer to the sample data to check.
* If it does not belong to the payload pool passed to the
* reader on construction, it yields undefined behavior.
* @param writer GUID of the writer that sent \c data.
* @param sn Sequence number related to \c data.
*
* @return true if the sample is valid
*/
RTPS_DllAPI bool is_sample_valid(
const void* data,
const GUID_t& writer,
const SequenceNumber_t& sn) const;
const std::unique_ptr<IDataSharingListener>& datasharing_listener() const
{
return datasharing_listener_;
}
#ifdef FASTDDS_STATISTICS
/**
* Add a listener to receive statistics backend callbacks
* @param listener
* @return true if successfully added
*/
RTPS_DllAPI bool add_statistics_listener(
std::shared_ptr<fastdds::statistics::IListener> listener);
/**
* Remove a listener from receiving statistics backend callbacks
* @param listener
* @return true if successfully removed
*/
RTPS_DllAPI bool remove_statistics_listener(
std::shared_ptr<fastdds::statistics::IListener> listener);
/**
* @brief Set the enabled statistics writers mask
*
* @param enabled_writers The new mask to set
*/
RTPS_DllAPI void set_enabled_statistics_writers_mask(
uint32_t enabled_writers);
/**
* @brief Get the connection list of this reader
*
* @param [out] connection_list of the reader
* @return True if could be retrieved
*/
RTPS_DllAPI virtual bool get_connections(
fastdds::statistics::rtps::ConnectionList& connection_list) = 0;
#endif // FASTDDS_STATISTICS
protected:
virtual bool may_remove_history_record(
bool removed_by_lease);
/*!
* @brief Add a remote writer to the persistence_guid map
* @param guid GUID of the remote writer
* @param persistence_guid Persistence GUID of the remote writer
*/
void add_persistence_guid(
const GUID_t& guid,
const GUID_t& persistence_guid);
/*!
* @brief Remove a remote writer from the persistence_guid map
* @param guid GUID of the remote writer
* @param persistence_guid Persistence GUID of the remote writer
* @param removed_by_lease Whether the GUIDs are being removed due to a participant drop.
*/
void remove_persistence_guid(
const GUID_t& guid,
const GUID_t& persistence_guid,
bool removed_by_lease);
/*!
* @brief Get the last notified sequence for a RTPS guid
* @param guid The RTPS guid to query
* @return Last notified sequence number for input guid
* @remarks Takes persistence_guid into consideration
*/
SequenceNumber_t get_last_notified(
const GUID_t& guid);
/*!
* @brief Update the last notified sequence for a RTPS guid
* @param guid The RTPS guid of the writer
* @param seq Max sequence number available on writer
* @return Previous value of last notified sequence number for input guid
* @remarks Takes persistence_guid into consideration
*/
SequenceNumber_t update_last_notified(
const GUID_t& guid,
const SequenceNumber_t& seq);
/*!
* @brief Set the last notified sequence for a persistence guid
* @param persistence_guid The persistence guid to update
* @param seq Sequence number to set for input guid
* @remarks Persistent readers will write to DB
*/
virtual void set_last_notified(
const GUID_t& persistence_guid,
const SequenceNumber_t& seq);
/*!
* @brief Search if there is a CacheChange_t, giving SequenceNumber_t and writer GUID_t,
* waiting to be completed because it is fragmented.
* @param sequence_number SequenceNumber_t of the searched CacheChange_t.
* @param writer_guid writer GUID_t of the searched CacheChange_t.
* @param change If a CacheChange_t was found, this argument will fill with its pointer.
* In other case nullptr is returned.
* @param hint Iterator since the search will start.
* Used to improve the search.
* @return Iterator pointing to the position were CacheChange_t was found.
* It can be used to improve next search.
*/
History::const_iterator findCacheInFragmentedProcess(
const SequenceNumber_t& sequence_number,
const GUID_t& writer_guid,
CacheChange_t** change,
History::const_iterator hint) const;
/**
* Creates the listener for the datasharing notifications
*
* @param limits Resource limits for the number of matched datasharing writers
*/
void create_datasharing_listener(
ResourceLimitedContainerConfig limits);
bool is_datasharing_compatible_with(
const WriterProxyData& wdata);
//!ReaderHistory
ReaderHistory* mp_history;
//!Listener
ReaderListener* mp_listener;
//!Accept msg to unknwon readers (default=true)
bool m_acceptMessagesToUnknownReaders;
//!Accept msg from unknwon writers (BE-true,RE-false)
bool m_acceptMessagesFromUnkownWriters;
//!Trusted writer (for Builtin)
EntityId_t m_trustedWriterEntityId;
//!Expects Inline Qos.
bool m_expectsInlineQos;
//!ReaderHistoryState
ReaderHistoryState* history_state_;
uint64_t total_unread_ = 0;
TimedConditionVariable new_notification_cv_;
//! The liveliness kind of this reader
LivelinessQosPolicyKind liveliness_kind_;
//! The liveliness lease duration of this reader
Duration_t liveliness_lease_duration_;
//! Whether the writer is datasharing compatible or not
bool is_datasharing_compatible_ = false;
//! The listener for the datasharing notifications
std::unique_ptr<IDataSharingListener> datasharing_listener_;
eprosima::fastdds::rtps::IReaderDataFilter* data_filter_ = nullptr;
private:
RTPSReader& operator =(
const RTPSReader&) = delete;
void init(
const std::shared_ptr<IPayloadPool>& payload_pool,
const std::shared_ptr<IChangePool>& change_pool,
const ReaderAttributes& att);
};
} /* namespace rtps */
} /* namespace fastrtps */
} /* namespace eprosima */
#endif /* _FASTDDS_RTPS_READER_RTPSREADER_H_ */