LocatorSelectorEntry.hpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright 2019 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. /**
  15. * @file LocatorSelectorEntry.hpp
  16. */
  17. #ifndef _FASTDDS_RTPS_COMMON_LOCATORSELECTORENTRY_HPP_
  18. #define _FASTDDS_RTPS_COMMON_LOCATORSELECTORENTRY_HPP_
  19. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  20. #include <fastdds/rtps/common/Guid.h>
  21. #include <fastdds/rtps/common/Locator.h>
  22. #include <fastrtps/utils/collections/ResourceLimitedVector.hpp>
  23. namespace eprosima {
  24. namespace fastrtps {
  25. namespace rtps {
  26. /**
  27. * An entry for the @ref LocatorSelector.
  28. *
  29. * This class holds the locators of a remote endpoint along with data required for the locator selection algorithm.
  30. * Can be easyly integrated inside other classes, such as @ref ReaderProxyData and @ref WriterProxyData.
  31. */
  32. struct LocatorSelectorEntry
  33. {
  34. /**
  35. * Holds the selection state of the locators held by a LocatorSelectorEntry
  36. */
  37. struct EntryState
  38. {
  39. /**
  40. * Construct an EntryState object.
  41. *
  42. * @param max_unicast_locators Maximum number of unicast locators to held by parent LocatorSelectorEntry.
  43. * @param max_multicast_locators Maximum number of multicast locators to held by parent LocatorSelectorEntry.
  44. */
  45. EntryState(
  46. size_t max_unicast_locators,
  47. size_t max_multicast_locators)
  48. : unicast(ResourceLimitedContainerConfig::fixed_size_configuration(max_unicast_locators))
  49. , multicast(ResourceLimitedContainerConfig::fixed_size_configuration(max_multicast_locators))
  50. {
  51. }
  52. //! Unicast locators selection state
  53. ResourceLimitedVector<size_t> unicast;
  54. //! Multicast locators selection state
  55. ResourceLimitedVector<size_t> multicast;
  56. };
  57. /**
  58. * Construct a LocatorSelectorEntry.
  59. *
  60. * @param max_unicast_locators Maximum number of unicast locators to hold.
  61. * @param max_multicast_locators Maximum number of multicast locators to hold.
  62. */
  63. LocatorSelectorEntry(
  64. size_t max_unicast_locators,
  65. size_t max_multicast_locators)
  66. : remote_guid(c_Guid_Unknown)
  67. , unicast(ResourceLimitedContainerConfig::fixed_size_configuration(max_unicast_locators))
  68. , multicast(ResourceLimitedContainerConfig::fixed_size_configuration(max_multicast_locators))
  69. , state(max_unicast_locators, max_multicast_locators)
  70. , enabled(false)
  71. , transport_should_process(false)
  72. {
  73. }
  74. /**
  75. * Set the enabled value.
  76. *
  77. * @param should_enable Whether this entry should be enabled.
  78. */
  79. void enable(bool should_enable)
  80. {
  81. enabled = should_enable && remote_guid != c_Guid_Unknown;
  82. }
  83. /**
  84. * Reset the selections.
  85. */
  86. void reset()
  87. {
  88. state.unicast.clear();
  89. state.multicast.clear();
  90. }
  91. //! GUID of the remote entity.
  92. GUID_t remote_guid;
  93. //! List of unicast locators to send data to the remote entity.
  94. ResourceLimitedVector<Locator_t> unicast;
  95. //! List of multicast locators to send data to the remote entity.
  96. ResourceLimitedVector<Locator_t> multicast;
  97. //! State of the entry
  98. EntryState state;
  99. //! Indicates whether this entry should be taken into consideration.
  100. bool enabled;
  101. //! A temporary value for each transport to help optimizing some use cases.
  102. bool transport_should_process;
  103. };
  104. } /* namespace rtps */
  105. } /* namespace fastrtps */
  106. } /* namespace eprosima */
  107. #endif /* DOXYGEN_SHOULD_SKIP_THIS_PUBLIC */
  108. #endif /* _FASTDDS_RTPS_COMMON_LOCATORSELECTORENTRY_HPP_ */