Foo:
DDS_DataReaderQos reader_qos; DDS_ReturnCode_t retcode; // MyReaderListener is user defined and // extends DDSDataReaderListener DDSDataReaderListener* reader_listener = new MyReaderListener(); // or = NULL retcode = subscriber->get_default_datareader_qos(reader_qos); if (retcode != DDS_RETCODE_OK) { // ... error }; FooDataReader* reader = subscriber->create_datareader(topic, reader_qos, reader_listener, DDS_STATUS_MASK_ALL); if (reader == NULL) { // ... error };
FooDataReader* reader = ...;
Foo
Foo data; // user data of type Foo // ... retcode = reader->get_key_value(data, instance_handle); if (retcode != DDS_RETCODE_OK) { // ... check for cause of failure }
T
. The samples are removed from the Service. The caller is responsible for deallocating the buffers. FooSeq data_seq; // holder for sequence of user data type Foo DDS_SampleInfoSeq info_seq; // holder for sequence of DDS_SampleInfo long max_samples = DDS_LENGTH_UNLIMITED; DDS_SampleStateMask sample_state_mask = DDS_ANY_SAMPLE_STATE; DDS_ViewStateMask view_state_mask = DDS_ANY_VIEW_STATE; DDS_InstanceStateMask instance_state_mask = DDS_ANY_INSTANCE_STATE; DDS_ReturnCode_t retcode; retcode = reader->take(data_seq, info_seq, max_samples, sample_state_mask, view_state_mask, instance_state_mask); if (retcode == DDS_RETCODE_NO_DATA) { return; } else if (retcode != DDS_RETCODE_OK) { // ... check for cause of failure }
// Use the received data samples 'data_seq' and associated information 'info_seq' for(int i = 0; i < data_seq.length(); ++i) { // use... data_seq[i] ... // use... info_seq[i] ... }
retcode = reader->return_loan(data_seq, info_seq); if (retcode != DDS_RETCODE_OK) { // ... check for cause of failure }
Foo
. The samples are not removed from the Service. It remains responsible for deallocating the buffers. FooSeq data_seq; // holder for sequence of user data type Foo DDS_SampleInfoSeq info_seq; // holder for sequence of DDS_SampleInfo long max_samples = DDS_LENGTH_UNLIMITED; DDS_SampleStateMask sample_state_mask = DDS_NOT_READ_SAMPLE_STATE; DDS_ViewStateMask view_state_mask = DDS_ANY_VIEW_STATE; DDS_InstanceStateMask instance_state_mask = DDS_ANY_INSTANCE_STATE; DDS_ReturnCode_t retcode; retcode = reader->read(data_seq, info_seq, max_samples, sample_state_mask, view_state_mask, instance_state_mask); if (retcode == DDS_RETCODE_NO_DATA) { return; } else if (retcode != DDS_RETCODE_OK) { // ... check for cause of failure }
// Use the received data samples 'data_seq' and associated // information 'info_seq' for(int i = 0; i < data_seq.length(); ++i) { // use... data_seq[i] ... // use... info_seq[i] ... }
retcode = reader->return_loan(data_seq, info_seq); if (retcode != DDS_RETCODE_OK) { // ... check for cause of failure }
DDS_ReturnCode_t retcode; retcode = subscriber->delete_datareader(reader); if (retcode != DDS_RETCODE_OK) { // ... check for cause of failure }