11 #ifndef RTIREFLEX_GENERIC_DR_H
12 #define RTIREFLEX_GENERIC_DR_H
40 std::shared_ptr<DDSDynamicDataReader> initialize_reader(DDSDomainParticipant *participant,
41 const DDS_DataReaderQos & drqos,
42 const char * topic_name,
43 const char * type_name,
44 DDSDynamicDataTypeSupport * support,
45 DDSDataReaderListener * listener,
46 DDS_DynamicDataTypeProperty_t props);
51 DDS_ReturnCode_t take_impl(
52 std::shared_ptr<DDSDynamicDataReader> dr,
55 DDS_SampleStateMask sample_states,
56 DDS_ViewStateMask view_states,
57 DDS_InstanceStateMask instance_states,
58 DDSReadCondition * cond = 0)
60 DDS_DynamicDataSeq data_seq;
61 DDS_SampleInfoSeq info_seq;
65 rc = dr->take_w_condition(data_seq, info_seq, max_samples, cond);
67 rc = dr->take(data_seq, info_seq, max_samples,
68 sample_states, view_states, instance_states);
70 if (rc == DDS_RETCODE_NO_DATA) {
73 else if (rc != DDS_RETCODE_OK) {
74 std::cerr <<
"! Unable to take data from data reader, error "
79 if (data_seq.length())
81 data.resize(data_seq.length());
83 for (
int i = 0; i < data_seq.length(); ++i)
85 if (info_seq[i].valid_data)
90 data[i].data() = temp;
92 data[i].info() = info_seq[i];
96 rc = dr->return_loan(data_seq, info_seq);
97 if (rc != DDS_RETCODE_OK) {
98 std::cerr <<
"! Unable to return loan, error "
105 class DataReaderListenerAdapter :
public DDSDataReaderListener
115 : generic_listener_(listener),
120 throw std::runtime_error(
"DataReaderListenerAdapter: NULL listener");
129 virtual void on_data_available(DDSDataReader *reader)
132 DDSDynamicDataReader *dd_reader = DDSDynamicDataReader::narrow(reader);
134 std::cerr <<
"Not a DynamicDataReader!!!\n";
137 generic_listener_->on_data_available(*data_reader_);
153 class GenericDataReaderListener
169 class GenericDataReader
176 std::shared_ptr<detail::DataReaderListenerAdapter<T>> safe_listener_adapter_;
177 std::shared_ptr<DDSDynamicDataReader> safe_datareader_;
182 DDSDomainParticipant *participant,
183 const char * topic_name,
185 const char * type_name = 0,
186 DDS_DynamicDataTypeProperty_t props =
187 DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT)
189 : type_manager_(props),
190 safe_listener_adapter_(listener ? new detail::DataReaderListenerAdapter<T>(listener) : 0),
191 safe_datareader_(detail::initialize_reader(
193 DDS_DATAREADER_QOS_DEFAULT,
197 safe_listener_adapter_.
get(),
200 if (safe_listener_adapter_)
201 safe_listener_adapter_->set_datareader(
this);
205 DDSDomainParticipant *participant,
206 const DDS_DataReaderQos & drqos,
207 const char * topic_name,
209 const char * type_name = 0,
210 DDS_DynamicDataTypeProperty_t props =
211 DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT)
213 : type_manager_(props),
214 safe_listener_adapter_(listener ? new detail::DataReaderListenerAdapter<T>(listener) : 0),
215 safe_datareader_(detail::initialize_reader(
220 type_manager_.get_support(),
221 safe_listener_adapter_.
get(),
224 if (safe_listener_adapter_)
225 safe_listener_adapter_->set_datareader(
this);
230 int max_samples = DDS_LENGTH_UNLIMITED,
231 DDS_SampleStateMask sample_states = DDS_ANY_SAMPLE_STATE,
232 DDS_ViewStateMask view_states = DDS_ANY_VIEW_STATE,
233 DDS_InstanceStateMask instance_states = DDS_ANY_INSTANCE_STATE)
235 return detail::take_impl<T>(
246 DDSReadCondition * cond)
249 return DDS_RETCODE_PRECONDITION_NOT_MET;
251 return detail::take_impl<T>(
255 DDS_ANY_SAMPLE_STATE,
257 DDS_ANY_INSTANCE_STATE,
266 return safe_datareader_.get();
282 return type_manager_.get_properties();
290 return type_manager_.get_safe_typecode();
298 return type_manager_.get_typecode();
306 return type_manager_.get_type_support();
314 #ifndef REFLEX_NO_HEADER_ONLY
315 #include "reflex/../../src/generic_dr.cxx"
320 #endif // RTIREFLEX_GENERIC_DR_H
DDSDynamicDataReader * operator->()
Return the underlying DDSDynamicDataReader.
Definition: generic_dr.h:272
GenericDataReader(DDSDomainParticipant *participant, const DDS_DataReaderQos &drqos, const char *topic_name, ListenerType *listener, const char *type_name=0, DDS_DynamicDataTypeProperty_t props=DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT)
Definition: generic_dr.h:204
DDS_ReturnCode_t take_w_condition(std::vector< Sample< T >> &data, int max_samples, DDSReadCondition *cond)
Definition: generic_dr.h:244
virtual void on_data_available(GenericDataReader< T > &dr)=0
Callback invoked when new data is available to read from GenericDataReader.
Manage type-specific context, such as typecode, type-support, and dynamic data properties.
Definition: type_manager.h:44
A datareader for adapted aggregate types.
Definition: generic_dr.h:30
const DDS_DynamicDataTypeProperty_t & get_properties() const
Definition: generic_dr.h:280
GenericDataReader(DDSDomainParticipant *participant, const char *topic_name, ListenerType *listener, const char *type_name=0, DDS_DynamicDataTypeProperty_t props=DDS_DYNAMIC_DATA_TYPE_PROPERTY_DEFAULT)
Definition: generic_dr.h:181
const DDS_TypeCode * get_typecode() const
Definition: generic_dr.h:296
#define REFLEX_DLL_EXPORT
Definition: dllexport.h:35
void read_dynamicdata(T &dest, const DDS_DynamicData &src)
Extracts data out from the source DDS_DynamicData instance and copies into the destination object of ...
Definition: reflex.h:186
const DDSDynamicDataTypeSupport * get_type_support() const
Definition: generic_dr.h:304
GenericDataReaderListener< T > ListenerType
Definition: generic_dr.h:172
const SafeTypeCode< T > & get_safe_typecode() const
Definition: generic_dr.h:288
DDSDynamicDataReader * underlying()
Return the underlying DDSDynamicDataReader.
Definition: generic_dr.h:264
DDS_ReturnCode_t take(std::vector< Sample< T >> &data, int max_samples=DDS_LENGTH_UNLIMITED, DDS_SampleStateMask sample_states=DDS_ANY_SAMPLE_STATE, DDS_ViewStateMask view_states=DDS_ANY_VIEW_STATE, DDS_InstanceStateMask instance_states=DDS_ANY_INSTANCE_STATE)
Definition: generic_dr.h:228
A type-safe, exception-safe wrapper for DDS TypeCode.
Definition: reflex_fwd.h:27
virtual ~GenericDataReaderListener()
Definition: generic_dr.h:162
Synchornous data listener for GenericDataReader.
Definition: generic_dr.h:33
A valuetype that combines an instance of type T (data) and DDS_SampleInfo.
Definition: sample.h:24