SubscriberQos subscriber_qos = new SubscriberQos(); SubscriberListener subscriber_listener = null; try { participant.get_default_subscriber_qos(subscriber_qos); } catch (DDS.Exception) { Console.WriteLine( "***Error: failed to get default subscriber qos"); } Subscriber subscriber = participant.create_subscriber( subscriber_qos, subscriber_listener, StatusMask.STATUS_MASK_NONE); if (subscriber == null) { Console.WriteLine( "***Error: failed to create subscriber"); }
// holder for list/set of readers DataReaderSeq reader_seq = new DataReaderSeq(); 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 { subscriber.get_datareaders( reader_seq, sample_state_mask, view_state_mask, instance_state_mask); } catch (DDS.Exception) { Console.WriteLine( "***Error: failed to access received data via subscriber"); return; }
for (int i = 0; i < reader_seq.length; ++i) { DataReader reader = reader_seq.get_at(i); // Take the data from reader, // OR // Read the data from reader }
try { subscriber.notify_datareaders(); } catch (DDS.Exception) { Console.WriteLine( "***Error: failed to notify datareaders"); }
try { subscriber.begin_access(); } catch (DDS.Exception) { // ... check for cause of failure }
try { subscriber.end_access(); } catch (DDS.Exception) { // ... check for cause of failure }
try { participant.delete_subscriber(ref subscriber); } catch (DDS.Exception) { Console.WriteLine( "***Error: failed to delete subscriber"); }