Fast DDS  Version 3.0.1
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
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
36namespace eprosima {
37namespace fastdds {
38namespace rtps {
39
45{
46protected:
47
49 const HistoryAttributes& att);
51 History&&) = delete;
53 History&&) = delete;
54 virtual ~History();
55
56public:
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
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
247 const SequenceNumber_t& seq,
248 const GUID_t& guid,
249 CacheChange_t** change,
250 const_iterator hint) const;
251
258 CacheChange_t** change);
259
260protected:
261
263 std::vector<CacheChange_t*> m_changes;
264
266 bool m_isHistoryFull = false;
267
270
273
274 FASTDDS_EXPORTED_API virtual void do_release_cache(
275 CacheChange_t* ch) = 0;
276
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
Class HistoryAttributes, to specify the attributes of a WriterHistory or a ReaderHistory.
Definition HistoryAttributes.hpp:39
uint32_t payloadMaxSize
Maximum payload size of the history, default value 500.
Definition HistoryAttributes.hpp:46
Class History, container of the different CacheChanges and the methods to access them.
Definition History.hpp:45
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...
std::vector< CacheChange_t * >::reverse_iterator reverse_iterator
Definition History.hpp:59
FASTDDS_EXPORTED_API bool get_min_change(CacheChange_t **min_change)
Get the minimum CacheChange_t.
History & operator=(History &&)=delete
std::vector< CacheChange_t * >::iterator iterator
Definition History.hpp:58
FASTDDS_EXPORTED_API size_t getHistorySize()
Get the History size.
Definition History.hpp:78
const_iterator get_change_nts(const SequenceNumber_t &seq, const GUID_t &guid, CacheChange_t **change, const_iterator hint) const
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
FASTDDS_EXPORTED_API reverse_iterator changesRbegin()
Definition History.hpp:187
FASTDDS_EXPORTED_API bool remove_change(CacheChange_t *ch)
Remove a specific change from the history.
virtual FASTDDS_EXPORTED_API void do_release_cache(CacheChange_t *ch)=0
bool get_earliest_change(CacheChange_t **change)
A method to get the change with the earliest timestamp.
virtual FASTDDS_EXPORTED_API iterator remove_change_nts(const_iterator removal, bool release=true)
Remove a specific change from the history.
void print_changes_seqNum2()
Print the seqNum of the changes in the History (for debuggisi, mng purposes).
FASTDDS_EXPORTED_API iterator remove_change(const_iterator removal, bool release=true)
Remove a specific change from the history.
Definition History.hpp:170
FASTDDS_EXPORTED_API bool get_change(const SequenceNumber_t &seq, const GUID_t &guid, CacheChange_t **change) const
std::vector< CacheChange_t * >::const_iterator const_iterator
Definition History.hpp:60
FASTDDS_EXPORTED_API iterator changesEnd()
Get the end of the changes history iterator.
Definition History.hpp:196
FASTDDS_EXPORTED_API const_iterator find_change_nts(CacheChange_t *ch)
Find a specific change in the history using the matches_change method criteria.
History::iterator remove_iterator_constness(const_iterator c_it)
Removes the constness of a const_iterator to obtain a regular iterator.
FASTDDS_EXPORTED_API uint32_t getTypeMaxSerialized()
Get the maximum serialized payload size.
Definition History.hpp:226
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.
FASTDDS_EXPORTED_API bool get_max_change(CacheChange_t **max_change)
Get the maximum CacheChange_t.
RecursiveTimedMutex * mp_mutex
Mutex for the History.
Definition History.hpp:269
HistoryAttributes m_att
Attributes of the History.
Definition History.hpp:63
History(const HistoryAttributes &att)
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.
FASTDDS_EXPORTED_API bool isFull()
Check if the history is full.
Definition History.hpp:69
FASTDDS_EXPORTED_API reverse_iterator changesRend()
Definition History.hpp:201
FASTDDS_EXPORTED_API iterator changesBegin()
Get the beginning of the changes history iterator.
Definition History.hpp:182
bool m_isHistoryFull
Variable to know if the history is full without needing to block the History mutex.
Definition History.hpp:266
FASTDDS_EXPORTED_API RecursiveTimedMutex * getMutex() const
Get the mutex.
Definition History.hpp:235
std::vector< CacheChange_t * > m_changes
Vector of pointers to the CacheChange_t.
Definition History.hpp:263
FASTDDS_EXPORTED_API bool remove_all_changes()
Remove all changes from the History.
std::recursive_timed_mutex RecursiveTimedMutex
Definition TimedMutex.hpp:201
eProsima namespace.
Structure CacheChange_t, contains information on a specific CacheChange.
Definition CacheChange.hpp:78
Structure GUID_t, entity identifier, unique in DDS-RTPS Domain.
Definition Guid.hpp:40
Structure SequenceNumber_t, different for each change in the same writer.
Definition SequenceNumber.hpp:38