A problem with narrow function

7 posts / 0 new
Last post
Offline
Last seen: 11 years 9 months ago
Joined: 07/25/2011
Posts: 8
A problem with narrow function

Hi RTI Users,

I'm programming an application using RTI-DDS and i have a trouble with the narrow function of the datawriters, it returns a null pointer.

I have tried unsuccessfully to find the bug in my code source.

 If anyone had the same problem, don't hesitate to tell me how to solve it.

Thanks in advance.

Fernando Garcia's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 05/18/2011
Posts: 199

 

The narrow function checks whether the actual type of the DataWriter returned by the create_datawriter()  operation corresponds to the type you are narrowing it to. It should the same pointer you pass in or NULL if you try to narrow it to the wrong type. So the error most likely indicates that:

 

a) Either the Topic was not created correctly

or

b) The data-type associated with the Topic is not the same as the one you are using to narrow the datawriter.

 

This pseudocode shows what I am trying to say:

 

// Register a type Foo

FooTypeSupport::register_type(participant, FooTypeSupport::get_type_name());


//Create a topic "MyTopicName"

DDS::Topic *topic = participant->create_topic("MyTopicName", FooTypeSupport::get_type_name(), ...);


//Create a data writer

DDS::DataWriter *writer = publisher->create_datawriter(topic, ...)


// Narrow to correct type:

 FooDataWriter *foo_writer = FooDataWriter::narrow(writer);


// The narrow should succeed resulting in foo_writer==writer


// Try to narrow to an incorrect type:

BarDataWriter *bar_writer = BarDataWriter::narrow(writer);


// The narrow should fail resulting in bar_writer==NULL

 

Can you provide more details of how you registered the type and created the Topic?

Offline
Last seen: 11 years 9 months ago
Joined: 07/25/2011
Posts: 8

Thank you for the fast reply.

I checked the writer's type and it must be the correct one, but the problem persists and the narrow function returns null pointer.

For more details, this is a part of my code source:

the idl file:

struct Climat
{
long climatDistVisi;
long climatHeure;
long climatHorizon;
boolean climatSport;
long rainDensity;
long rainSize;
long wiperAngle;

};

 

 

the C++ File:

DDSTopic *topic_climat = NULL;

     DDSDataWriter *writer_climat = NULL;
    PlatSim_ClimatDataWriter * Climat_writer = NULL;


/* Register type before creating topic */
    type_name_climat = PlatSim_ClimatTypeSupport::get_type_name();
    retcode_climat = PlatSim_ClimatTypeSupport::register_type(
        participant, type_name_climat);
    if (retcode_climat != DDS_RETCODE_OK) {
        printf("register_type error %d\n", retcode_climat);
        publisher_shutdown(participant);
        return -1;
    }

 /* To customize topic QoS, use
       the configuration file USER_QOS_PROFILES.xml */
    topic_climat = participant->create_topic(
        "Example Climat",
        type_name, DDS_TOPIC_QOS_DEFAULT, NULL /* listener */,
        DDS_STATUS_MASK_NONE);
    if (topic_climat == NULL) {
        printf("create_topic error\n");
        publisher_shutdown(participant);
        return -1;
    }

    /* To customize data writer QoS, use
       the configuration file USER_QOS_PROFILES.xml */
    writer_climat = publisher->create_datawriter(
        topic_climat, DDS_DATAWRITER_QOS_DEFAULT, NULL /* listener */,
        DDS_STATUS_MASK_NONE);
    if (writer_climat == NULL) {
        printf("create_datawriter error\n");
        publisher_shutdown(participant);
        return -1;
    }

   
   
    /*  
    Climat_writer = PlatSim_ClimatDataWriter::narrow(writer_climat);
    if (Climat_writer == NULL) {
        printf("c'est là");
        printf("DataWriter narrow error\n");
        publisher_shutdown(participant);
        return -1;
    }
   
    */
   
    /* Create data sample for writing */
    instance_climat = PlatSim_ClimatTypeSupport::create_data();
    if (instance_climat == NULL) {
        printf("ClimatTypeSupport::create_data error\n");
        publisher_shutdown(participant);
        return -1;
    }

 

As seen, The definition seems to be correct but the narrow function returns a null pointer.

Thank you.  

Gerardo Pardo's picture
Offline
Last seen: 2 months 1 day ago
Joined: 06/02/2010
Posts: 601

 

Hello,

I noticed something in the code you posted. You assigned the type name to a variable called type_name_climat an use that to register the type:

    type_name_climat = PlatSim_ClimatTypeSupport::get_type_name();
    retcode_climat = PlatSim_ClimatTypeSupport::register_type(
        participant, type_name_climat);

 

But then when you create the Topic you use the variable type_name to indicate the type name:

topic_climat = participant->create_topic(
        "Example Climat",
        type_name, DDS_TOPIC_QOS_DEFAULT, NULL /* listener */,
        DDS_STATUS_MASK_NONE);

Was that a typo in the code that you pasted here? If you indeed did this it could explain the problem you are seeing...

Offline
Last seen: 11 years 9 months ago
Joined: 07/25/2011
Posts: 8

Hello!

Yes! it was because of this variable.

My application runs now correctly .

Thank you for helping me.

Offline
Last seen: 11 years 9 months ago
Joined: 07/25/2011
Posts: 8

Hello Gerardo and all rti users.

One of my goals now is to evaluate my application's performances. I don't know if is are any efficient tool which monitor rti applications.                                                                     I have also a problem with RTI Monitor, I'm not able to configure it in order to monitor my application giving that I'm working in a Windows Xp platform, using Visula studio C++.

Please, can you explain me how to configure it ?

Thank you !

Gerardo Pardo's picture
Offline
Last seen: 2 months 1 day ago
Joined: 06/02/2010
Posts: 601

 

I see you also posted asking for help on the use of RTI Monitoring on a separate thread so I will not address that here as it seems that people are already responding to the other thread.

Regarding the evaluation of application Performance this is a very broad subject so without knowing more of what you are trying to do it is hard to answer. However I do think that RTI Monitoring is the right startng point. This tool will give you a idea of the ammount of traffic going between different computers, DDS Participants and specific data writers and readers. It will laos give you other statistics to monitor status and health like CPU consumption, memory, ammount of repair traffic, etc.

 

-Gerardo