void myBuiltInPubListener::on_data_available(DDSDataReader* reader)
{
printf("\nmyBuiltInPubListener on_data_available\n");
DDSPublicationBuiltinTopicDataDataReader* builtin_reader = NULL;
DDS_PublicationBuiltinTopicDataSeq data_seq;
DDS_SampleInfoSeq info_seq;
DDS_ReturnCode_t retcode;
DDS_ExceptionCode_t ex;
int i;
builtin_reader = DDSPublicationBuiltinTopicDaltaDataReader::narrow(reader);
if (builtin_reader == NULL) {
printf("Builtin Pub DataReader narrow error\n");
return;
}
retcode = builtin_reader->take(
data_seq, info_seq, DDS_LENGTH_UNLIMITED,
DDS_ANY_SAMPLE_STATE, DDS_ANY_VIEW_STATE, DDS_ANY_INSTANCE_STATE);
if (retcode == DDS_RETCODE_NO_DATA) {
return;
} else if (retcode != DDS_RETCODE_OK) {
printf("take error %d\n", retcode);
return;
}
for (i = 0; i < data_seq.length(); ++i) {
if (info_seq[i].valid_data) {
printf("Publication: topic '%s' of type '%s'\n", data_seq[i].topic_name,
data_seq[i].type_name);
data_seq[i].type_code->print_IDL(3, ex);
}
}
retcode = builtin_reader->return_loan(data_seq, info_seq);
if (retcode != DDS_RETCODE_OK) {
printf("return loan error %d\n", retcode);
}
}
What do you mean by "save the publication"? Do you mean save the data onto disk? Save into a database? Save into your own data structure? The data received is given to you as elements of the data_seq. data_seq[i] is a value of the data structure that was received. You should use standard coding techniques to use the data however you want to in your application. In the current example, all that is done is to print some of the members.
What do you mean by "create a new data_listener and listener"? What is the difference between "data_listener" and "listener"? Why do you want to create a new data_listener/listener? What do you want to do with the new data_listener/listener?