PublisherHistory.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 PublisherHistory.h
  16. *
  17. */
  18. #ifndef PUBLISHERHISTORY_H_
  19. #define PUBLISHERHISTORY_H_
  20. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  21. #include <fastdds/rtps/resources/ResourceManagement.h>
  22. #include <fastdds/rtps/history/WriterHistory.h>
  23. #include <fastrtps/qos/QosPolicies.h>
  24. #include <fastrtps/common/KeyedChanges.h>
  25. #include <fastrtps/attributes/TopicAttributes.h>
  26. namespace eprosima {
  27. namespace fastrtps {
  28. /**
  29. * Class PublisherHistory, implementing a WriterHistory with support for keyed topics and HistoryQOS.
  30. * This class is created by the PublisherImpl and should not be used by the user directly.
  31. * @ingroup FASTRTPS_MODULE
  32. */
  33. class PublisherHistory : public rtps::WriterHistory
  34. {
  35. public:
  36. /**
  37. * Constructor of the PublisherHistory.
  38. * @param topic_att TopicAttributed
  39. * @param payloadMax Maximum payload size.
  40. * @param mempolicy Set wether the payloads ccan dynamically resized or not.
  41. */
  42. PublisherHistory(
  43. const TopicAttributes& topic_att,
  44. uint32_t payloadMax,
  45. rtps::MemoryManagementPolicy_t mempolicy);
  46. virtual ~PublisherHistory();
  47. /*!
  48. * @brief Tries to reserve resources for the new instance.
  49. * @param instance_handle Instance's key.
  50. * @param lock Lock which should be unlock in case the operation has to wait.
  51. * @param max_blocking_time Maximum time the operation should be waiting.
  52. * @return True if resources was reserved successfully.
  53. */
  54. bool register_instance(
  55. const rtps::InstanceHandle_t& instance_handle,
  56. std::unique_lock<RecursiveTimedMutex>& lock,
  57. const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time);
  58. /**
  59. * Add a change comming from the Publisher.
  60. * @param change Pointer to the change
  61. * @param wparams Extra write parameters.
  62. * @param lock
  63. * @param max_blocking_time
  64. * @return True if added.
  65. */
  66. bool add_pub_change(
  67. rtps::CacheChange_t* change,
  68. rtps::WriteParams& wparams,
  69. std::unique_lock<RecursiveTimedMutex>& lock,
  70. const std::chrono::time_point<std::chrono::steady_clock>& max_blocking_time);
  71. /**
  72. * Remove all change from the associated history.
  73. * @param removed Number of elements removed.
  74. * @return True if all elements were removed.
  75. */
  76. bool removeAllChange(
  77. size_t* removed);
  78. /**
  79. * Remove the change with the minimum sequence Number.
  80. * @return True if removed.
  81. */
  82. bool removeMinChange();
  83. /**
  84. * Remove a change by the publisher History.
  85. * @param change Pointer to the CacheChange_t.
  86. * @return True if removed.
  87. */
  88. bool remove_change_pub(
  89. rtps::CacheChange_t* change);
  90. virtual bool remove_change_g(
  91. rtps::CacheChange_t* a_change);
  92. bool remove_instance_changes(
  93. const rtps::InstanceHandle_t& handle,
  94. const rtps::SequenceNumber_t& seq_up_to);
  95. /**
  96. * @brief Sets the next deadline for the given instance
  97. * @param handle The instance handle
  98. * @param next_deadline_us The time point when the deadline will occur
  99. * @return True if deadline was set successfully
  100. */
  101. bool set_next_deadline(
  102. const rtps::InstanceHandle_t& handle,
  103. const std::chrono::steady_clock::time_point& next_deadline_us);
  104. /**
  105. * @brief Returns the deadline for the instance that is next going to 'expire'
  106. * @param handle The handle for the instance that will next miss the deadline
  107. * @param next_deadline_us The time point when the deadline will occur
  108. * @return True if deadline could be retrieved for the given instance
  109. */
  110. bool get_next_deadline(
  111. rtps::InstanceHandle_t& handle,
  112. std::chrono::steady_clock::time_point& next_deadline_us);
  113. /*!
  114. * @brief Checks if the instance's key is registered.
  115. * @param[in] handle Instance's key.
  116. * return `true` if instance's key is registered in the history.
  117. */
  118. bool is_key_registered(
  119. const rtps::InstanceHandle_t& handle);
  120. private:
  121. typedef std::map<rtps::InstanceHandle_t, KeyedChanges> t_m_Inst_Caches;
  122. //!Map where keys are instance handles and values are vectors of cache changes associated
  123. t_m_Inst_Caches keyed_changes_;
  124. //!Time point when the next deadline will occur (only used for topics with no key)
  125. std::chrono::steady_clock::time_point next_deadline_us_;
  126. //!HistoryQosPolicy values.
  127. HistoryQosPolicy history_qos_;
  128. //!ResourceLimitsQosPolicy values.
  129. ResourceLimitsQosPolicy resource_limited_qos_;
  130. //!Topic Attributes
  131. TopicAttributes topic_att_;
  132. /**
  133. * @brief Method that finds a key in m_keyedChanges or tries to add it if not found
  134. * @param instance_handle Instance of the key.
  135. * @param map_it A map iterator to the given key
  136. * @return True if the key was found or could be added to the map
  137. */
  138. bool find_or_add_key(
  139. const rtps::InstanceHandle_t& instance_handle,
  140. t_m_Inst_Caches::iterator* map_it);
  141. };
  142. } /* namespace fastrtps */
  143. } /* namespace eprosima */
  144. #endif
  145. #endif /* PUBLISHERHISTORY_H_ */