| Fast DDS Version 3.3.0 Fast DDS

Loading...
Searching...
No Matches
History.hpp
1// Copyright 2016 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
19
20#ifndef FASTDDS_RTPS_HISTORY__HISTORY_HPP
21#define FASTDDS_RTPS_HISTORY__HISTORY_HPP
22
23#include <fastdds/fastdds_dll.hpp>
24#include <fastdds/rtps/history/IChangePool.hpp>
25#include <fastdds/rtps/history/IPayloadPool.hpp>
26#include <fastdds/rtps/common/SequenceNumber.hpp>
27#include <fastdds/rtps/common/Guid.hpp>
28#include <fastdds/rtps/attributes/HistoryAttributes.hpp>
29#include <fastdds/utils/TimedMutex.hpp>
30
31#include <cassert>
32#include <functional>
33#include <memory>
34#include <mutex>
35
36 namespace eprosima {
37 namespace fastdds {
38 namespace rtps {
39
44 class History
45{
46 protected:
47
48 History(
49 const HistoryAttributes& att);
50 History(
51 History&&) = delete;
52 History& operator =(
53 History&&) = delete;
54 virtual ~History();
55
56 public:
57
58 using iterator = std::vector<CacheChange_t*>::iterator;
59 using reverse_iterator = std::vector<CacheChange_t*>::reverse_iterator;
60 using const_iterator = std::vector<CacheChange_t*>::const_iterator;
61
63 HistoryAttributes m_att;
64
69 FASTDDS_EXPORTED_API bool isFull()
70 {
71 return m_isHistoryFull;
72 }
73
78 FASTDDS_EXPORTED_API size_t getHistorySize()
79 {
80 std::lock_guard<RecursiveTimedMutex> guard(*mp_mutex);
81 return m_changes.size();
82 }
83
90 FASTDDS_EXPORTED_API const_iterator find_change_nts(
91 CacheChange_t* ch);
92
100 FASTDDS_EXPORTED_API virtual iterator remove_change_nts(
101 const_iterator removal,
102 bool release = true);
103
112 FASTDDS_EXPORTED_API virtual iterator remove_change_nts(
113 const_iterator removal,
114 const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time,
115 bool release = true);
116
121 FASTDDS_EXPORTED_API bool remove_all_changes();
122
128 FASTDDS_EXPORTED_API bool remove_change(
129 CacheChange_t* ch);
130
137 FASTDDS_EXPORTED_API bool remove_change(
138 CacheChange_t* ch,
139 const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time);
140
146 FASTDDS_EXPORTED_API const_iterator find_change(
147 CacheChange_t* ch)
148 {
149 std::lock_guard<RecursiveTimedMutex> guard(*mp_mutex);
150 return find_change_nts(ch);
151 }
152
160 FASTDDS_EXPORTED_API virtual bool matches_change(
161 const CacheChange_t* ch_inner,
162 CacheChange_t* ch_outer);
163
170 FASTDDS_EXPORTED_API iterator remove_change(
171 const_iterator removal,
172 bool release = true)
173 {
174 std::lock_guard<RecursiveTimedMutex> guard(*mp_mutex);
175 return remove_change_nts(removal, release);
176 }
177
182 FASTDDS_EXPORTED_API iterator changesBegin()
183 {
184 return m_changes.begin();
185 }
186
187 FASTDDS_EXPORTED_API reverse_iterator changesRbegin()
188 {
189 return m_changes.rbegin();
190 }
191
196 FASTDDS_EXPORTED_API iterator changesEnd()
197 {
198 return m_changes.end();
199 }
200
201 FASTDDS_EXPORTED_API reverse_iterator changesRend()
202 {
203 return m_changes.rend();
204 }
205
211 FASTDDS_EXPORTED_API bool get_min_change(
212 CacheChange_t** min_change);
213
219 FASTDDS_EXPORTED_API bool get_max_change(
220 CacheChange_t** max_change);
221
226 FASTDDS_EXPORTED_API inline uint32_t getTypeMaxSerialized()
227 {
228 return m_att.payloadMaxSize;
229 }
230
235 FASTDDS_EXPORTED_API inline RecursiveTimedMutex* getMutex() const
236 {
237 assert(mp_mutex != nullptr);
238 return mp_mutex;
239 }
240
241 FASTDDS_EXPORTED_API bool get_change(
242 const SequenceNumber_t& seq,
243 const GUID_t& guid,
244 CacheChange_t** change) const;
245
246 const_iterator get_change_nts(
247 const SequenceNumber_t& seq,
248 const GUID_t& guid,
249 CacheChange_t** change,
250 const_iterator hint) const;
251
257 bool get_earliest_change(
258 CacheChange_t** change);
259
260 protected:
261
263 std::vector<CacheChange_t*> m_changes;
264
266 bool m_isHistoryFull = false;
267
269 RecursiveTimedMutex* mp_mutex = nullptr;
270
272 void print_changes_seqNum2();
273
274 FASTDDS_EXPORTED_API virtual void do_release_cache(
275 CacheChange_t* ch) = 0;
276
286 History::iterator remove_iterator_constness(
287 const_iterator c_it);
288
289};
290
291} // namespace rtps
292} // namespace fastdds
293} // namespace eprosima
294
295#endif // FASTDDS_RTPS_HISTORY__HISTORY_HPP
eprosima::fastdds::rtps::HistoryAttributes
Class HistoryAttributes, to specify the attributes of a WriterHistory or a ReaderHistory.
Definition HistoryAttributes.hpp:39
eprosima::fastdds::rtps::History::matches_change
virtual FASTDDS_EXPORTED_API bool matches_change(const CacheChange_t *ch_inner, CacheChange_t *ch_outer)
Verifies if an element of the changes collection matches a given change Derived classes have more inf...
eprosima::fastdds::rtps::History::reverse_iterator
std::vector< CacheChange_t * >::reverse_iterator reverse_iterator
Definition History.hpp:59
eprosima::fastdds::rtps::History::get_min_change
FASTDDS_EXPORTED_API bool get_min_change(CacheChange_t **min_change)
Get the minimum CacheChange_t.
eprosima::fastdds::rtps::History::operator=
History & operator=(History &&)=delete
eprosima::fastdds::rtps::History::iterator
std::vector< CacheChange_t * >::iterator iterator
Definition History.hpp:58
eprosima::fastdds::rtps::History::getHistorySize
FASTDDS_EXPORTED_API size_t getHistorySize()
Get the History size.
Definition History.hpp:78
eprosima::fastdds::rtps::History::get_change_nts
const_iterator get_change_nts(const SequenceNumber_t &seq, const GUID_t &guid, CacheChange_t **change, const_iterator hint) const
eprosima::fastdds::rtps::History::find_change
FASTDDS_EXPORTED_API const_iterator find_change(CacheChange_t *ch)
Find a specific change in the history using the matches_change method criteria.
Definition History.hpp:146
eprosima::fastdds::rtps::History::History
History(History &&)=delete
eprosima::fastdds::rtps::History::changesRbegin
FASTDDS_EXPORTED_API reverse_iterator changesRbegin()
Definition History.hpp:187
eprosima::fastdds::rtps::History::remove_change
FASTDDS_EXPORTED_API bool remove_change(CacheChange_t *ch)
Remove a specific change from the history.
eprosima::fastdds::rtps::History::do_release_cache
virtual FASTDDS_EXPORTED_API void do_release_cache(CacheChange_t *ch)=0
eprosima::fastdds::rtps::History::get_earliest_change
bool get_earliest_change(CacheChange_t **change)
A method to get the change with the earliest timestamp.
eprosima::fastdds::rtps::History::remove_change_nts
virtual FASTDDS_EXPORTED_API iterator remove_change_nts(const_iterator removal, bool release=true)
Remove a specific change from the history.
eprosima::fastdds::rtps::History::print_changes_seqNum2
void print_changes_seqNum2()
Print the seqNum of the changes in the History (for debuggisi, mng purposes).
eprosima::fastdds::rtps::History::remove_change
FASTDDS_EXPORTED_API iterator remove_change(const_iterator removal, bool release=true)
Remove a specific change from the history.
Definition History.hpp:170
eprosima::fastdds::rtps::History::get_change
FASTDDS_EXPORTED_API bool get_change(const SequenceNumber_t &seq, const GUID_t &guid, CacheChange_t **change) const
eprosima::fastdds::rtps::History::const_iterator
std::vector< CacheChange_t * >::const_iterator const_iterator
Definition History.hpp:60
eprosima::fastdds::rtps::History::changesEnd
FASTDDS_EXPORTED_API iterator changesEnd()
Get the end of the changes history iterator.
Definition History.hpp:196
eprosima::fastdds::rtps::History::find_change_nts
FASTDDS_EXPORTED_API const_iterator find_change_nts(CacheChange_t *ch)
Find a specific change in the history using the matches_change method criteria.
eprosima::fastdds::rtps::History::remove_iterator_constness
History::iterator remove_iterator_constness(const_iterator c_it)
Removes the constness of a const_iterator to obtain a regular iterator.
eprosima::fastdds::rtps::History::getTypeMaxSerialized
FASTDDS_EXPORTED_API uint32_t getTypeMaxSerialized()
Get the maximum serialized payload size.
Definition History.hpp:226
eprosima::fastdds::rtps::History::remove_change
FASTDDS_EXPORTED_API bool remove_change(CacheChange_t *ch, const std::chrono::time_point< std::chrono::steady_clock > &max_blocking_time)
Remove a specific change from the history.
eprosima::fastdds::rtps::History::get_max_change
FASTDDS_EXPORTED_API bool get_max_change(CacheChange_t **max_change)
Get the maximum CacheChange_t.
eprosima::fastdds::rtps::History::mp_mutex
RecursiveTimedMutex * mp_mutex
Mutex for the History.
Definition History.hpp:269
eprosima::fastdds::rtps::History::m_att
HistoryAttributes m_att
Attributes of the History.
Definition History.hpp:63
eprosima::fastdds::rtps::History::History
History(const HistoryAttributes &att)
eprosima::fastdds::rtps::History::remove_change_nts
virtual FASTDDS_EXPORTED_API iterator remove_change_nts(const_iterator removal, const std::chrono::time_point< std::chrono::steady_clock > &max_blocking_time, bool release=true)
Remove a specific change from the history.
eprosima::fastdds::rtps::History::~History
virtual ~History()
eprosima::fastdds::rtps::History::isFull
FASTDDS_EXPORTED_API bool isFull()
Check if the history is full.
Definition History.hpp:69
eprosima::fastdds::rtps::History::changesRend
FASTDDS_EXPORTED_API reverse_iterator changesRend()
Definition History.hpp:201
eprosima::fastdds::rtps::History::changesBegin
FASTDDS_EXPORTED_API iterator changesBegin()
Get the beginning of the changes history iterator.
Definition History.hpp:182
eprosima::fastdds::rtps::History::m_isHistoryFull
bool m_isHistoryFull
Variable to know if the history is full without needing to block the History mutex.
Definition History.hpp:266
eprosima::fastdds::rtps::History::getMutex
FASTDDS_EXPORTED_API RecursiveTimedMutex * getMutex() const
Get the mutex.
Definition History.hpp:235
eprosima::fastdds::rtps::History::m_changes
std::vector< CacheChange_t * > m_changes
Vector of pointers to the CacheChange_t.
Definition History.hpp:263
eprosima::fastdds::rtps::History::remove_all_changes
FASTDDS_EXPORTED_API bool remove_all_changes()
Remove all changes from the History.
eprosima::fastdds::rtps
Contains the RTPS protocol implementation.
eprosima::fastdds
eprosima::fastdds::RecursiveTimedMutex
std::recursive_timed_mutex RecursiveTimedMutex
Definition TimedMutex.hpp:206
eprosima
eProsima namespace.
eprosima::fastdds::rtps::CacheChange_t
Structure CacheChange_t, contains information on a specific CacheChange.
Definition CacheChange.hpp:78
eprosima::fastdds::rtps::GUID_t
Structure GUID_t, entity identifier, unique in DDS-RTPS Domain.
Definition Guid.hpp:40
eprosima::fastdds::rtps::SequenceNumber_t
Structure SequenceNumber_t, different for each change in the same writer.
Definition SequenceNumber.hpp:38