EDPSimple.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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 EDPSimple.h
  16. *
  17. */
  18. #ifndef _FASTDDS_RTPS_EDPSIMPLE_H_
  19. #define _FASTDDS_RTPS_EDPSIMPLE_H_
  20. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  21. #include <fastdds/rtps/builtin/discovery/endpoint/EDP.h>
  22. #include <fastdds/rtps/builtin/data/WriterProxyData.h>
  23. #include <fastdds/rtps/builtin/data/ReaderProxyData.h>
  24. namespace eprosima {
  25. namespace fastrtps {
  26. namespace rtps {
  27. class StatefulReader;
  28. class StatefulWriter;
  29. class RTPSWriter;
  30. class RTPSReader;
  31. class ReaderHistory;
  32. class WriterHistory;
  33. class HistoryAttributes;
  34. class ReaderAttributes;
  35. class WriterAttributes;
  36. class EDPListener;
  37. /**
  38. * Class EDPSimple, implements the Simple Endpoint Discovery Protocol defined in the RTPS specification.
  39. * Inherits from EDP class.
  40. *@ingroup DISCOVERY_MODULE
  41. */
  42. class EDPSimple : public EDP
  43. {
  44. using t_p_StatefulWriter = std::pair<StatefulWriter*, WriterHistory*>;
  45. using t_p_StatefulReader = std::pair<StatefulReader*, ReaderHistory*>;
  46. public:
  47. /**
  48. * Constructor.
  49. * @param p Pointer to the PDP
  50. * @param part Pointer to the RTPSParticipantImpl
  51. */
  52. EDPSimple(
  53. PDP* p,
  54. RTPSParticipantImpl* part);
  55. virtual ~EDPSimple();
  56. //!Discovery attributes.
  57. BuiltinAttributes m_discovery;
  58. //!Pointer to the Publications Writer (only created if indicated in the DiscoveryAtributes).
  59. t_p_StatefulWriter publications_writer_;
  60. //!Pointer to the Subscriptions Writer (only created if indicated in the DiscoveryAtributes).
  61. t_p_StatefulWriter subscriptions_writer_;
  62. //!Pointer to the Publications Reader (only created if indicated in the DiscoveryAtributes).
  63. t_p_StatefulReader publications_reader_;
  64. //!Pointer to the Subscriptions Reader (only created if indicated in the DiscoveryAtributes).
  65. t_p_StatefulReader subscriptions_reader_;
  66. #if HAVE_SECURITY
  67. t_p_StatefulWriter publications_secure_writer_;
  68. t_p_StatefulReader publications_secure_reader_;
  69. t_p_StatefulWriter subscriptions_secure_writer_;
  70. t_p_StatefulReader subscriptions_secure_reader_;
  71. #endif
  72. //!Pointer to the listener associated with PubReader and PubWriter.
  73. EDPListener* publications_listener_;
  74. //!Pointer to the listener associated with SubReader and SubWriter.
  75. EDPListener* subscriptions_listener_;
  76. /**
  77. * Initialization method.
  78. * @param attributes Reference to the DiscoveryAttributes.
  79. * @return True if correct.
  80. */
  81. bool initEDP(
  82. BuiltinAttributes& attributes) override;
  83. /**
  84. * This method assigns the remote builtin endpoints that the remote RTPSParticipant indicates is using to our local builtin endpoints.
  85. * @param pdata Pointer to the RTPSParticipantProxyData object.
  86. */
  87. void assignRemoteEndpoints(
  88. const ParticipantProxyData& pdata) override;
  89. /**
  90. * Remove remote endpoints from the endpoint discovery protocol
  91. * @param pdata Pointer to the ParticipantProxyData to remove
  92. */
  93. void removeRemoteEndpoints(
  94. ParticipantProxyData* pdata) override;
  95. //! Verify if the given participant EDP enpoints are matched with us
  96. bool areRemoteEndpointsMatched(
  97. const ParticipantProxyData* pdata) override;
  98. /**
  99. * This method generates the corresponding change in the subscription writer and send it to all known remote endpoints.
  100. * @param reader Pointer to the Reader object.
  101. * @param rdata Pointer to the ReaderProxyData object.
  102. * @return true if correct.
  103. */
  104. bool processLocalReaderProxyData(
  105. RTPSReader* reader,
  106. ReaderProxyData* rdata) override;
  107. /**
  108. * This method generates the corresponding change in the publciations writer and send it to all known remote endpoints.
  109. * @param writer Pointer to the Writer object.
  110. * @param wdata Pointer to the WriterProxyData object.
  111. * @return true if correct.
  112. */
  113. bool processLocalWriterProxyData(
  114. RTPSWriter* writer,
  115. WriterProxyData* wdata) override;
  116. /**
  117. * This methods generates the change disposing of the local Reader and calls the unpairing and removal methods of the base class.
  118. * @param R Pointer to the RTPSReader object.
  119. * @return True if correct.
  120. */
  121. bool removeLocalReader(
  122. RTPSReader*R) override;
  123. /**
  124. * This methods generates the change disposing of the local Writer and calls the unpairing and removal methods of the base class.
  125. * @param W Pointer to the RTPSWriter object.
  126. * @return True if correct.
  127. */
  128. bool removeLocalWriter(
  129. RTPSWriter*W) override;
  130. protected:
  131. /**
  132. * Initialization of history attributes for EDP built-in readers
  133. *
  134. * @param [out] attributes History attributes to initialize
  135. */
  136. virtual void set_builtin_reader_history_attributes(
  137. HistoryAttributes& attributes);
  138. /**
  139. * Initialization of history attributes for EDP built-in writers
  140. *
  141. * @param [out] attributes History attributes to initialize
  142. */
  143. virtual void set_builtin_writer_history_attributes(
  144. HistoryAttributes& attributes);
  145. /**
  146. * Initialization of reader attributes for EDP built-in readers
  147. *
  148. * @param [out] attributes Reader attributes to initialize
  149. */
  150. virtual void set_builtin_reader_attributes(
  151. ReaderAttributes& attributes);
  152. /**
  153. * Initialization of writer attributes for EDP built-in writers
  154. *
  155. * @param [out] attributes Writer attributes to initialize
  156. */
  157. virtual void set_builtin_writer_attributes(
  158. WriterAttributes& attributes);
  159. /**
  160. * Create local SEDP Endpoints based on the DiscoveryAttributes.
  161. * @return True if correct.
  162. */
  163. virtual bool createSEDPEndpoints();
  164. /**
  165. * Create a cache change on a builtin writer and serialize a WriterProxyData on it.
  166. * @param [in] data The WriterProxyData object to be serialized.
  167. * @param [in] writer The writer,history pair where the change should be added.
  168. * @param [in] remove_same_instance Should previous changes with same key be removed?
  169. * @param [out] created_change Where the pointer to the created change should be returned.
  170. * @return false if data could not be serialized into the created change.
  171. */
  172. bool serialize_writer_proxy_data(
  173. const WriterProxyData& data,
  174. const t_p_StatefulWriter& writer,
  175. bool remove_same_instance,
  176. CacheChange_t** created_change);
  177. /**
  178. * Create a cache change on a builtin writer and serialize a ReaderProxyData on it.
  179. * @param [in] data The ReaderProxyData object to be serialized.
  180. * @param [in] writer The writer,history pair where the change should be added.
  181. * @param [in] remove_same_instance Should previous changes with same key be removed?
  182. * @param [out] created_change Where the pointer to the created change should be returned.
  183. * @return false if data could not be serialized into the created change.
  184. */
  185. bool serialize_reader_proxy_data(
  186. const ReaderProxyData& data,
  187. const t_p_StatefulWriter& writer,
  188. bool remove_same_instance,
  189. CacheChange_t** created_change);
  190. //! Process the info recorded in the persistence database
  191. static void processPersistentData(t_p_StatefulReader & reader, t_p_StatefulWriter & writer);
  192. private:
  193. /**
  194. * Create a cache change on a builtin writer and serialize a ProxyData on it.
  195. * @param [in] data The ProxyData object to be serialized.
  196. * @param [in] writer The writer,history pair where the change should be added.
  197. * @param [in] remove_same_instance Should previous changes with same key be removed?
  198. * @param [out] created_change Where the pointer to the created change should be returned.
  199. * @return false if data could not be serialized into the created change.
  200. */
  201. template<typename ProxyData>
  202. bool serialize_proxy_data(
  203. const ProxyData& data,
  204. const t_p_StatefulWriter& writer,
  205. bool remove_same_instance,
  206. CacheChange_t** created_change);
  207. #if HAVE_SECURITY
  208. bool create_sedp_secure_endpoints();
  209. bool pairing_remote_writer_with_local_builtin_reader_after_security(
  210. const GUID_t& local_reader,
  211. const WriterProxyData& remote_writer_data) override;
  212. bool pairing_remote_reader_with_local_builtin_writer_after_security(
  213. const GUID_t& local_writer,
  214. const ReaderProxyData& remote_reader_data) override;
  215. #endif
  216. std::mutex temp_data_lock_;
  217. ReaderProxyData temp_reader_proxy_data_;
  218. WriterProxyData temp_writer_proxy_data_;
  219. };
  220. } /* namespace rtps */
  221. } /* namespace fastrtps */
  222. } /* namespace eprosima */
  223. #endif
  224. #endif /* _FASTDDS_RTPS_EDPSIMPLE_H_ */