Foo:
DataReaderQos reader_qos = new DataReaderQos(); DataReaderListener reader_listener = null; try { subscriber.get_default_datareader_qos(reader_qos); } catch (DDS.Exception) { Console.WriteLine( "***Error: failed to get default datareader qos"); } DataReader reader = subscriber.create_datareader( topic, reader_qos, reader_listener, StatusMask.STATUS_MASK_NONE); if (reader == null) { Console.WriteLine("***Error: failed to create reader"); }
FooDataReader reader = ...;
Foo
Foo data = new Foo(); // user data of type Foo // ... try { reader.get_key_value(data, instance_handle); } catch (DDS.Exception) { // ... check for cause of failure }
T
. The samples are removed from the Service. The caller is responsible for deallocating the buffers. FooSeq data_seq = new FooSeq(); // sequence of user data type Foo SampleInfoSeq info_seq = new SampleInfoSeq(); // sequence of SampleInfo int max_samples = ResourceLimitsQosPolicy.LENGTH_UNLIMITED; SampleStateKind sample_state_mask = SampleStateKind.ANY_SAMPLE_STATE; ViewStateKind view_state_mask = ViewStateKind.ANY_VIEW_STATE; InstanceStateKind instance_state_mask = InstanceStateKind.ANY_INSTANCE_STATE; try { reader.take(data_seq, info_seq, max_samples, sample_state_mask, view_state_mask, instance_state_mask); } catch (Retcode_NoData) { return; } catch (DDS.Exception) { Console.WriteLine( "***Error: failed to access data from the reader"); }
// Use the received data samples 'data_seq' and associated // meta-information 'info_seq' for (int i = 0; i < data_seq.length; ++i) { SampleInfo info = info_seq.get_at(i); if (!info.valid_data) { continue; } Foo data = data_seq.get_at(i); Console.WriteLine( " Data = (%d, %d) sample_state = %d", data.x, data.y, info.sample_state); }
try { reader.return_loan(data_seq, info_seq); } catch (DDS.Exception) { Console.WriteLine("***Error: failed to return loan"); }
Foo
. The samples are not removed from the Service. It remains responsible for deallocating the buffers. FooSeq data_seq = new FooSeq(); // sequence of user data type Foo SampleInfoSeq info_seq = new SampleInfoSeq(); // sequence of SampleInfo int max_samples = ResourceLimitsQosPolicy.LENGTH_UNLIMITED; SampleStateKind sample_state_mask = SampleStateKind.ANY_SAMPLE_STATE; ViewStateKind view_state_mask = ViewStateKind.ANY_VIEW_STATE; InstanceStateKind instance_state_mask = InstanceStateKind.ANY_INSTANCE_STATE; try { reader.read(data_seq, info_seq, max_samples, sample_state_mask, view_state_mask, instance_state_mask); } catch (Retcode_NoData) { return; } catch (DDS.Exception) { Console.WriteLine( "***Error: failed to access data from the reader"); }
// Use the received data samples 'data_seq' and associated // meta-information 'info_seq' for (int i = 0; i < data_seq.length; ++i) { SampleInfo info = info_seq.get_at(i); if (!info.valid_data) { continue; } Foo data = data_seq.get_at(i); Console.WriteLine( " Data = (%d, %d) sample_state = %d", data.x, data.y, info.sample_state); }
try { reader.return_loan(data_seq, info_seq); } catch (DDS.Exception) { Console.WriteLine("***Error: failed to return loan"); }
try { subscriber.delete_datareader(ref reader); } catch (DDS.Exception) { Console.WriteLine("***Error: failed to delete reader"); }