-
Notifications
You must be signed in to change notification settings - Fork 941
Expand file tree
/
Copy pathStatefulReader.hpp
More file actions
383 lines (332 loc) · 12.4 KB
/
Copy pathStatefulReader.hpp
File metadata and controls
383 lines (332 loc) · 12.4 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
// 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 StatefulReader.hpp
*/
#ifndef RTPS_READER__STATEFULREADER_HPP
#define RTPS_READER__STATEFULREADER_HPP
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#include <mutex>
#include <fastdds/rtps/common/CDRMessage_t.h>
#include <fastdds/rtps/common/VendorId_t.hpp>
#include <fastdds/rtps/reader/RTPSReader.h>
#include <fastdds/utils/collections/ResourceLimitedVector.hpp>
namespace eprosima {
namespace fastrtps {
namespace rtps {
class WriterProxy;
class RTPSMessageSenderInterface;
/**
* Class StatefulReader, specialization of RTPSReader than stores the state of the matched writers.
* @ingroup READER_MODULE
*/
class StatefulReader : public RTPSReader
{
public:
friend class RTPSParticipantImpl;
virtual ~StatefulReader();
protected:
StatefulReader(
RTPSParticipantImpl* pimpl,
const GUID_t& guid,
const ReaderAttributes& att,
ReaderHistory* hist,
ReaderListener* listen = nullptr);
StatefulReader(
RTPSParticipantImpl* pimpl,
const GUID_t& guid,
const ReaderAttributes& att,
const std::shared_ptr<IPayloadPool>& payload_pool,
ReaderHistory* hist,
ReaderListener* listen = nullptr);
StatefulReader(
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);
public:
/**
* Add a matched writer represented by its attributes.
* @param wdata Attributes of the writer to add.
* @return True if correctly added.
*/
bool matched_writer_add(
const WriterProxyData& wdata) override;
/**
* Remove a WriterProxyData from the matached writers.
* @param writer_guid GUID of the writer to remove.
* @param removed_by_lease true it the writer was removed due to lease duration.
* @return True if correct.
*/
bool matched_writer_remove(
const GUID_t& writer_guid,
bool removed_by_lease = false) override;
/**
* 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.
*/
bool matched_writer_is_matched(
const GUID_t& writer_guid) override;
/**
* Look for a specific WriterProxy.
* @param writerGUID GUID_t of the writer we are looking for.
* @param WP Pointer to pointer to a WriterProxy.
* @return True if found.
*/
bool matched_writer_lookup(
const GUID_t& writerGUID,
WriterProxy** WP);
/**
* Processes a new DATA message.
* @param change Pointer to the CacheChange_t.
* @return true if the reader accepts messages.
*/
bool processDataMsg(
CacheChange_t* change) override;
/**
* 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.
*/
bool processDataFragMsg(
CacheChange_t* change,
uint32_t sampleSize,
uint32_t fragmentStartingNum,
uint16_t fragmentsInSubmessage) override;
/**
* Processes a new HEARTBEAT message.
*
* @return true if the reader accepts messages.
*/
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) override;
bool processGapMsg(
const GUID_t& writerGUID,
const SequenceNumber_t& gapStart,
const SequenceNumberSet_t& gapList,
fastdds::rtps::VendorId_t origin_vendor_id = c_VendorId_Unknown) override;
/**
* 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.
*/
bool change_removed_by_history(
CacheChange_t* change,
WriterProxy* prox = nullptr) override;
/**
* This method is called when a new change is received. This method calls the received_change of the History
* and depending on the implementation performs different actions.
* @param a_change Pointer of the change to add.
* @param prox Pointer to the WriterProxy that adds the Change.
* @param unknown_missing_changes_up_to The number of changes from the same writer with a lower sequence number that
* could potentially be received in the future.
* @return True if added.
*/
bool change_received(
CacheChange_t* a_change,
WriterProxy* prox,
size_t unknown_missing_changes_up_to);
/**
* Get the RTPS participant
* @return Associated RTPS participant
*/
inline RTPSParticipantImpl* getRTPSParticipant() const
{
return mp_RTPSParticipant;
}
/**
* Get reference to associated RTPS partiicipant's \c ResourceEvent
* @return Reference to associated RTPS partiicipant's \c ResourceEvent
*/
ResourceEvent& getEventResource() const;
/**
* Read the next unread CacheChange_t from the history
* @param change Pointer to pointer of CacheChange_t
* @param wpout Pointer to pointer the matched writer proxy
* @return True if read.
*/
bool nextUnreadCache(
CacheChange_t** change,
WriterProxy** wpout = nullptr) override;
/**
* Take the next CacheChange_t from the history;
* @param change Pointer to pointer of CacheChange_t
* @param wpout Pointer to pointer the matched writer proxy
* @return True if read.
*/
bool nextUntakenCache(
CacheChange_t** change,
WriterProxy** wpout = nullptr) override;
/**
* Update the times parameters of the Reader.
* @param times ReaderTimes reference.
* @return True if correctly updated.
*/
bool updateTimes(
const ReaderTimes& times);
/**
*
* @return Reference to the ReaderTimes.
*/
inline ReaderTimes& getTimes()
{
return times_;
}
/**
* Get the number of matched writers
* @return Number of matched writers
*/
inline size_t getMatchedWritersSize() const
{
return matched_writers_.size();
}
/*!
* @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.
*/
bool isInCleanState() override;
/**
* Sends an acknack message from this reader.
* @param writer Pointer to the info of the remote writer.
* @param sns Sequence number bitmap with the acknack information.
* @param sender Message sender interface.
* @param is_final Value for final flag.
*/
void send_acknack(
const WriterProxy* writer,
const SequenceNumberSet_t& sns,
RTPSMessageSenderInterface* sender,
bool is_final);
/**
* Sends an acknack message from this reader in response to a heartbeat.
* @param writer Pointer to the proxy representing the writer to send the acknack to.
* @param sender Message sender interface.
* @param heartbeat_was_final Final flag of the last received heartbeat.
*/
void send_acknack(
const WriterProxy* writer,
RTPSMessageSenderInterface* sender,
bool heartbeat_was_final);
/**
* Use the participant of this reader to send a message to certain locator.
* @param message Message to be sent.
* @param locators_begin Destination locators iterator begin.
* @param locators_end Destination locators iterator end.
* @param max_blocking_time_point Future time point where any blocking should end.
*/
bool send_sync_nts(
CDRMessage_t* message,
const Locators& locators_begin,
const Locators& locators_end,
std::chrono::steady_clock::time_point& max_blocking_time_point);
/**
* Assert the livelines of a matched writer.
* @param writer GUID of the writer to assert.
*/
void assert_writer_liveliness(
const GUID_t& writer) override;
/**
* 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.
*/
bool begin_sample_access_nts(
CacheChange_t* change,
WriterProxy*& wp,
bool& is_future_change) override;
/**
* 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.
*/
void end_sample_access_nts(
CacheChange_t* change,
WriterProxy*& wp,
bool mark_as_read) override;
/**
* 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
*/
void change_read_by_user(
CacheChange_t* change,
WriterProxy* writer,
bool mark_as_read = true) override;
#ifdef FASTDDS_STATISTICS
bool get_connections(
fastdds::statistics::rtps::ConnectionList& connection_list) override;
#endif // ifdef FASTDDS_STATISTICS
private:
void init(
RTPSParticipantImpl* pimpl,
const ReaderAttributes& att);
bool acceptMsgFrom(
const GUID_t& entityGUID,
WriterProxy** wp) const;
/*!
* @remarks Non thread-safe.
*/
bool findWriterProxy(
const GUID_t& writerGUID,
WriterProxy** wp) const;
void NotifyChanges(
WriterProxy* wp);
void remove_changes_from(
const GUID_t& writerGUID,
bool is_payload_pool_lost = false);
//! Acknack Count
uint32_t acknack_count_;
//! NACKFRAG Count
uint32_t nackfrag_count_;
//!ReaderTimes of the StatefulReader.
ReaderTimes times_;
//! Vector containing pointers to all the active WriterProxies.
ResourceLimitedVector<WriterProxy*> matched_writers_;
//! Vector containing pointers to all the inactive, ready for reuse, WriterProxies.
ResourceLimitedVector<WriterProxy*> matched_writers_pool_;
//!
ResourceLimitedContainerConfig proxy_changes_config_;
//! True to disable positive ACKs
bool disable_positive_acks_;
//! False when being destroyed
bool is_alive_;
};
} /* namespace rtps */
} /* namespace fastrtps */
} /* namespace eprosima */
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif // RTPS_READER__STATEFULREADER_HPP