Comparing DDS Entities

2 posts / 0 new
Last post
Last seen: 4 years 10 months ago
Joined: 03/25/2015
Posts: 33
Comparing DDS Entities


I have been maintaining a structure (c-struct) in my application which constitutes of 







DDS:Entity, as you know can be either a DataWriter or DataReader etc.. I maintain a list of these structures within my base application - probably for some legacy purposes which I dont want to dig in now. During filling the list, I plan to check for an existing DataWriter using the following logic:

EntityList::iterator it = m_entityList.begin();
EntityList::iterator end = m_entityList.end();
for ( ; it != end ; it++)
if ((*it)->entity == entity)
return (*it);
return NULL;

Though it seems to work (I mean if I try to give same DataWriter, then it considers a duplicate), but I would like to know a bit more on this. How does a "compare" work in such scenarios? In other words, what gets compared during this '==' operator? I tried searching around, but didn't get any clue.

Thanks in advance.


ajimenez's picture
Last seen: 1 year 11 months ago
Joined: 09/29/2017
Posts: 21

Hi Uday,

Firstly, the condition == is just comparing pointers of DDS_Entity.

The proper way about how to compare two DDS_Entity objects is using DDS_BuiltinTopicKey_t:

   "Each remote DDS_Entity to be discovered can be uniquely identified by DDS_BuiltinTopicKey_t"

   As DDS_InstanceHandle_t is derived from DDS_BuiltinTopicKey_t, the API provides methods to compare DDS_Entity objects by DDS_InstanceHandle_t, steps:

       1. Get DDS_InstanceHandle_t:

DDS_InstanceHandle_t DDSEntity::get_instance_handle();

               This operation returns the DDS_InstanceHandle_t that represents the DDS_Entity.

       2. Compare two DDS_InstanceHandle_t objects:

DDS_Boolean DDS_InstanceHandle_equals(
        const DDS_InstanceHandle_t *self,
        const DDS_InstanceHandle_t *other);        

           If this operation returns DDS_BOOLEAN_TRUE if the two DDS_Entities have equal values, or DDS_BOOLEAN_FALSE otherwise.

Let me know if you have further questions about DDS_Entity comparisons.