Question

I am new to RTI DDS connext. I tried running some C++ examples(Hello_dynamic,Hello_simple) of rti and they where working fine.Then i thought of passing a C++ map as Topic type from publisher to Subscriber.But i guess their is no documentation and example codes are available for doing this. Please help me here ..??

Was it helpful?

Solution

The C++ standard map type can not natively be used as a Topic type. DDS can distribute any type that can be expressed by a defined subset of OMG's IDL (Interface Definition Language) and the map type is not among that.

The two code examples that you are referring to are not your typical situation, because they rely on the built-in string type (Hello_simple) or the proprietary dynamic data API (Hello_dynamic). To get a better idea how you would normally define your own datatypes, check out the Hello_idl example. It shows a user-defined type, defined in IDL, that is translated into a C++ type to be used by your application.

It would be fairly easy to create a Topic type to achieve functionality similar to a C++ map. Suppose your map-items have string keys and long values, then you could use a structure in IDL to express a single item in your map, for example using the following type:

struct mapItem {
    unsigned long m_mapId; //@key
    string m_key;          //@key
    long   m_value;
};

m-mapId indicates to which map this item belongs. Your map is the collection of all mapItems with the same m_mapId value. The fields m_key and m_value are obviously the key-value pairs.

On the publisher side, your application can write the map elements to DDS one-by-one. Values with the same values for m_mapId and m_key will overwrite each other, resulting in the same behavior as expected for standard maps. On the subscriber side, it is possible to build up the complete map by querying the datareader for all mapItems with the same m_mapId.

Your application code will not be using standard maps when using this approach. In order to achieve that, you will have to create wrapper functions that translate a map(-like) API into the corresponding write and read actions.

In case you are familiar with regular data-base designs, you will notice the similarity to what you would be doing when designing this in a relational data model. Indeed, DDS can be considered a distributed data management infrastructure with a lot of similarities to regular DBMS-es.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top