19#ifndef FASTDDS_RTPS_COMMON__LOCATORSELECTOR_HPP
20#define FASTDDS_RTPS_COMMON__LOCATORSELECTOR_HPP
22#include <fastdds/rtps/common/LocatorSelectorEntry.hpp>
23#include <fastdds/rtps/common/Guid.hpp>
24#include <fastdds/rtps/common/Locator.hpp>
25#include <fastdds/rtps/common/LocatorsIterator.hpp>
26#include <fastdds/utils/collections/ResourceLimitedVector.hpp>
27#include <fastdds/utils/IPLocator.hpp>
65 : entries_(entries_allocation)
66 , selections_(entries_allocation)
67 , last_state_(entries_allocation)
69 static_cast<void>(initial_allow_to_send_);
70 static_cast<void>(force_reset_);
91 return entries_.push_back(entry) !=
nullptr;
101 return entries_.remove_if(
119 last_state_.push_back(entry->enabled ? 1 : 0);
120 entry->enable(enable_all);
134 if (entry->remote_guid == guid)
136 entry->enabled =
true;
149 if (entries_.size() != last_state_.size())
154 for (
size_t i = 0; i < entries_.size(); ++i)
156 if (last_state_.at(i) != (entries_.at(i)->enabled ? 1 : 0))
188 entry->transport_should_process = entry->enabled;
202 if (index < entries_.size() &&
203 std::find(selections_.begin(), selections_.end(), index) == selections_.end())
205 selections_.push_back(index);
218 for (
size_t index : selections_)
240 for (
size_t index : selections_)
245 if (entry->
multicast.at(loc_index) == locator)
254 for (
size_t index : selections_)
259 if (entry->
unicast.at(loc_index) == locator)
276 template<
class UnaryPredicate>
278 UnaryPredicate action)
const
280 for (
size_t index : selections_)
289 action(entry->
unicast.at(loc_index));
306 using iterator_category = std::input_iterator_tag;
315 void go_to_next_entry()
318 while (++current_.selections_index < locator_selector_.selections_.size())
321 locator_selector_.entries_.at(locator_selector_.selections_[current_.selections_index]);
335 current_.state_multicast_done =
false;
355 : locator_selector_(locator_selector)
357 current_ = {(std::numeric_limits<size_t>::max)(), 0,
true,
nullptr};
367 : locator_selector_(other.locator_selector_)
368 , current_(other.current_)
375 assert(current_.selections_index < locator_selector_.selections_.size());
378 locator_selector_.entries_.at(locator_selector_.selections_[current_.selections_index]);
381 if (current_.state_multicast_done)
386 current_.state_index = 0;
400 current_.state_multicast_done =
true;
401 current_.state_index = 0;
424 return *
this ==
static_cast<const iterator&
>(other);
430 return !(*
this == other);
436 return (current_.locator == other.current_.
locator);
442 return !(*
this == other);
447 return current_.locator;
452 return *current_.locator;
477 bool initial_allow_to_send_ {
true};
480 bool force_reset_ {
false};
Resource limited wrapper of std::vector.
Definition ResourceLimitedVector.hpp:59
size_type size() const noexcept
Definition ResourceLimitedVector.hpp:479
reference at(size_type pos)
Wrappers to other basic vector methods.
Definition ResourceLimitedVector.hpp:370
static FASTDDS_EXPORTED_API bool isMulticast(const Locator_t &locator)
Checks if the locator has a multicast IP address.
Class Locator_t, uniquely identifies a communication channel for a particular transport.
Definition Locator.hpp:74
Definition LocatorSelector.hpp:304
iterator(const iterator &other)
Definition LocatorSelector.hpp:365
bool operator!=(const LocatorsIterator &other) const
Not equal to operator.
Definition LocatorSelector.hpp:427
iterator(const LocatorSelector &locator_selector, Position index_pos)
Definition LocatorSelector.hpp:352
bool operator==(const LocatorsIterator &other) const
Equal to operator.
Definition LocatorSelector.hpp:421
reference operator*() const
Dereference operator.
Definition LocatorSelector.hpp:450
Position
Definition LocatorSelector.hpp:347
@ Begin
Definition LocatorSelector.hpp:348
@ End
Definition LocatorSelector.hpp:349
iterator & operator++()
Increment operator.
Definition LocatorSelector.hpp:372
pointer operator->() const
Definition LocatorSelector.hpp:445
iterator begin() const
Definition LocatorSelector.hpp:457
LocatorSelector(const ResourceLimitedContainerConfig &entries_allocation)
Construct a LocatorSelector.
Definition LocatorSelector.hpp:63
void select(size_t index)
Marks an entry as selected.
Definition LocatorSelector.hpp:199
size_t selected_size() const
Count the number of selected locators.
Definition LocatorSelector.hpp:214
bool remove_entry(const GUID_t &guid)
Remove an entry from this selector.
Definition LocatorSelector.hpp:98
iterator end() const
Definition LocatorSelector.hpp:462
ResourceLimitedVector< LocatorSelectorEntry * > & transport_starts()
Called when the selection algorithm starts for a specific transport.
Definition LocatorSelector.hpp:184
bool state_has_changed() const
Check if enabling state has changed.
Definition LocatorSelector.hpp:147
bool add_entry(LocatorSelectorEntry *entry)
Add an entry to this selector.
Definition LocatorSelector.hpp:88
void selection_start()
Reset the selection state of the selector.
Definition LocatorSelector.hpp:168
void for_each(UnaryPredicate action) const
Performs an action on each selected locator.
Definition LocatorSelector.hpp:277
void enable(const GUID_t &guid)
Enable an entry given its GUID.
Definition LocatorSelector.hpp:129
void clear()
Clears all internal data.
Definition LocatorSelector.hpp:76
void reset(bool enable_all)
Reset the enabling state of the selector.
Definition LocatorSelector.hpp:113
bool is_selected(const Locator_t locator) const
Check if a locator is present in the selections of this object.
Definition LocatorSelector.hpp:235
Contains the RTPS protocol implementation.
Specifies the configuration of a resource limited collection.
Definition ResourceLimitedContainerConfig.hpp:36
Structure GUID_t, entity identifier, unique in DDS-RTPS Domain.
Definition Guid.hpp:40
Definition LocatorSelector.hpp:295
size_t selections_index
Definition LocatorSelector.hpp:296
size_t state_index
Definition LocatorSelector.hpp:297
bool state_multicast_done
Definition LocatorSelector.hpp:298
Locator_t * locator
Definition LocatorSelector.hpp:299
ResourceLimitedVector< size_t > unicast
Unicast locators selection state.
Definition LocatorSelectorEntry.hpp:60
ResourceLimitedVector< size_t > multicast
Multicast locators selection state.
Definition LocatorSelectorEntry.hpp:62
An entry for the LocatorSelector.
Definition LocatorSelectorEntry.hpp:39
ResourceLimitedVector< Locator_t > unicast
List of unicast locators to send data to the remote entity.
Definition LocatorSelectorEntry.hpp:137
ResourceLimitedVector< Locator_t > multicast
List of multicast locators to send data to the remote entity.
Definition LocatorSelectorEntry.hpp:139
GUID_t remote_guid
GUID of the remote entity.
Definition LocatorSelectorEntry.hpp:135
EntryState state
State of the entry.
Definition LocatorSelectorEntry.hpp:141
Provides a Locator's iterator interface that can be used by different Locator's containers.
Definition LocatorsIterator.hpp:33