EDP.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 EDP.h
  16. *
  17. */
  18. #ifndef _FASTDDS_RTPS_EDP_H_
  19. #define _FASTDDS_RTPS_EDP_H_
  20. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  21. #include <fastdds/rtps/attributes/RTPSParticipantAttributes.h>
  22. #include <fastdds/rtps/builtin/data/ReaderProxyData.h>
  23. #include <fastdds/rtps/builtin/data/WriterProxyData.h>
  24. #include <fastdds/rtps/common/Guid.h>
  25. #include <fastdds/dds/core/status/PublicationMatchedStatus.hpp>
  26. #include <fastdds/dds/core/status/SubscriptionMatchedStatus.hpp>
  27. namespace eprosima {
  28. namespace fastrtps {
  29. namespace types {
  30. class TypeIdentifier;
  31. }
  32. class TopicAttributes;
  33. namespace rtps {
  34. class PDP;
  35. class ParticipantProxyData;
  36. class RTPSWriter;
  37. class RTPSReader;
  38. class WriterProxyData;
  39. class RTPSParticipantImpl;
  40. /**
  41. * Class EDP, base class for Endpoint Discovery Protocols. It contains generic methods used by the two EDP implemented (EDPSimple and EDPStatic), as well as abstract methods
  42. * definitions required by the specific implementations.
  43. * @ingroup DISCOVERY_MODULE
  44. */
  45. class EDP
  46. {
  47. public:
  48. /**
  49. * Constructor.
  50. * @param p Pointer to the PDPSimple
  51. * @param part Pointer to the RTPSParticipantImpl
  52. */
  53. EDP(
  54. PDP* p,
  55. RTPSParticipantImpl* part);
  56. virtual ~EDP();
  57. /**
  58. * Abstract method to initialize the EDP.
  59. * @param attributes DiscoveryAttributes structure.
  60. * @return True if correct.
  61. */
  62. virtual bool initEDP(
  63. BuiltinAttributes& attributes) = 0;
  64. /**
  65. * Abstract method that assigns remote endpoints when a new RTPSParticipantProxyData is discovered.
  66. * @param pdata Discovered ParticipantProxyData
  67. */
  68. virtual void assignRemoteEndpoints(
  69. const ParticipantProxyData& pdata) = 0;
  70. /**
  71. * Remove remote endpoints from the endpoint discovery protocol
  72. * @param pdata Pointer to the ParticipantProxyData to remove
  73. */
  74. virtual void removeRemoteEndpoints(
  75. ParticipantProxyData* pdata)
  76. {
  77. (void) pdata;
  78. }
  79. //! Verify if the given participant EDP enpoints are matched with us
  80. virtual bool areRemoteEndpointsMatched(
  81. const ParticipantProxyData* )
  82. {
  83. return false;
  84. }
  85. /**
  86. * Abstract method that removes a local Reader from the discovery method
  87. * @param R Pointer to the Reader to remove.
  88. * @return True if correctly removed.
  89. */
  90. virtual bool removeLocalReader(
  91. RTPSReader* R) = 0;
  92. /**
  93. * Abstract method that removes a local Writer from the discovery method
  94. * @param W Pointer to the Writer to remove.
  95. * @return True if correctly removed.
  96. */
  97. virtual bool removeLocalWriter(
  98. RTPSWriter* W) = 0;
  99. /**
  100. * After a new local ReaderProxyData has been created some processing is needed (depends on the implementation).
  101. * @param reader Pointer to the Reader object.
  102. * @param rdata Pointer to the ReaderProxyData object.
  103. * @return True if correct.
  104. */
  105. virtual bool processLocalReaderProxyData(
  106. RTPSReader* reader,
  107. ReaderProxyData* rdata) = 0;
  108. /**
  109. * After a new local WriterProxyData has been created some processing is needed (depends on the implementation).
  110. * @param writer Pointer to the Writer object.
  111. * @param wdata Pointer to the Writer ProxyData object.
  112. * @return True if correct.
  113. */
  114. virtual bool processLocalWriterProxyData(
  115. RTPSWriter* writer,
  116. WriterProxyData* wdata) = 0;
  117. /**
  118. * Create a new ReaderPD for a local Reader.
  119. * @param R Pointer to the RTPSReader.
  120. * @param att Attributes of the associated topic
  121. * @param qos QoS policies dictated by the subscriber
  122. * @return True if correct.
  123. */
  124. bool newLocalReaderProxyData(
  125. RTPSReader* R,
  126. const TopicAttributes& att,
  127. const ReaderQos& qos);
  128. /**
  129. * Create a new ReaderPD for a local Writer.
  130. * @param W Pointer to the RTPSWriter.
  131. * @param att Attributes of the associated topic
  132. * @param qos QoS policies dictated by the publisher
  133. * @return True if correct.
  134. */
  135. bool newLocalWriterProxyData(
  136. RTPSWriter* W,
  137. const TopicAttributes& att,
  138. const WriterQos& qos);
  139. /**
  140. * A previously created Reader has been updated
  141. * @param R Pointer to the reader;
  142. * @param att Attributes of the associated topic
  143. * @param qos QoS policies dictated by the subscriber
  144. * @return True if correctly updated
  145. */
  146. bool updatedLocalReader(
  147. RTPSReader* R,
  148. const TopicAttributes& att,
  149. const ReaderQos& qos);
  150. /**
  151. * A previously created Writer has been updated
  152. * @param W Pointer to the Writer
  153. * @param att Attributes of the associated topic
  154. * @param qos QoS policies dictated by the publisher
  155. * @return True if correctly updated
  156. */
  157. bool updatedLocalWriter(
  158. RTPSWriter* W,
  159. const TopicAttributes& att,
  160. const WriterQos& qos);
  161. /**
  162. * Check the validity of a matching between a RTPSWriter and a ReaderProxyData object.
  163. * @param wdata Pointer to the WriterProxyData object.
  164. * @param rdata Pointer to the ReaderProxyData object.
  165. * @return True if the two can be matched.
  166. */
  167. bool validMatching(
  168. const WriterProxyData* wdata,
  169. const ReaderProxyData* rdata);
  170. /**
  171. * Check the validity of a matching between a RTPSReader and a WriterProxyData object.
  172. * @param rdata Pointer to the ReaderProxyData object.
  173. * @param wdata Pointer to the WriterProxyData object.
  174. * @return True if the two can be matched.
  175. */
  176. bool validMatching(
  177. const ReaderProxyData* rdata,
  178. const WriterProxyData* wdata);
  179. /**
  180. * Unpair a WriterProxyData object from all local readers.
  181. * @param participant_guid GUID of the participant.
  182. * @param writer_guid GUID of the writer.
  183. * @return True if correct.
  184. */
  185. bool unpairWriterProxy(
  186. const GUID_t& participant_guid,
  187. const GUID_t& writer_guid);
  188. /**
  189. * Unpair a ReaderProxyData object from all local writers.
  190. * @param participant_guid GUID of the participant.
  191. * @param reader_guid GUID of the reader.
  192. * @return True if correct.
  193. */
  194. bool unpairReaderProxy(
  195. const GUID_t& participant_guid,
  196. const GUID_t& reader_guid);
  197. /**
  198. * Try to pair/unpair ReaderProxyData.
  199. * @param participant_guid Identifier of the participant.
  200. * @param rdata Pointer to the ReaderProxyData object.
  201. * @return True.
  202. */
  203. bool pairing_reader_proxy_with_any_local_writer(
  204. const GUID_t& participant_guid,
  205. ReaderProxyData* rdata);
  206. #if HAVE_SECURITY
  207. bool pairing_reader_proxy_with_local_writer(
  208. const GUID_t& local_writer,
  209. const GUID_t& remote_participant_guid,
  210. ReaderProxyData& rdata);
  211. bool pairing_remote_reader_with_local_writer_after_security(
  212. const GUID_t& local_writer,
  213. const ReaderProxyData& remote_reader_data);
  214. #endif
  215. /**
  216. * Try to pair/unpair WriterProxyData.
  217. * @param participant_guid Identifier of the participant.
  218. * @param wdata Pointer to the WriterProxyData.
  219. * @return True.
  220. */
  221. bool pairing_writer_proxy_with_any_local_reader(
  222. const GUID_t& participant_guid,
  223. WriterProxyData* wdata);
  224. #if HAVE_SECURITY
  225. bool pairing_writer_proxy_with_local_reader(
  226. const GUID_t& local_reader,
  227. const GUID_t& remote_participant_guid,
  228. WriterProxyData& wdata);
  229. bool pairing_remote_writer_with_local_reader_after_security(
  230. const GUID_t& local_reader,
  231. const WriterProxyData& remote_writer_data);
  232. virtual bool pairing_remote_writer_with_local_builtin_reader_after_security(
  233. const GUID_t& /*local_reader*/,
  234. const WriterProxyData& /*remote_writer_data*/)
  235. {
  236. return false;
  237. }
  238. virtual bool pairing_remote_reader_with_local_builtin_writer_after_security(
  239. const GUID_t& /*local_writer*/,
  240. const ReaderProxyData& /*remote_reader_data*/)
  241. {
  242. return false;
  243. }
  244. #endif
  245. const fastdds::dds::SubscriptionMatchedStatus& update_subscription_matched_status(
  246. const GUID_t& reader_guid,
  247. const GUID_t& writer_guid,
  248. int change);
  249. const fastdds::dds::PublicationMatchedStatus& update_publication_matched_status(
  250. const GUID_t& reader_guid,
  251. const GUID_t& writer_guid,
  252. int change);
  253. //! Pointer to the PDP object that contains the endpoint discovery protocol.
  254. PDP* mp_PDP;
  255. //! Pointer to the RTPSParticipant.
  256. RTPSParticipantImpl* mp_RTPSParticipant;
  257. private:
  258. /**
  259. * Try to pair/unpair a local Reader against all possible writerProxy Data.
  260. * @param R Pointer to the Reader
  261. * @param participant_guid
  262. * @param rdata
  263. * @return True
  264. */
  265. bool pairingReader(
  266. RTPSReader* R,
  267. const GUID_t& participant_guid,
  268. const ReaderProxyData& rdata);
  269. /**
  270. * Try to pair/unpair a local Writer against all possible readerProxy Data.
  271. * @param W Pointer to the Writer
  272. * @param participant_guid
  273. * @param wdata
  274. * @return True
  275. */
  276. bool pairingWriter(
  277. RTPSWriter* W,
  278. const GUID_t& participant_guid,
  279. const WriterProxyData& wdata);
  280. bool checkDataRepresentationQos(
  281. const WriterProxyData* wdata,
  282. const ReaderProxyData* rdata) const;
  283. bool checkTypeValidation(
  284. const WriterProxyData* wdata,
  285. const ReaderProxyData* rdata) const;
  286. bool checkTypeIdentifier(
  287. const WriterProxyData* wdata,
  288. const ReaderProxyData* rdata) const;
  289. bool hasTypeIdentifier(
  290. const WriterProxyData* wdata,
  291. const ReaderProxyData* rdata) const;
  292. bool checkTypeObject(
  293. const WriterProxyData* wdata,
  294. const ReaderProxyData* rdata) const;
  295. bool hasTypeObject(
  296. const WriterProxyData* wdata,
  297. const ReaderProxyData* rdata) const;
  298. ReaderProxyData temp_reader_proxy_data_;
  299. WriterProxyData temp_writer_proxy_data_;
  300. std::map<GUID_t, fastdds::dds::SubscriptionMatchedStatus> reader_status_;
  301. std::map<GUID_t, fastdds::dds::PublicationMatchedStatus> writer_status_;
  302. };
  303. } /* namespace rtps */
  304. } /* namespace fastrtps */
  305. } /* namespace eprosima */
  306. #endif
  307. #endif /* _FASTDDS_RTPS_EDP_H_ */