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)
89 return entries_.push_back(entry) !=
nullptr;
99 return entries_.remove_if(
117 last_state_.
push_back(entry->enabled ? 1 : 0);
118 entry->enable(enable_all);
132 if (entry->remote_guid == guid)
134 entry->enabled =
true;
147 if (entries_.size() != last_state_.
size())
152 for (
size_t i = 0; i < entries_.size(); ++i)
154 if (last_state_.
at(i) != (entries_.at(i)->enabled ? 1 : 0))
186 entry->transport_should_process = entry->enabled;
200 if (index < entries_.size() &&
201 std::find(selections_.
begin(), selections_.
end(), index) == selections_.
end())
216 for (
size_t index : selections_)
238 for (
size_t index : selections_)
243 if (entry->
multicast.at(loc_index) == locator)
252 for (
size_t index : selections_)
257 if (entry->
unicast.at(loc_index) == locator)
274 template<
class UnaryPredicate>
276 UnaryPredicate action)
const
278 for (
size_t index : selections_)
287 action(entry->
unicast.at(loc_index));
304 using iterator_category = std::input_iterator_tag;
313 void go_to_next_entry()
319 locator_selector_.entries_.at(locator_selector_.selections_[current_.
selections_index]);
353 : locator_selector_(locator_selector)
355 current_ = {(std::numeric_limits<size_t>::max)(), 0,
true,
nullptr};
365 : locator_selector_(other.locator_selector_)
366 , current_(other.current_)
376 locator_selector_.entries_.at(locator_selector_.selections_[current_.
selections_index]);
422 return *
this ==
static_cast<const iterator&
>(other);
428 return !(*
this == other);
440 return !(*
this == other);
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
iterator begin() noexcept
Definition ResourceLimitedVector.hpp:414
pointer push_back(const value_type &val)
Add element at the end.
Definition ResourceLimitedVector.hpp:174
void clear()
Definition ResourceLimitedVector.hpp:494
iterator end() noexcept
Definition ResourceLimitedVector.hpp:429
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:71
Definition LocatorSelector.hpp:302
iterator(const iterator &other)
Definition LocatorSelector.hpp:363
bool operator!=(const LocatorsIterator &other) const
Not equal to operator.
Definition LocatorSelector.hpp:425
iterator(const LocatorSelector &locator_selector, Position index_pos)
Definition LocatorSelector.hpp:350
bool operator==(const LocatorsIterator &other) const
Equal to operator.
Definition LocatorSelector.hpp:419
reference operator*() const
Dereference operator.
Definition LocatorSelector.hpp:448
Position
Definition LocatorSelector.hpp:345
iterator & operator++()
Increment operator.
Definition LocatorSelector.hpp:370
pointer operator->() const
Definition LocatorSelector.hpp:443
A class used for the efficient selection of locators when sending data to multiple entities.
Definition LocatorSelector.hpp:55
iterator begin() const
Definition LocatorSelector.hpp:455
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:197
size_t selected_size() const
Count the number of selected locators.
Definition LocatorSelector.hpp:212
bool remove_entry(const GUID_t &guid)
Remove an entry from this selector.
Definition LocatorSelector.hpp:96
iterator end() const
Definition LocatorSelector.hpp:460
ResourceLimitedVector< LocatorSelectorEntry * > & transport_starts()
Called when the selection algorithm starts for a specific transport.
Definition LocatorSelector.hpp:182
bool state_has_changed() const
Check if enabling state has changed.
Definition LocatorSelector.hpp:145
bool add_entry(LocatorSelectorEntry *entry)
Add an entry to this selector.
Definition LocatorSelector.hpp:86
void selection_start()
Reset the selection state of the selector.
Definition LocatorSelector.hpp:166
void for_each(UnaryPredicate action) const
Performs an action on each selected locator.
Definition LocatorSelector.hpp:275
void enable(const GUID_t &guid)
Enable an entry given its GUID.
Definition LocatorSelector.hpp:127
void clear()
Clears all internal data.
Definition LocatorSelector.hpp:74
void reset(bool enable_all)
Reset the enabling state of the selector.
Definition LocatorSelector.hpp:111
bool is_selected(const Locator_t locator) const
Check if a locator is present in the selections of this object.
Definition LocatorSelector.hpp:233
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:293
size_t selections_index
Definition LocatorSelector.hpp:294
size_t state_index
Definition LocatorSelector.hpp:295
bool state_multicast_done
Definition LocatorSelector.hpp:296
Locator_t * locator
Definition LocatorSelector.hpp:297
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:136
ResourceLimitedVector< Locator_t > multicast
List of multicast locators to send data to the remote entity.
Definition LocatorSelectorEntry.hpp:138
GUID_t remote_guid
GUID of the remote entity.
Definition LocatorSelectorEntry.hpp:134
EntryState state
State of the entry.
Definition LocatorSelectorEntry.hpp:140
Provides a Locator's iterator interface that can be used by different Locator's containers.
Definition LocatorsIterator.hpp:33