MessageReceiver.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 MessageReceiver.h
  16. */
  17. #ifndef _FASTDDS_RTPS_MESSAGERECEIVER_H_
  18. #define _FASTDDS_RTPS_MESSAGERECEIVER_H_
  19. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  20. #include <fastdds/rtps/common/all_common.h>
  21. #include <unordered_map>
  22. #include <mutex>
  23. namespace eprosima {
  24. namespace fastrtps {
  25. namespace rtps {
  26. class RTPSParticipantImpl;
  27. class Endpoint;
  28. class RTPSWriter;
  29. class RTPSReader;
  30. struct SubmessageHeader_t;
  31. /**
  32. * Class MessageReceiver, process the received messages.
  33. * @ingroup MANAGEMENT_MODULE
  34. */
  35. class MessageReceiver
  36. {
  37. public:
  38. /**
  39. * @param participant
  40. * @param rec_buffer_size
  41. */
  42. MessageReceiver(
  43. RTPSParticipantImpl* participant,
  44. uint32_t rec_buffer_size);
  45. virtual ~MessageReceiver();
  46. /**
  47. * Process a new CDR message.
  48. * @param[in] loc Locator indicating the sending address.
  49. * @param[in] msg Pointer to the message
  50. */
  51. void processCDRMsg(
  52. const Locator_t& loc,
  53. CDRMessage_t* msg);
  54. // Functions to associate/remove associatedendpoints
  55. void associateEndpoint(
  56. Endpoint* to_add);
  57. void removeEndpoint(
  58. Endpoint* to_remove);
  59. private:
  60. std::mutex mtx_;
  61. std::vector<RTPSWriter*> associated_writers_;
  62. std::unordered_map<EntityId_t, std::vector<RTPSReader*> > associated_readers_;
  63. RTPSParticipantImpl* participant_;
  64. //!Protocol version of the message
  65. ProtocolVersion_t source_version_;
  66. //!VendorID that created the message
  67. VendorId_t source_vendor_id_;
  68. //!GuidPrefix of the entity that created the message
  69. GuidPrefix_t source_guid_prefix_;
  70. //!GuidPrefix of the entity that receives the message. GuidPrefix of the RTPSParticipant.
  71. GuidPrefix_t dest_guid_prefix_;
  72. //!Has the message timestamp?
  73. bool have_timestamp_;
  74. //!Timestamp associated with the message
  75. Time_t timestamp_;
  76. #if HAVE_SECURITY
  77. CDRMessage_t crypto_msg_;
  78. #endif
  79. //!Reset the MessageReceiver to process a new message.
  80. void reset();
  81. /**
  82. * Check the RTPSHeader of a received message.
  83. * @param msg Pointer to the message.
  84. * @return True if correct.
  85. */
  86. bool checkRTPSHeader(
  87. CDRMessage_t* msg);
  88. /**
  89. * Read the submessage header of a message.
  90. * @param msg Pointer to the CDRMessage_t to read.
  91. * @param smh Pointer to the submessageheader structure.
  92. * @return True if correctly read.
  93. */
  94. bool readSubmessageHeader(
  95. CDRMessage_t* msg,
  96. SubmessageHeader_t* smh);
  97. /**
  98. * Find if there is a reader (in associated_readers_) that will accept a msg directed
  99. * to the given entity ID.
  100. */
  101. bool willAReaderAcceptMsgDirectedTo(
  102. const EntityId_t& readerID);
  103. /**
  104. * Find all readers (in associated_readers_), with the given entity ID, and call the
  105. * callback provided.
  106. */
  107. template<typename Functor>
  108. void findAllReaders(
  109. const EntityId_t& readerID,
  110. const Functor& callback);
  111. /**@name Processing methods.
  112. * These methods are designed to read a part of the message
  113. * and perform the corresponding actions:
  114. * -Modify the message receiver state if necessary.
  115. * -Add information to the history.
  116. * -Return an error if the message is malformed.
  117. * @param[in,out] msg Pointer to the message
  118. * @param[in] smh Pointer to the submessage header
  119. * @return True if correct, false otherwise
  120. */
  121. ///@{
  122. /**
  123. *
  124. * @param msg
  125. * @param smh
  126. * @return
  127. */
  128. bool proc_Submsg_Data(
  129. CDRMessage_t* msg,
  130. SubmessageHeader_t* smh);
  131. bool proc_Submsg_DataFrag(
  132. CDRMessage_t* msg,
  133. SubmessageHeader_t* smh);
  134. bool proc_Submsg_Acknack(
  135. CDRMessage_t* msg,
  136. SubmessageHeader_t* smh);
  137. bool proc_Submsg_Heartbeat(
  138. CDRMessage_t* msg,
  139. SubmessageHeader_t* smh);
  140. bool proc_Submsg_Gap(
  141. CDRMessage_t* msg,
  142. SubmessageHeader_t* smh);
  143. bool proc_Submsg_InfoTS(
  144. CDRMessage_t* msg,
  145. SubmessageHeader_t* smh);
  146. bool proc_Submsg_InfoDST(
  147. CDRMessage_t* msg,
  148. SubmessageHeader_t* smh);
  149. bool proc_Submsg_InfoSRC(
  150. CDRMessage_t* msg,
  151. SubmessageHeader_t* smh);
  152. bool proc_Submsg_NackFrag(
  153. CDRMessage_t* msg,
  154. SubmessageHeader_t* smh);
  155. bool proc_Submsg_HeartbeatFrag(
  156. CDRMessage_t* msg,
  157. SubmessageHeader_t* smh);
  158. ///@}
  159. };
  160. } /* namespace rtps */
  161. } /* namespace fastrtps */
  162. } /* namespace eprosima */
  163. #endif
  164. #endif /* _FASTDDS_RTPS_MESSAGERECEIVER_H_ */