Save a Publication

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

Hello,

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

    retcode = builtin_reader->take(
        data_seqinfo_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 = 0i < 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(3ex);                       
        }
    }

    retcode = builtin_reader->return_loan(data_seqinfo_seq);
    if (retcode != DDS_RETCODE_OK) {
        printf("return loan error %d\n"retcode);
    }
   
}
Howard's picture
Offline
Last seen: 21 hours 35 min ago
Joined: 11/29/2012
Posts: 565

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?