RTPSMessageCreator.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 RTPSMessageCreator.h
  16. */
  17. #ifndef _FASTDDS_RTPS_CDRMESSAGECREATOR_H_
  18. #define _FASTDDS_RTPS_CDRMESSAGECREATOR_H_
  19. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  20. #include <fastdds/rtps/common/CDRMessage_t.h>
  21. #include <fastdds/rtps/common/Guid.h>
  22. #include <fastdds/rtps/common/SequenceNumber.h>
  23. #include <fastdds/rtps/common/FragmentNumber.h>
  24. #include <fastdds/rtps/common/CacheChange.h>
  25. namespace eprosima {
  26. namespace fastrtps{
  27. namespace rtps{
  28. //!An interface to add inline qos parameters to a CDRMessage
  29. class InlineQosWriter
  30. {
  31. public:
  32. virtual ~InlineQosWriter() = default;
  33. /**
  34. * Writes inline QOS parameters to a CDRMessage.
  35. * @param msg Pointer to the message.
  36. * @return true if writing was successful, false otherwise.
  37. */
  38. virtual bool writeQosToCDRMessage(CDRMessage_t* msg) = 0;
  39. };
  40. /**
  41. * @brief Class RTPSMessageCreator, allows the generation of serialized CDR RTPS Messages.
  42. * @ingroup MANAGEMENT_MODULE
  43. */
  44. class RTPSMessageCreator
  45. {
  46. public:
  47. RTPSMessageCreator() = delete;
  48. ~RTPSMessageCreator() = delete;
  49. /**
  50. * Create a Header to the serialized message.
  51. * @param msg Pointer to the Message.
  52. * @param Prefix RTPSParticipant prefix of the message.
  53. * @param version Protocol version.
  54. * @param vendorId Vendor Id.
  55. * @return True if correct.
  56. */
  57. static bool addHeader(CDRMessage_t*msg ,const GuidPrefix_t& Prefix,const ProtocolVersion_t& version,const VendorId_t& vendorId);
  58. /**
  59. * Create a Header to the serialized message.
  60. * @param msg Pointer to the Message.
  61. * @param Prefix RTPSParticipant prefix of the message.
  62. * @return True if correct.
  63. */
  64. static bool addHeader(CDRMessage_t*msg ,const GuidPrefix_t& Prefix);
  65. /**
  66. * Add a custom content to the serialized message.
  67. * @param msg Pointer to the Message.
  68. * @param content content to create.
  69. * @param contentSize size of the content.
  70. * @return True if correct.
  71. */
  72. static bool addCustomContent(CDRMessage_t*msg, const octet* content, const size_t contentSize);
  73. /**
  74. * Create SubmessageHeader.
  75. * @param msg Pointer to the CDRMessage.
  76. * @param id SubMessage Id.
  77. * @param flags Submessage flags.
  78. * @param size Submessage size.
  79. * @return True if correct.
  80. */
  81. static bool addSubmessageHeader(CDRMessage_t* msg,octet id,octet flags,uint16_t size);
  82. /** @name CDR messages creation methods.
  83. * These methods create a CDR message for different types
  84. * Depending on the function a complete message (with RTPS Header is created) or only the submessage.
  85. * @param[out] msg Pointer to where the message is going to be created and stored.
  86. * @param[in] guidPrefix Guid Prefix of the RTPSParticipant.
  87. * @param[in] param Different parameters depending on the message.
  88. * @return True if correct.
  89. */
  90. /// @{
  91. static bool addMessageData(CDRMessage_t* msg, GuidPrefix_t& guidprefix, const CacheChange_t* change,
  92. TopicKind_t topicKind, const EntityId_t& readerId, bool expectsInlineQos, InlineQosWriter* inlineQos);
  93. static bool addSubmessageData(CDRMessage_t* msg, const CacheChange_t* change,
  94. TopicKind_t topicKind, const EntityId_t& readerId, bool expectsInlineQos, InlineQosWriter* inlineQos,
  95. bool* is_big_submessage);
  96. static bool addMessageDataFrag(CDRMessage_t* msg, GuidPrefix_t& guidprefix, const CacheChange_t* change, uint32_t fragment_number,
  97. TopicKind_t topicKind, const EntityId_t& readerId, bool expectsInlineQos, InlineQosWriter* inlineQos);
  98. static bool addSubmessageDataFrag(CDRMessage_t* msg, const CacheChange_t* change, uint32_t fragment_number,
  99. uint32_t sample_size, TopicKind_t topicKind, const EntityId_t& readerId, bool expectsInlineQos,
  100. InlineQosWriter* inlineQos);
  101. static bool addMessageGap(CDRMessage_t* msg, const GuidPrefix_t& guidprefix, const GuidPrefix_t& remoteGuidPrefix,
  102. const SequenceNumber_t& seqNumFirst, const SequenceNumberSet_t& seqNumList,const EntityId_t& readerId,const EntityId_t& writerId);
  103. static bool addSubmessageGap(CDRMessage_t* msg, const SequenceNumber_t& seqNumFirst, const SequenceNumberSet_t& seqNumList,const EntityId_t& readerId,const EntityId_t& writerId);
  104. static bool addMessageHeartbeat(CDRMessage_t* msg, const GuidPrefix_t& guidprefix,
  105. const EntityId_t& readerId, const EntityId_t& writerId,
  106. const SequenceNumber_t& firstSN, const SequenceNumber_t& lastSN,
  107. Count_t count, bool isFinal, bool livelinessFlag);
  108. static bool addMessageHeartbeat(CDRMessage_t* msg,const GuidPrefix_t& guidprefix,
  109. const GuidPrefix_t& remoteGuidprefix, const EntityId_t& readerId,
  110. const EntityId_t& writerId, const SequenceNumber_t& firstSN,
  111. const SequenceNumber_t& lastSN, Count_t count, bool isFinal, bool livelinessFlag);
  112. static bool addSubmessageHeartbeat(CDRMessage_t* msg, const EntityId_t& readerId, const EntityId_t& writerId,
  113. const SequenceNumber_t& firstSN, const SequenceNumber_t& lastSN,
  114. Count_t count, bool isFinal, bool livelinessFlag);
  115. static bool addMessageHeartbeatFrag(CDRMessage_t* msg, const GuidPrefix_t& guidprefix, const EntityId_t& readerId, const EntityId_t& writerId,
  116. SequenceNumber_t& firstSN, FragmentNumber_t& lastFN, Count_t count);
  117. static bool addSubmessageHeartbeatFrag(CDRMessage_t* msg, const EntityId_t& readerId, const EntityId_t& writerId,
  118. SequenceNumber_t& firstSN, FragmentNumber_t& lastFN, Count_t count);
  119. static bool addMessageAcknack(CDRMessage_t* msg,const GuidPrefix_t& guidprefix, const GuidPrefix_t& remoteGuidPrefix,
  120. const EntityId_t& readerId,const EntityId_t& writerId,const SequenceNumberSet_t& SNSet,int32_t count,bool finalFlag);
  121. static bool addSubmessageAcknack(CDRMessage_t* msg,
  122. const EntityId_t& readerId,const EntityId_t& writerId,const SequenceNumberSet_t& SNSet,int32_t count,bool finalFlag);
  123. static bool addMessageNackFrag(CDRMessage_t* msg, const GuidPrefix_t& guidprefix, const GuidPrefix_t& remoteGuidPrefix,
  124. const EntityId_t& readerId, const EntityId_t& writerId, SequenceNumber_t& writerSN, FragmentNumberSet_t fnState, int32_t count);
  125. static bool addSubmessageNackFrag(CDRMessage_t* msg,
  126. const EntityId_t& readerId, const EntityId_t& writerId, const SequenceNumber_t& writerSN, FragmentNumberSet_t fnState, int32_t count);
  127. static bool addSubmessageInfoTS(CDRMessage_t* msg, const Time_t &time, bool invalidateFlag);
  128. static bool addSubmessageInfoTS_Now(CDRMessage_t* msg,bool invalidateFlag);
  129. static bool addSubmessageInfoSRC(CDRMessage_t* msg, const ProtocolVersion_t& version, const VendorId_t& vendorId, const GuidPrefix_t& guidP);
  130. static bool addSubmessageInfoDST(CDRMessage_t* msg, const GuidPrefix_t& guidP);
  131. };
  132. }
  133. } /* namespace rtps */
  134. } /* namespace eprosima */
  135. #endif
  136. #endif /* _FASTDDS_RTPS_CDRMESSAGECREATOR_H_ */