Working with data readers.
More...
Working with data readers.
Setting up a data reader
- Set up subscriber
- Set up a topic
- Create a data reader, FooDataReader, of user data type
Foo:
MyReaderListener_RequestedDeadlineMissed;
MyReaderListener_RequestedIncompatibleQos;
MyReaderListener_LivelinessChanged;
reader_listener.on_subscription_match =
MyReaderListener_SubscriptionMatch;
subscriber, &reader_qos);
printf("***Error: failed to get default datareader qos\n");
}
&reader_qos,
&reader_listener ,
if (reader == NULL) {
printf("***Error: failed to create reader\n");
}
Managing instances
- Given a data reader
- Getting an instance "key" value of user data type
Foo
Set up reader to access received data
Access received data via a reader
Taking data
- Ensure reader is set up to access received data
- Take samples of user data type
T
. The samples are removed from the Service. The caller is responsible for deallocating the buffers. struct FooSeq data_seq = FooSeq_INITIALIZER;
max_samples,
sample_state_mask,
view_state_mask,
instance_state_mask);
return;
printf("***Error: failed to access data from the reader\n");
}
- Use the received data
int i;
info = DDS_SampleInfoSeq_get_reference(&info_seq, i);
}
- Return the data samples and the information buffers back to the middleware. IMPORTANT: Once this call returns, you must not retain any pointers to any part of any sample or sample info object.
printf("***Error: failed to return loan\n");
}
Reading data
- Ensure reader is set up to access received data
- Read samples of user data type
Foo
. The samples are not removed from the Service. It remains responsible for deallocating the buffers. struct FooSeq data_seq = FooSeq_INITIALIZER;
max_samples,
sample_state_mask,
view_state_mask,
instance_state_mask);
return;
printf("***Error: failed to access data from the reader\n");
}
- Use the received data
int i;
info = DDS_SampleInfoSeq_get_reference(&info_seq, i);
}
- Return the data samples and the information buffers back to the middleware
printf("***Error: failed to return loan\n");
}
Tearing down a data reader
- Delete DDS_DataReader:
printf("***Error: failed to delete reader\n");
}