Save a Publication

2 posts / 0 new
Last post
Last seen: 2 months 1 week ago
Joined: 09/18/2020
Posts: 1
Save a Publication


I am currently using the code below to listen and print a publication. I'm testing it witht he connext c++ hello_builtin example and am succesfully able to print it when listening.  I want to save the publication and create a new data_listener and listener but I'm unsure how to do both of those things.  How should I go about this.


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");

    retcode = builtin_reader->take(
        data_seqinfo_seq, DDS_LENGTH_UNLIMITED,

    if (retcode == DDS_RETCODE_NO_DATA) {
    } else if (retcode != DDS_RETCODE_OK) {
        printf("take error %d\n"retcode);

    for (i = 0i < data_seq.length(); ++i) {
        if (info_seq[i].valid_data) {
            printf("Publication: topic '%s' of type '%s'\n"data_seq[i].topic_name,

    retcode = builtin_reader->return_loan(data_seqinfo_seq);
    if (retcode != DDS_RETCODE_OK) {
        printf("return loan error %d\n"retcode);
Howard's picture
Last seen: 2 days 7 hours ago
Joined: 11/29/2012
Posts: 95

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?