Publisher.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 Publisher.h
  16. *
  17. */
  18. #ifndef PUBLISHER_H_
  19. #define PUBLISHER_H_
  20. #include <fastrtps/fastrtps_dll.h>
  21. #include <fastdds/rtps/common/Guid.h>
  22. #include <fastdds/rtps/common/Time_t.h>
  23. #include <fastrtps/attributes/PublisherAttributes.h>
  24. #include <fastrtps/qos/DeadlineMissedStatus.h>
  25. #include <fastrtps/qos/LivelinessLostStatus.h>
  26. namespace eprosima {
  27. namespace fastrtps {
  28. namespace rtps {
  29. struct GUID_t;
  30. class WriteParams;
  31. class RTPSParticipant;
  32. }
  33. class Participant;
  34. class PublisherImpl;
  35. /**
  36. * Class Publisher, used to send data to associated subscribers.
  37. * @ingroup FASTRTPS_MODULE
  38. */
  39. class RTPS_DllAPI Publisher
  40. {
  41. friend class PublisherImpl;
  42. virtual ~Publisher();
  43. public:
  44. /**
  45. * Constructor from a PublisherImpl pointer
  46. * @param pimpl Actual implementation of the publisher
  47. */
  48. Publisher(
  49. PublisherImpl* pimpl);
  50. /*!
  51. * @brief Writes a sample of the topic.
  52. * @param sample Pointer to the sample.
  53. * @return true when operation works successfully.
  54. * @note This method is blocked for a period of time.
  55. * ReliabilityQosPolicy.max_blocking_time on PublisherAttributes defines this period of time.
  56. * @par Calling example:
  57. * @snippet fastrtps_example.cpp ex_PublisherWrite
  58. */
  59. bool write(
  60. void* sample);
  61. /*!
  62. * @brief Writes a sample of the topic with additional options.
  63. * @param sample Pointer to the sample.
  64. * @param wparams Extra write parameters.
  65. * @return true when operation works successfully.
  66. * @note This method is blocked for a period of time.
  67. * ReliabilityQosPolicy.max_blocking_time on PublisherAttributes defines this period of time.
  68. * @par Calling example:
  69. * @snippet fastrtps_example.cpp ex_PublisherWrite
  70. */
  71. bool write(
  72. void* sample,
  73. rtps::WriteParams& wparams);
  74. /*!
  75. * @brief Informs that the application will be modifying a particular instance.
  76. * It gives and opportunity to the middleware to pre-configure itself to improve performance.
  77. * @param[in] instance Sample used to get the instance's key.
  78. * @return Handle containing the instance's key.
  79. * This handle could be used in successive `write` or `dispose` operations.
  80. * In case of error, HANDLE_NIL will be returned.
  81. */
  82. fastrtps::rtps::InstanceHandle_t register_instance(
  83. void* instance);
  84. /*!
  85. * @brief Requests the middleware to delete the instance.
  86. * Applications are made aware of the deletion through the DataReader objects.
  87. * @param[in] data Sample used to deduce instance's key in case of `handle` parameter is HANDLE_NIL.
  88. * @param[in] handle Instance's key to be unregistered.
  89. * @return Returns the operation's result.
  90. * If the operation finishes successfully, `true` is returned.
  91. */
  92. bool dispose(
  93. void* data,
  94. const rtps::InstanceHandle_t& handle);
  95. /*!
  96. * @brief This operation reserves the action of `register_instance`.
  97. * Informs the middleware that the DataWriter is not intending to modify any more of that data instance.
  98. * Also indicates that the middleware can locally remove all information regarding that instance.
  99. * @param[in] instance Sample used to deduce instance's key in case of `handle` parameter is HANDLE_NIL.
  100. * @param[in] handle Instance's key to be unregistered.
  101. * @return Returns the operation's result.
  102. * If the operation finishes successfully, `true` is returned.
  103. */
  104. bool unregister_instance(
  105. void* instance,
  106. const rtps::InstanceHandle_t& handle);
  107. /**
  108. * Remove all the Changes in the associated RTPSWriter.
  109. * @param[out] removed Number of elements removed
  110. * @return True if all elements were removed.
  111. */
  112. bool removeAllChange(
  113. size_t* removed = nullptr);
  114. /**
  115. * Waits until all changes were acknowledged or max_wait.
  116. * @param max_wait Maximum time to wait until all changes are acknowledged.
  117. * @return True if all were acknowledged.
  118. */
  119. bool wait_for_all_acked(
  120. const Duration_t& max_wait);
  121. /**
  122. * Get the GUID_t of the associated RTPSWriter.
  123. * @return GUID_t.
  124. */
  125. const rtps::GUID_t& getGuid();
  126. /**
  127. * Get the Attributes of the Publisher.
  128. * @return Attributes of the publisher
  129. */
  130. const PublisherAttributes& getAttributes() const;
  131. /**
  132. * Update the Attributes of the publisher.
  133. * @param att Reference to a PublisherAttributes object to update the parameters.
  134. * @return True if correctly updated, false if ANY of the updated parameters cannot be updated.
  135. */
  136. bool updateAttributes(
  137. const PublisherAttributes& att);
  138. /**
  139. * @brief Returns the offered deadline missed status
  140. * @param status missed status struct
  141. */
  142. void get_offered_deadline_missed_status(
  143. OfferedDeadlineMissedStatus& status);
  144. /**
  145. * @brief Asserts liveliness
  146. */
  147. void assert_liveliness();
  148. /**
  149. * @brief Returns the liveliness lost status
  150. * @param status Liveliness lost status
  151. */
  152. void get_liveliness_lost_status(
  153. LivelinessLostStatus& status);
  154. private:
  155. PublisherImpl* mp_impl;
  156. };
  157. } /* namespace fastrtps */
  158. } /* namespace eprosima */
  159. #endif /* PUBLISHER_H_ */