LCOV - code coverage report
Current view: top level - DCPS/RTPS - MessageUtils.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 44 58 75.9 %
Date: 2023-04-30 01:32:43 Functions: 5 6 83.3 %

          Line data    Source code
       1             : /*
       2             :  * Distributed under the OpenDDS License.
       3             :  * See: http://www.opendds.org/license.html
       4             :  */
       5             : 
       6             : #include "MessageUtils.h"
       7             : 
       8             : #include "MessageTypes.h"
       9             : 
      10             : #include <dds/DCPS/Time_Helper.h>
      11             : #include <dds/OpenddsDcpsExtTypeSupportImpl.h>
      12             : 
      13             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      14             : 
      15             : namespace OpenDDS {
      16             : namespace RTPS {
      17             : 
      18             : using DCPS::Encoding;
      19             : 
      20             : namespace {
      21             :   const Encoding encoding_plain_native(Encoding::KIND_XCDR1);
      22             : }
      23             : 
      24          21 : const DCPS::Encoding& get_locators_encoding()
      25             : {
      26          21 :   static const Encoding encoding(Encoding::KIND_XCDR1, DCPS::ENDIAN_BIG);
      27          21 :   return encoding;
      28             : }
      29             : 
      30           8 : DDS::ReturnCode_t blob_to_locators(const DCPS::TransportBLOB& blob,
      31             :                                    DCPS::LocatorSeq& locators,
      32             :                                    bool* requires_inline_qos,
      33             :                                    unsigned int* pBytesRead)
      34             : {
      35           8 :   ACE_Data_Block db(blob.length(), ACE_Message_Block::MB_DATA,
      36           8 :                     reinterpret_cast<const char*>(blob.get_buffer()),
      37           8 :                     0 /*alloc*/, 0 /*lock*/, ACE_Message_Block::DONT_DELETE, 0 /*db_alloc*/);
      38           8 :   ACE_Message_Block mb(&db, ACE_Message_Block::DONT_DELETE, 0 /*mb_alloc*/);
      39           8 :   mb.wr_ptr(mb.space());
      40             : 
      41           8 :   DCPS::Serializer ser(&mb, get_locators_encoding());
      42           8 :   if (!(ser >> locators)) {
      43           0 :     ACE_ERROR_RETURN((LM_ERROR,
      44             :                       ACE_TEXT("(%P|%t) blob_to_locators: ")
      45             :                       ACE_TEXT("Failed to deserialize blob's locators\n")),
      46             :                      DDS::RETCODE_ERROR);
      47             :   }
      48             : 
      49           8 :   if (requires_inline_qos) {
      50           0 :     if (!(ser >> ACE_InputCDR::to_boolean(*requires_inline_qos))) {
      51           0 :       ACE_ERROR_RETURN((LM_ERROR,
      52             :                         ACE_TEXT("(%P|%t) blob_to_locators: ")
      53             :                         ACE_TEXT("Failed to deserialize blob inline QoS flag\n")),
      54             :                        DDS::RETCODE_ERROR);
      55             :     }
      56             :   } else {
      57           8 :     if (!ser.skip(1)) {
      58           0 :       ACE_ERROR_RETURN((LM_ERROR,
      59             :                         ACE_TEXT("(%P|%t) blob_to_locators: ")
      60             :                         ACE_TEXT("Failed to skip blob inline QoS flag\n")),
      61             :                        DDS::RETCODE_ERROR);
      62             :     }
      63             :   }
      64             : 
      65           8 :   if (pBytesRead) {
      66           0 :     *pBytesRead = blob.length() - static_cast<unsigned int>(mb.length());
      67             :   }
      68           8 :   return DDS::RETCODE_OK;
      69           8 : }
      70             : 
      71          13 : void locators_to_blob(const DCPS::LocatorSeq& locators,
      72             :                       DCPS::TransportBLOB& blob)
      73             : {
      74             :   using namespace OpenDDS::DCPS;
      75          13 :   const Encoding& encoding = get_locators_encoding();
      76          13 :   size_t size = 0;
      77          13 :   serialized_size(encoding, size, locators);
      78          13 :   ACE_Message_Block mb_locator(size + 1);
      79          13 :   Serializer ser(&mb_locator, encoding);
      80          13 :   if (!(ser << locators)) {
      81           0 :     ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) locators_to_blob: ")
      82             :       ACE_TEXT("Failed to serialize locators to blob\n")));
      83             :   }
      84             :   // Add a bool for 'requires inline qos', see Sedp::set_inline_qos():
      85             :   // if the bool is no longer the last octet of the sequence then that function
      86             :   // must be changed as well.
      87          13 :   if (!(ser << ACE_OutputCDR::from_boolean(false))) {
      88           0 :     ACE_ERROR((LM_ERROR, ACE_TEXT("(%P|%t) locators_to_blob: ")
      89             :       ACE_TEXT("Failed to serialize boolean for blob\n")));
      90             :   }
      91          13 :   message_block_to_sequence(mb_locator, blob);
      92          13 : }
      93             : 
      94             : OpenDDS_Rtps_Export
      95           0 : DCPS::LocatorSeq transport_locator_to_locator_seq(const DCPS::TransportLocator& info)
      96             : {
      97           0 :   DCPS::LocatorSeq locators;
      98           0 :   blob_to_locators(info.data, locators);
      99           0 :   return locators;
     100           0 : }
     101             : 
     102           4 : DCPS::TimeDuration rtps_duration_to_time_duration(const Duration_t& rtps_duration, const ProtocolVersion_t& version, const VendorId_t& vendor)
     103             : {
     104           4 :   if (rtps_duration == DURATION_INFINITE) {
     105           0 :     return DCPS::TimeDuration::max_value;
     106             :   }
     107             : 
     108           4 :   if (version < PROTOCOLVERSION_2_4 && vendor == VENDORID_OPENDDS) {
     109             :     return OpenDDS::DCPS::TimeDuration(
     110           1 :       rtps_duration.seconds,
     111           1 :       static_cast<ACE_UINT32>(rtps_duration.fraction / 1000));
     112             :   } else {
     113             :     return OpenDDS::DCPS::TimeDuration(
     114           3 :       rtps_duration.seconds,
     115           3 :       DCPS::uint32_fractional_seconds_to_microseconds(rtps_duration.fraction));
     116             :   }
     117             : }
     118             : 
     119          22 : bool bitmapNonEmpty(const SequenceNumberSet& snSet)
     120             : {
     121          22 :   const CORBA::ULong num_ulongs = (snSet.numBits + 31) / 32;
     122             : 
     123          22 :   OPENDDS_ASSERT(num_ulongs <= snSet.bitmap.length());
     124             : 
     125          22 :   if (num_ulongs == 0) {
     126           2 :     return false;
     127             :   }
     128             : 
     129          20 :   const CORBA::ULong last_index = num_ulongs - 1;
     130          29 :   for (CORBA::ULong i = 0; i < last_index; ++i) {
     131           9 :     if (snSet.bitmap[i]) {
     132           0 :       return true;
     133             :     }
     134             :   }
     135             : 
     136          20 :   const CORBA::ULong mod = snSet.numBits % 32;
     137          20 :   const CORBA::ULong mask = mod ? (1 + ~(1u << (32 - mod))) : 0xFFFFFFFF;
     138          20 :   return (bool)(snSet.bitmap[last_index] & mask);
     139             : }
     140             : 
     141             : }
     142             : }
     143             : 
     144             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16