Can not access to rti::core::Guid in 16 LENGTH in modern c++

7 posts / 0 new
Last post
Offline
Last seen: 10 hours 20 min ago
Joined: 09/10/2022
Posts: 37
Can not access to rti::core::Guid in 16 LENGTH in modern c++

I have problem in getting arrays that rti connext dds gives access to in modern c++.

As you know in modern c++, arrays ends with zero 0.

There for you can not have zero in array unless at the end of array. When modern c++ see zero, it soppose that this is end of array and next values are not valid as part of array.

I think rti connext dds has problem in give acces to arrays like rti::core::guid or keyHashes. Length of some arrays is 16, and i assume that this arrays have 16 length, but it is not true and datas after zero are not valid and sometimes arrays like guid have less than 16 length

Howard's picture
Offline
Last seen: 1 day 12 hours ago
Joined: 11/29/2012
Posts: 621

"As you know in modern c++, arrays ends with zero 0." 

I don't understand what you mean by the above.  Nor do I agree with the statement.  For arrays in general, there is no automatic "end with zero" behavior in C++.

In any case, rti::core::Guid is its own class/data structure.  It is not an array:

uint8_t value[16]

nor is it a std::array or std::vector.

The length of an rti::core::Guid is always 16.  A Guid is always comprised of 16 uint8_t values.  And all 0's is a valid value for the Guid.

Offline
Last seen: 10 hours 20 min ago
Joined: 09/10/2022
Posts: 37

I don't know how does your developer fill guid or how gives access to its data's with [ ], but I see that guid that i get from sampleInfos that sent by one publisher are not equal after zero.I have the same issue with keyHashes. I compare guids before zero for equality

Howard's picture
Offline
Last seen: 1 day 12 hours ago
Joined: 11/29/2012
Posts: 621

Unfortunately, I don't know what you mean by "not equal after zero".

But if you are trying to compare two values of type rti::core::Guid, why don't you use the "=" operator.  It's defined for that class.

https://community.rti.com/static/documentation/connext-dds/current/doc/api/connext_dds/api_cpp2/classrti_1_1core_1_1Guid.html

It would be more clear if you post sample code and sample output to understand what you are trying to do.

 

Offline
Last seen: 10 hours 20 min ago
Joined: 09/10/2022
Posts: 37

I'm sorry I think I was wrong in comparing some values and that made mistake. I have to compare some entities with any unique attribute like guid or keyhash, but I made wrong comparing. let me explain that...

I have a dds::pub::publisher named P_A and dds::pub::DataWriter<T> named DW_A in a dds::domain::DomainParticipant named DP_A.

Also I have dds::sub::DataReader<T> in DP_A named DR_A. In another dds::domain::DomainParticipant named DP_B I have dds::pub::DataWriter<T> named DW_B. In another dds::domain::DomainParticipant named DP_C I have dds::pub::DataWriter<T> named DW_C. DP_A, DP_B and DP_C are in seprate project.

1. I want to detect DR_A, matched to DW_B ?

for this purpose I do like this:

dds::core::status::SubscriptionMatchedStatus sms = DR_A.subscription_matched_status();
dds::core::InstanceHandle publisherInstance = P_A.instance_handle();
std::string participantName = ""; 
while(true)
{
   if(sms.current_count()>0)
   {
      bool matchedDW_B = false;
      const dds::core::InstanceHandleSeq matchedPublications = dds::sub::matched_publications(DR_A);
      for(auto matchedPublication: matchedPublications)
      { 
          if(std::equal(std::begin(publisherInstance->native().keyHash.value),
                        std::end(publisherInstance->native().keyHash.value),
                        std::begin(matchedPublication->native().keyHash.value)) == false)
          {
              // std::cerr << "hashs are not the same" << std::endl;
              participantName = rti::sub::matched_publication_participant_data(DR_A,matchedPublication)->participant_name().name().get();
          }
          else
          {
              // std::cerr << "hashs are the same" << std::endl;
              participantName = "DP_A_NAME";
          };
  
          if(participantName == "DP_B_NAME")
          {
              matchedDW_B = true;
              break;
          }
      };
      if(matchedDW_B == true)
      {
        break;
      };
  };
}

