on_data_available

4 posts / 0 new
Last post
Offline
Last seen: 11 years 2 months ago
Joined: 04/09/2013
Posts: 13
on_data_available

within the overload function on_data_avaliable the example shows how to display the data received. Which works very well. What I am trying to do is to cast the data received to the struct that originally created it so that I can use the data in other functions.

how do I get the actual data received, not the string data, in a pointer format or class format, which inturn I can copy to a struct or another class?

 

rip
rip's picture
Offline
Last seen: 3 days 23 hours ago
Joined: 04/06/2012
Posts: 324

The object is already in the format you are looking for.

C++:

    for (i = 0; i < data_seq.length(); ++i) {
        if (info_seq[i].valid_data) {
            ShapeTypeExtendedTypeSupport::print_data(&data_seq[i]);
            ShapeTypeExtended *foo = (ShapeTypeExtended *)&data_seq[i];
            printf("Color = %s\n", foo->color);
            printf("    x = %i\n", foo->x);
            printf("    y = %i\n", foo->y);
            printf("Ssize = %i\n", foo->shapesize);
        }
    }

java:

    for(int i = 0; i < _dataSeq.size(); ++i) {
        SampleInfo info = (SampleInfo)_infoSeq.get(i);

        if (info.valid_data) {
            //System.out.println((ShapeTypeExtended)_dataSeq.get(i)).toString("Received",0));
            ShapeTypeExtended foo = (ShapeTypeExtended)_dataSeq.get(i);
            System.out.println("Color = " + foo.color);
            System.out.println("    x = " + foo.x);
            System.out.println("    y = " + foo.y);
            System.out.println("Ssize = " + foo.shapesize);

        }
   }

If I've missed the point of your question...restate the question.

Regards, rip

Offline
Last seen: 11 years 2 months ago
Joined: 04/09/2013
Posts: 13

When the IDL was converted to run on the RTI environment the structures are still avaliable witin the xxSupport.h files
along with the class created. If you have a struct foo you also have a function fooStatusReport and fooTypeSupport.
Within the ::on_data_available(DDSDataReader* reader) overload function
example:

fooStatusReport receivedData; //this is the actual structure

for (i = 0; i < data_seq.length(); ++i)
{
if (info_seq[i].valid_data)
{
fooTypeSupport::copy_data(&receivedData,&data_seq[i]);
}
}

receivedData struct will have a complete structure breakdown of the data received.

Offline
Last seen: 11 years 2 months ago
Joined: 04/09/2013
Posts: 13

Thanks for your solution of the shapeType example. That also works very well. Note in the user manual I painfull went through nither your example or the one I found with copydata is documented. Of course there is still a great deal of documents I need to read.

thanks again for your reply.