ReaderLocator.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. /**
  15. * @file ReaderLocator.h
  16. */
  17. #ifndef _FASTDDS_RTPS_READERLOCATOR_H_
  18. #define _FASTDDS_RTPS_READERLOCATOR_H_
  19. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  20. #include <vector>
  21. #include <fastdds/rtps/common/Locator.h>
  22. #include <fastdds/rtps/common/Guid.h>
  23. #include <fastdds/rtps/common/SequenceNumber.h>
  24. #include <fastdds/rtps/messages/RTPSMessageGroup.h>
  25. #include <fastdds/rtps/common/LocatorSelectorEntry.hpp>
  26. namespace eprosima {
  27. namespace fastrtps {
  28. namespace rtps {
  29. class RTPSParticipantImpl;
  30. class RTPSWriter;
  31. class RTPSReader;
  32. /**
  33. * Class ReaderLocator, contains information about a remote reader, without saving its state.
  34. * It also implements RTPSMessageSenderInterface, so it can be used when separate sending is enabled.
  35. * @ingroup WRITER_MODULE
  36. */
  37. class ReaderLocator : public RTPSMessageSenderInterface
  38. {
  39. public:
  40. virtual ~ReaderLocator() = default;
  41. /**
  42. * Construct a ReaderLocator.
  43. *
  44. * @param owner Pointer to the RTPSWriter creating this object.
  45. * @param max_unicast_locators Maximum number of unicast locators to hold.
  46. * @param max_multicast_locators Maximum number of multicast locators to hold.
  47. */
  48. ReaderLocator(
  49. RTPSWriter* owner,
  50. size_t max_unicast_locators,
  51. size_t max_multicast_locators);
  52. bool expects_inline_qos() const
  53. {
  54. return expects_inline_qos_;
  55. }
  56. bool is_local_reader() const
  57. {
  58. return is_local_reader_;
  59. }
  60. RTPSReader* local_reader();
  61. void local_reader(
  62. RTPSReader* local_reader)
  63. {
  64. local_reader_ = local_reader;
  65. }
  66. const GUID_t& remote_guid() const
  67. {
  68. return locator_info_.remote_guid;
  69. }
  70. LocatorSelectorEntry* locator_selector_entry()
  71. {
  72. return &locator_info_;
  73. }
  74. /**
  75. * Try to start using this object for a new matched reader.
  76. *
  77. * @param remote_guid GUID of the remote reader.
  78. * @param unicast_locators Unicast locators of the remote reader.
  79. * @param multicast_locators Multicast locators of the remote reader.
  80. * @param expects_inline_qos Whether remote reader expects to receive inline QoS.
  81. *
  82. * @return false when this object was already started, true otherwise.
  83. */
  84. bool start(
  85. const GUID_t& remote_guid,
  86. const ResourceLimitedVector<Locator_t>& unicast_locators,
  87. const ResourceLimitedVector<Locator_t>& multicast_locators,
  88. bool expects_inline_qos);
  89. /**
  90. * Try to update information of this object.
  91. *
  92. * @param unicast_locators Unicast locators of the remote reader.
  93. * @param multicast_locators Multicast locators of the remote reader.
  94. * @param expects_inline_qos Whether remote reader expects to receive inline QoS.
  95. *
  96. * @return true when information has changed, false otherwise.
  97. */
  98. bool update(
  99. const ResourceLimitedVector<Locator_t>& unicast_locators,
  100. const ResourceLimitedVector<Locator_t>& multicast_locators,
  101. bool expects_inline_qos);
  102. /**
  103. * Try to stop using this object for an unmatched reader.
  104. *
  105. * @param remote_guid GUID of the remote reader.
  106. *
  107. * @return true if this object was started for remote_guid, false otherwise.
  108. */
  109. bool stop(
  110. const GUID_t& remote_guid);
  111. /**
  112. * Check if the destinations managed by this sender interface have changed.
  113. *
  114. * @return true if destinations have changed, false otherwise.
  115. */
  116. bool destinations_have_changed() const override
  117. {
  118. return false;
  119. }
  120. /**
  121. * Get a GUID prefix representing all destinations.
  122. *
  123. * @return When all the destinations share the same prefix (i.e. belong to the same participant)
  124. * that prefix is returned. When there are no destinations, or they belong to different
  125. * participants, c_GuidPrefix_Unknown is returned.
  126. */
  127. GuidPrefix_t destination_guid_prefix() const override
  128. {
  129. return locator_info_.remote_guid.guidPrefix;
  130. }
  131. /**
  132. * Get the GUID prefix of all the destination participants.
  133. *
  134. * @return a const reference to a vector with the GUID prefix of all destination participants.
  135. */
  136. const std::vector<GuidPrefix_t>& remote_participants() const override
  137. {
  138. return guid_prefix_as_vector_;
  139. }
  140. /**
  141. * Get the GUID of all destinations.
  142. *
  143. * @return a const reference to a vector with the GUID of all destinations.
  144. */
  145. const std::vector<GUID_t>& remote_guids() const override
  146. {
  147. return guid_as_vector_;
  148. }
  149. /**
  150. * Send a message through this interface.
  151. *
  152. * @param message Pointer to the buffer with the message already serialized.
  153. * @param max_blocking_time_point Future timepoint where blocking send should end.
  154. */
  155. bool send(
  156. CDRMessage_t* message,
  157. std::chrono::steady_clock::time_point& max_blocking_time_point) const override;
  158. private:
  159. RTPSWriter* owner_;
  160. RTPSParticipantImpl* participant_owner_;
  161. LocatorSelectorEntry locator_info_;
  162. bool expects_inline_qos_;
  163. bool is_local_reader_;
  164. RTPSReader* local_reader_;
  165. std::vector<GuidPrefix_t> guid_prefix_as_vector_;
  166. std::vector<GUID_t> guid_as_vector_;
  167. };
  168. } /* namespace rtps */
  169. } /* namespace fastrtps */
  170. } /* namespace eprosima */
  171. #endif
  172. #endif /* _FASTDDS_RTPS_READERLOCATOR_H_ */