I found that I'm wrong in comparing "P_A.instance_handle()->native().keyHash.value" with "matchedPublication->native().keyHash.value". Should I compare between "matchedPublication->native().keyHash.value" and "DW_A.instance_handle()->native().keyHash.value"?

 2. I want to know does "DW_B" Published sample that received by "DR_A"?

For this purpose I compare like this:

auto lnSamples = DR_A.take();
dds::core::InstanceHandle publisherInstance = P_A.instance_handle();
for (const auto& index : lnSamples)
{
    if (index.info().valid())
    {
        if(std::equal(std::begin(publisherInstance->native().keyHash.value),
                      std::end(publisherInstance->native().keyHash.value),
                      std::begin(index.info().publication_handle()->native().keyHash.value)) == false)
        {
            // std::cerr << "hashs are not the same" << std::endl;
            participantName = rti::sub::matched_publication_participant_data(DR_A,index.info().publication_handle())->participant_name().name().get();
        }
        else
        {
            // std::cerr << "hashs are the same" << std::endl;
            participantName = "DP_A_NAME";
        };
 
         if(participantName == "DP_B_NAME")
         {
           //..
         }
     }
 }

 

I found that I'm wrong in comparing "P_A.instance_handle()->native().keyHash.value" with "index.info().publication_handle()->native().keyHash.value". Should I compare between "index.info().publication_handle()->native().keyHash.value" and "DW_A.instance_handle()->native().keyHash.value"?

 

3. I want to know that two samples received from one DataWiter and there is not packet lost:

For this purpose I do like this:

auto lnSamples = DR_A.take();
 for (const auto& index : lnSamples)
 {
     if (index.info().valid())
     {
         static std::map<std::string, long int> uniqueStr;
         std::string guid;
         for(int i =0; i <16; i++)
         {
             guid+=(index.info()->operator const rti::sub::SampleInfoImpl &().source_guid().native().value[i]);
         }
  
         if(uniqueStr.find(guid) == uniqueStr.end())
         {
             uniqueStr.insert(std::make_pair<std::string, long int>(guid.data(),0));
         }
  
         if(index.info()->operator const rti::sub::SampleInfoImpl &().publication_sequence_number().value() != ++uniqueStr[guid])
         {
             std::cerr << " Not Received Data from " << --uniqueStr[guid] << " to " << index.info()->operator const rti::sub::SampleInfoImpl &().publication_sequence_number().value() << std::endl;
         }
  
         uniqueStr[guid] = index.info()->operator const rti::sub::SampleInfoImpl &().publication_sequence_number().value();
     }
 }

 

I have two question there:

1. is "loanedSample.info()->operator const rti::sub::SampleInfoImpl &().source_guid().native().value" equal to "DW_B.qos()->protocol.virtual_guid()" where writer of loanedSample is DW_B?

2. is "loanedSample.info()->operator const rti::sub::SampleInfoImpl &().source_guid().native().value" equal to "loanedSample.info().publication_handle()->native().keyHash.value"?

 

Howard's picture
Offline
Last seen: 1 day 12 hours ago
Joined: 11/29/2012
Posts: 621

I'm sorry, I think what you're asking about is beyond what I can response to on this forum.  There are misconceptions on what information/guids is received with discovery and data versus local handles of local objects.  Also a DDSPublisher object is not the same as a "publication".

If you are on a project that has paid support from RTI, I suggest you open a case with them.  However, it seems like you can use some services provided by RTI's Professional Service groups since what you need is more along the lines of training/education.

Offline
Last seen: 10 hours 20 min ago
Joined: 09/10/2022
Posts: 37

Ok thank you mr. Howard