EDPServer.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 EDPServer.h
  16. *
  17. */
  18. #ifndef _FASTDDS_RTPS_EDPSERVER_H_
  19. #define _FASTDDS_RTPS_EDPSERVER_H_
  20. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  21. #include <fastdds/rtps/common/CacheChange.h>
  22. #include <fastdds/rtps/builtin/data/ParticipantProxyData.h>
  23. #include <fastdds/rtps/builtin/discovery/endpoint/EDPSimple.h>
  24. #include <set>
  25. namespace eprosima {
  26. namespace fastrtps {
  27. namespace rtps {
  28. class EDPServerPUBListener;
  29. class EDPServerSUBListener;
  30. /**
  31. * Class EDPServer, implements the Endpoint Discovery Protocol for server participants
  32. * Inherits from EDPSimple class.
  33. *@ingroup DISCOVERY_MODULE
  34. */
  35. class EDPServer : public EDPSimple
  36. {
  37. friend class EDPServerPUBListener;
  38. friend class EDPServerSUBListener;
  39. typedef std::set<InstanceHandle_t> key_list;
  40. //! Keys to wipe out from WriterHistory because its related Participants have been removed
  41. key_list _PUBdemises, _SUBdemises;
  42. //! TRANSIENT or TRANSIENT_LOCAL durability;
  43. DurabilityKind_t _durability;
  44. public:
  45. /**
  46. * Constructor.
  47. * @param p Pointer to the PDP
  48. * @param part Pointer to the RTPSParticipantImpl
  49. * @param durability_kind the kind of persistence we want for the discovery data
  50. */
  51. EDPServer(
  52. PDP* p,
  53. RTPSParticipantImpl* part,
  54. DurabilityKind_t durability_kind)
  55. : EDPSimple(p, part)
  56. , _durability(durability_kind)
  57. {
  58. }
  59. ~EDPServer() override
  60. {
  61. }
  62. /**
  63. * This method generates the corresponding change in the subscription writer and send it to all known remote endpoints.
  64. * @param reader Pointer to the Reader object.
  65. * @param rdata Pointer to the ReaderProxyData object.
  66. * @return true if correct.
  67. */
  68. bool processLocalReaderProxyData(
  69. RTPSReader* reader,
  70. ReaderProxyData* rdata) override;
  71. /**
  72. * This method generates the corresponding change in the publciations writer and send it to all known remote endpoints.
  73. * @param writer Pointer to the Writer object.
  74. * @param wdata Pointer to the WriterProxyData object.
  75. * @return true if correct.
  76. */
  77. bool processLocalWriterProxyData(
  78. RTPSWriter* writer,
  79. WriterProxyData* wdata) override;
  80. /**
  81. * This methods generates the change disposing of the local Reader and calls the unpairing and removal methods of the base class.
  82. * @param R Pointer to the RTPSReader object.
  83. * @return True if correct.
  84. */
  85. bool removeLocalReader(
  86. RTPSReader*R) override;
  87. /**
  88. * This methods generates the change disposing of the local Writer and calls the unpairing and removal methods of the base class.
  89. * @param W Pointer to the RTPSWriter object.
  90. * @return True if correct.
  91. */
  92. bool removeLocalWriter(
  93. RTPSWriter*W) override;
  94. /**
  95. * Some History data is flag for defer removal till every client
  96. * acknowledges reception
  97. * @return True if trimming must be done
  98. */
  99. inline bool pendingHistoryCleaning()
  100. {
  101. return !(_PUBdemises.empty() && _SUBdemises.empty());
  102. }
  103. //! Callback to remove unnecesary WriterHistory info
  104. bool trimPUBWriterHistory()
  105. {
  106. return trimWriterHistory<ProxyHashTable<WriterProxyData>*>(_PUBdemises,
  107. *publications_writer_.first, *publications_writer_.second, &ParticipantProxyData::m_writers);
  108. }
  109. bool trimSUBWriterHistory()
  110. {
  111. return trimWriterHistory<ProxyHashTable<ReaderProxyData>*>(_SUBdemises,
  112. *subscriptions_writer_.first, *subscriptions_writer_.second, &ParticipantProxyData::m_readers);
  113. }
  114. //! returns true if loading info from persistency database
  115. bool ongoingDeserialization();
  116. //! Process the info recorded in the persistence database
  117. void processPersistentData();
  118. protected:
  119. /**
  120. * Add participant CacheChange_ts from reader to writer
  121. * @return True if successfully modified WriterHistory
  122. */
  123. bool addPublisherFromHistory(
  124. CacheChange_t& c)
  125. {
  126. return addEndpointFromHistory(*publications_writer_.first, *publications_writer_.second, c);
  127. }
  128. bool addSubscriberFromHistory(
  129. CacheChange_t& c)
  130. {
  131. return addEndpointFromHistory(*subscriptions_writer_.first, *subscriptions_writer_.second, c);
  132. }
  133. /**
  134. * Trigger the participant CacheChange_t removal system
  135. * @return True if successfully modified WriterHistory
  136. */
  137. void removePublisherFromHistory(
  138. const InstanceHandle_t&);
  139. void removeSubscriberFromHistory(
  140. const InstanceHandle_t&);
  141. private:
  142. /**
  143. * Callback to remove unnecesary WriterHistory info common implementation
  144. * @return True if trim is finished
  145. */
  146. template<class ProxyCont>
  147. bool trimWriterHistory(
  148. key_list& _demises,
  149. StatefulWriter& writer,
  150. WriterHistory& history,
  151. ProxyCont ParticipantProxyData::* pCont);
  152. //! addPublisherFromHistory and addSubscriberFromHistory common implementation
  153. bool addEndpointFromHistory(
  154. StatefulWriter& writer,
  155. WriterHistory& history,
  156. CacheChange_t& c);
  157. /**
  158. * Create local SEDP Endpoints based on the DiscoveryAttributes.
  159. * @return True if correct.
  160. */
  161. virtual bool createSEDPEndpoints() override;
  162. };
  163. } /* namespace rtps */
  164. } /* namespace fastrtps */
  165. } /* namespace eprosima */
  166. #endif
  167. #endif /* _FASTDDS_RTPS_EDPSERVER_H_ */