DataReader.hpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. // Copyright 2019 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 DataReader.hpp
  16. *
  17. */
  18. #ifndef _FASTRTPS_DATAREADER_HPP_
  19. #define _FASTRTPS_DATAREADER_HPP_
  20. #ifndef DOXYGEN_SHOULD_SKIP_THIS_PUBLIC
  21. #include <fastrtps/qos/DeadlineMissedStatus.h>
  22. #include <fastdds/rtps/common/Time_t.h>
  23. #include <fastdds/dds/core/status/StatusMask.hpp>
  24. #include <fastdds/dds/core/Entity.hpp>
  25. #include <fastrtps/types/TypesBase.h>
  26. #include <vector>
  27. #include <cstdint>
  28. using eprosima::fastrtps::types::ReturnCode_t;
  29. namespace dds {
  30. namespace sub {
  31. class DataReader;
  32. } // namespace sub
  33. } // namespace dds
  34. namespace eprosima {
  35. namespace fastrtps {
  36. class TopicAttributes;
  37. namespace rtps {
  38. class ReaderAttributes;
  39. struct GUID_t;
  40. struct InstanceHandle_t;
  41. } // namespace rtps
  42. } // namespace fastrtps
  43. namespace fastdds {
  44. namespace dds {
  45. class Subscriber;
  46. class SubscriberImpl;
  47. class DataReaderImpl;
  48. class DataReaderListener;
  49. class TypeSupport;
  50. class DataReaderQos;
  51. class TopicDescription;
  52. struct LivelinessChangedStatus;
  53. struct SampleInfo;
  54. /**
  55. * Class DataReader, contains the actual implementation of the behaviour of the Subscriber.
  56. * @ingroup FASTDDS_MODULE
  57. */
  58. class DataReader : public DomainEntity
  59. {
  60. friend class DataReaderImpl;
  61. friend class SubscriberImpl;
  62. /**
  63. * Creates a DataReader. Don't use it directly, but through Subscriber.
  64. */
  65. RTPS_DllAPI DataReader(
  66. DataReaderImpl* impl,
  67. const StatusMask& mask = StatusMask::all());
  68. RTPS_DllAPI DataReader(
  69. Subscriber* s,
  70. TopicDescription* topic,
  71. const DataReaderQos& qos,
  72. DataReaderListener* listener = nullptr,
  73. const StatusMask& mask = StatusMask::all());
  74. public:
  75. /**
  76. * @brief Destructor
  77. */
  78. RTPS_DllAPI virtual ~DataReader();
  79. /**
  80. * @brief This operation enables the DataReader
  81. * @return RETCODE_OK is successfully enabled. RETCODE_PRECONDITION_NOT_MET if the Subscriber creating this
  82. * DataReader is not enabled.
  83. */
  84. RTPS_DllAPI ReturnCode_t enable() override;
  85. /**
  86. * Method to block the current thread until an unread message is available
  87. * @param timeout Max blocking time for this operation
  88. * @return true if there is new unread message, false if timeout
  89. */
  90. RTPS_DllAPI bool wait_for_unread_message(
  91. const fastrtps::Duration_t& timeout);
  92. /** @name Read or take data methods.
  93. * Methods to read or take data from the History.
  94. */
  95. ///@{
  96. /* TODO
  97. RTPS_DllAPI bool read(
  98. std::vector<void*>& data_values,
  99. std::vector<SampleInfo>& sample_infos,
  100. uint32_t max_samples);
  101. */
  102. /**
  103. * @brief This operation copies the next, non-previously accessed Data value from the DataReader; the operation also
  104. * copies the corresponding SampleInfo. The implied order among the samples stored in the DataReader is the same as for
  105. * the read operation.
  106. *
  107. * The read_next_sample operation is semantically equivalent to the read operation where the input Data sequence has
  108. * max_length=1, the sample_states=NOT_READ, the view_states=ANY_VIEW_STATE, and the instance_states=ANY_INSTANCE_STATE.
  109. *
  110. * The read_next_sample operation provides a simplified API to ‘read’ samples avoiding the need for the application to
  111. * manage sequences and specify states.
  112. *
  113. * If there is no unread data in the DataReader, the operation will return NO_DATA and nothing is copied
  114. * @param data Data pointer to store the sample
  115. * @param info SampleInfo pointer to store the sample information
  116. * @return RETCODE_NO_DATA if the history is empty, RETCODE_OK if the next sample is returned and RETCODE_ERROR otherwise
  117. */
  118. RTPS_DllAPI ReturnCode_t read_next_sample(
  119. void* data,
  120. SampleInfo* info);
  121. /* TODO
  122. RTPS_DllAPI bool take(
  123. std::vector<void*>& data_values,
  124. std::vector<SampleInfo>& sample_infos,
  125. uint32_t max_samples);
  126. */
  127. /**
  128. * @brief This operation copies the next, non-previously accessed Data value from the DataReader and ‘removes’ it from
  129. * the DataReader so it is no longer accessible. The operation also copies the corresponding SampleInfo. This operation
  130. * is analogous to the read_next_sample except for the fact that the sample is ‘removed’ from the DataReader.
  131. *
  132. * The take_next_sample operation is semantically equivalent to the take operation where the input sequence has
  133. * max_length=1, the sample_states=NOT_READ, the view_states=ANY_VIEW_STATE, and the instance_states=ANY_INSTANCE_STATE.
  134. *
  135. * This operation provides a simplified API to ’take’ samples avoiding the need for the application to manage sequences
  136. * and specify states.
  137. *
  138. * If there is no unread data in the DataReader, the operation will return NO_DATA and nothing is copied.
  139. * @param data Data pointer to store the sample
  140. * @param info SampleInfo pointer to store the sample information
  141. * @return RETCODE_NO_DATA if the history is empty, RETCODE_OK if the next sample is returned and RETCODE_ERROR otherwise
  142. */
  143. RTPS_DllAPI ReturnCode_t take_next_sample(
  144. void* data,
  145. SampleInfo* info);
  146. ///@}
  147. /**
  148. * @brief Returns information about the first untaken sample.
  149. * @param [out] info Pointer to a SampleInfo_t structure to store first untaken sample information.
  150. * @return RETCODE_OK if sample info was returned. RETCODE_NO_DATA if there is no sample to take.
  151. */
  152. RTPS_DllAPI ReturnCode_t get_first_untaken_info(
  153. SampleInfo* info);
  154. /**
  155. * Get associated GUID
  156. * @return Associated GUID
  157. */
  158. RTPS_DllAPI const fastrtps::rtps::GUID_t& guid();
  159. /**
  160. * @brief Getter for the associated InstanceHandle
  161. * @return Copy of the InstanceHandle
  162. */
  163. RTPS_DllAPI fastrtps::rtps::InstanceHandle_t get_instance_handle() const;
  164. /**
  165. * Getter for the data type
  166. * @return TypeSupport associated to the DataReader
  167. */
  168. TypeSupport type();
  169. /**
  170. * Get TopicDescription
  171. * @return TopicDescription pointer
  172. */
  173. const TopicDescription* get_topicdescription() const;
  174. /**
  175. * @brief Get the requested deadline missed status
  176. * @return The deadline missed status
  177. */
  178. RTPS_DllAPI ReturnCode_t get_requested_deadline_missed_status(
  179. fastrtps::RequestedDeadlineMissedStatus& status);
  180. /**
  181. * @brief Setter for the DataReaderQos
  182. * @param qos new value for the DataReaderQos
  183. * @return RETCODE_IMMUTABLE_POLICY if any of the Qos cannot be changed, RETCODE_INCONSISTENT_POLICY if the Qos is not
  184. * self consistent and RETCODE_OK if the qos is changed correctly.
  185. */
  186. RTPS_DllAPI ReturnCode_t set_qos(
  187. const DataReaderQos& qos);
  188. /**
  189. * @brief Getter for the DataReaderQos
  190. * @return Pointer to the DataReaderQos
  191. */
  192. RTPS_DllAPI const DataReaderQos& get_qos() const;
  193. /**
  194. * @brief Getter for the DataReaderQos
  195. * @param qos DataReaderQos where the qos is returned
  196. * @return RETCODE_OK
  197. */
  198. RTPS_DllAPI ReturnCode_t get_qos(
  199. DataReaderQos& qos) const;
  200. /**
  201. * @brief Setter for the DataReaderListener
  202. * @param listener new value for the DataReaderListener
  203. * @return RETCODE_OK
  204. */
  205. RTPS_DllAPI ReturnCode_t set_listener(
  206. DataReaderListener* listener);
  207. /**
  208. * @brief Getter for the DataReaderListener
  209. * @return Pointer to the DataReaderListener
  210. */
  211. RTPS_DllAPI const DataReaderListener* get_listener() const;
  212. /* TODO
  213. RTPS_DllAPI bool get_key_value(
  214. void* data,
  215. const fastrtps::rtps::InstanceHandle_t& handle);
  216. */
  217. /**
  218. * @brief Get the liveliness changed status
  219. * @param status LivelinessChangedStatus object where the status is returned
  220. * @return RETCODE_OK
  221. */
  222. RTPS_DllAPI ReturnCode_t get_liveliness_changed_status(
  223. LivelinessChangedStatus& status) const;
  224. /* TODO
  225. RTPS_DllAPI bool get_requested_incompatible_qos_status(
  226. fastrtps::RequestedIncompatibleQosStatus& status) const;
  227. */
  228. /* TODO
  229. RTPS_DllAPI bool get_sample_lost_status(
  230. fastrtps::SampleLostStatus& status) const;
  231. */
  232. /* TODO
  233. RTPS_DllAPI bool get_sample_rejected_status(
  234. fastrtps::SampleRejectedStatus& status) const;
  235. */
  236. /**
  237. * @brief Getter for the Subscriber
  238. * @return Subscriber pointer
  239. */
  240. RTPS_DllAPI const Subscriber* get_subscriber() const;
  241. /* TODO
  242. RTPS_DllAPI bool wait_for_historical_data(
  243. const fastrtps::Duration_t& max_wait) const;
  244. */
  245. private:
  246. DataReaderImpl* impl_;
  247. friend class ::dds::sub::DataReader;
  248. };
  249. } /* namespace dds */
  250. } /* namespace fastdds */
  251. } /* namespace eprosima */
  252. #endif
  253. #endif /* _FASTRTPS_DATAREADER_HPP_*/