-
Notifications
You must be signed in to change notification settings - Fork 905
Expand file tree
/
Copy pathStatelessWriter.h
More file actions
306 lines (252 loc) · 10.1 KB
/
StatelessWriter.h
File metadata and controls
306 lines (252 loc) · 10.1 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
// 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 StatelessWriter.h
*/
#ifndef _FASTDDS_RTPS_STATELESSWRITER_H_
#define _FASTDDS_RTPS_STATELESSWRITER_H_
#ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#include <fastdds/rtps/common/Time_t.h>
#include <fastdds/rtps/history/IChangePool.h>
#include <fastdds/rtps/history/IPayloadPool.h>
#include <fastdds/rtps/interfaces/IReaderDataFilter.hpp>
#include <fastdds/rtps/writer/ChangeForReader.h>
#include <fastdds/rtps/writer/ReaderLocator.h>
#include <fastdds/rtps/writer/RTPSWriter.h>
#include <fastrtps/utils/collections/ResourceLimitedVector.hpp>
#include <condition_variable>
#include <list>
#include <memory>
#include <mutex>
namespace eprosima {
namespace fastrtps {
namespace rtps {
/**
* Class StatelessWriter, specialization of RTPSWriter that manages writers that don't keep state of the matched readers.
* @ingroup WRITER_MODULE
*/
class StatelessWriter : public RTPSWriter
{
friend class RTPSParticipantImpl;
protected:
StatelessWriter(
RTPSParticipantImpl* participant,
const GUID_t& guid,
const WriterAttributes& attributes,
fastdds::rtps::FlowController* flow_controller,
WriterHistory* history,
WriterListener* listener = nullptr);
StatelessWriter(
RTPSParticipantImpl* impl,
const GUID_t& guid,
const WriterAttributes& att,
const std::shared_ptr<IPayloadPool>& payload_pool,
fastdds::rtps::FlowController* flow_controller,
WriterHistory* hist,
WriterListener* listen = nullptr);
StatelessWriter(
RTPSParticipantImpl* impl,
const GUID_t& guid,
const WriterAttributes& att,
const std::shared_ptr<IPayloadPool>& payload_pool,
const std::shared_ptr<IChangePool>& change_pool,
fastdds::rtps::FlowController* flow_controller,
WriterHistory* hist,
WriterListener* listen = nullptr);
mutable LocatorList_t fixed_locators_;
virtual bool send_to_fixed_locators(
CDRMessage_t* message,
std::chrono::steady_clock::time_point& max_blocking_time_point) const;
public:
virtual ~StatelessWriter();
/**
* Add a specific change to all ReaderLocators.
* @param change Pointer to the change.
* @param[in] max_blocking_time Maximum time this method has to complete the task.
*/
void unsent_change_added_to_history(
CacheChange_t* change,
const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time) override;
/**
* Indicate the writer that a change has been removed by the history due to some HistoryQos requirement.
* @param change Pointer to the change that is going to be removed.
* @param[in] max_blocking_time Maximum time this method has to complete the task.
* @return True if removed correctly.
*/
bool change_removed_by_history(
CacheChange_t* change,
const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time) override;
/**
* Add a matched reader.
* @param data Pointer to the ReaderProxyData object added.
* @return True if added.
*/
bool matched_reader_add(
const ReaderProxyData& data) override;
/**
* Remove a matched reader.
* @param reader_guid GUID of the reader to remove.
* @return True if removed.
*/
bool matched_reader_remove(
const GUID_t& reader_guid) override;
/**
* Tells us if a specific Reader is matched against this writer
* @param reader_guid GUID of the reader to check.
* @return True if it was matched.
*/
bool matched_reader_is_matched(
const GUID_t& reader_guid) override;
/**
* @brief Set a content filter to perform content filtering on this writer.
*
* This method sets a content filter that will be used to check whether a cache change is relevant
* for a reader or not.
*
* @param filter The content filter to use on this writer. May be @c nullptr to remove the content filter
* (i.e. treat all samples as relevant).
*/
void reader_data_filter(
fastdds::rtps::IReaderDataFilter* filter) final
{
reader_data_filter_ = filter;
}
/**
* @brief Get the content filter used to perform content filtering on this writer.
*
* @return The content filter used on this writer.
*/
const fastdds::rtps::IReaderDataFilter* reader_data_filter() const final
{
return reader_data_filter_;
}
/**
* Update the Attributes of the Writer.
* @param att New attributes
*/
void updateAttributes(
const WriterAttributes& att) override
{
(void)att;
//FOR NOW THERE IS NOTHING TO UPDATE.
}
//! Deprecated in favor of PDP simple writer
bool set_fixed_locators(
const LocatorList_t& locator_list);
//! Deprecated in favor of PDP simple writer
void unsent_changes_reset();
/**
* @brief Check if a specific change has been delivered to the transport layer at least once for every matched
* remote RTPSReader.
*
* @param seq_num Sequence number of the change to check.
* @return true if delivered.
* @return false otherwise.
*/
bool has_been_fully_delivered(
const SequenceNumber_t& seq_num) const override;
bool is_acked_by_all(
const CacheChange_t* change) const override;
bool try_remove_change(
const std::chrono::steady_clock::time_point&,
std::unique_lock<RecursiveTimedMutex>&) override;
bool wait_for_acknowledgement(
const SequenceNumber_t& seq,
const std::chrono::steady_clock::time_point& max_blocking_time_point,
std::unique_lock<RecursiveTimedMutex>& lock) override;
/**
* Send a message through this interface.
*
* @param message Pointer to the buffer with the message already serialized.
* @param locator_selector RTPSMessageSenderInterface reference uses for selecting locators. The reference has to
* be a member of this RTPSWriter object.
* @param max_blocking_time_point Future timepoint where blocking send should end.
*/
bool send_nts(
CDRMessage_t* message,
const LocatorSelectorSender& locator_selector,
std::chrono::steady_clock::time_point& max_blocking_time_point) const override;
/**
* Get the number of matched readers
* @return Number of the matched readers
*/
inline size_t getMatchedReadersSize() const
{
std::lock_guard<RecursiveTimedMutex> guard(mp_mutex);
return matched_remote_readers_.size()
+ matched_local_readers_.size()
+ matched_datasharing_readers_.size();
}
/*!
* Tells writer the sample can be sent to the network.
* This function should be used by a fastdds::rtps::FlowController.
*
* @param cache_change Pointer to the CacheChange_t that represents the sample which can be sent.
* @param group RTPSMessageGroup reference uses for generating the RTPS message.
* @param locator_selector RTPSMessageSenderInterface reference uses for selecting locators. The reference has to
* be a member of this RTPSWriter object.
* @param max_blocking_time Future timepoint where blocking send should end.
* @return Return code.
* @note Must be non-thread safe.
*/
DeliveryRetCode deliver_sample_nts(
CacheChange_t* cache_change,
RTPSMessageGroup& group,
LocatorSelectorSender& locator_selector,
const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time) override;
LocatorSelectorSender& get_general_locator_selector() override
{
return locator_selector_;
}
LocatorSelectorSender& get_async_locator_selector() override
{
return locator_selector_;
}
#ifdef FASTDDS_STATISTICS
bool get_connections(
fastdds::statistics::rtps::ConnectionList& connection_list) override;
#endif // ifdef FASTDDS_STATISTICS
private:
void init(
RTPSParticipantImpl* participant,
const WriterAttributes& attributes);
void get_builtin_guid();
bool has_builtin_guid();
void update_reader_info(
bool create_sender_resources);
bool datasharing_delivery(
CacheChange_t* change);
bool intraprocess_delivery(
CacheChange_t* change,
ReaderLocator& reader_locator);
//! Check if a specific sequence number has been sent to every remote RTPSReader
bool is_acked_by_all(
const SequenceNumber_t& seq_num) const;
bool is_inline_qos_expected_ = false;
ResourceLimitedVector<std::unique_ptr<ReaderLocator>> matched_remote_readers_;
std::condition_variable_any unsent_changes_cond_;
uint64_t current_sequence_number_sent_ = 0;
FragmentNumber_t current_fragment_sent_ = 0;
uint64_t last_sequence_number_sent_ = 0;
ResourceLimitedVector<std::unique_ptr<ReaderLocator>> matched_local_readers_;
ResourceLimitedVector<std::unique_ptr<ReaderLocator>> matched_datasharing_readers_;
ResourceLimitedVector<std::unique_ptr<ReaderLocator>> matched_readers_pool_;
LocatorSelectorSender locator_selector_;
fastdds::rtps::IReaderDataFilter* reader_data_filter_ = nullptr;
};
} /* namespace rtps */
} /* namespace fastrtps */
} /* namespace eprosima */
#endif // ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
#endif /* _FASTDDS_RTPS_STATELESSWRITER_H_ */