LCOV - code coverage report
Current view: top level - DCPS - RepoIdGenerator.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 28 67.9 %
Date: 2023-04-30 01:32:43 Functions: 3 5 60.0 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *
       4             :  * Distributed under the OpenDDS License.
       5             :  * See: http://www.opendds.org/license.html
       6             :  */
       7             : 
       8             : #include "DCPS/DdsDcps_pch.h"
       9             : 
      10             : #include "RepoIdGenerator.h"
      11             : #include "RepoIdBuilder.h"
      12             : #include "ace/Log_Msg.h"
      13             : 
      14             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      15             : namespace OpenDDS {
      16             : namespace DCPS {
      17             : 
      18             : const unsigned int RepoIdGenerator::KeyBits = 24;
      19             : 
      20             : const unsigned int RepoIdGenerator::KeyMask = (1 << KeyBits) - 1;
      21             : 
      22           1 : RepoIdGenerator::RepoIdGenerator(long federation, long participant, EntityKind kind)
      23           1 :   : kind_(kind)
      24           1 :   , federation_(federation)
      25           1 :   , participant_(participant)
      26           1 :   , lastKey_(0)
      27             : {
      28           1 : }
      29             : 
      30           1 : RepoIdGenerator::~RepoIdGenerator()
      31             : {
      32           1 : }
      33             : 
      34             : GUID_t
      35          12 : RepoIdGenerator::next(bool builtin)
      36             : {
      37             :   // Generate a new key value.
      38          12 :   ++lastKey_;
      39             : 
      40          12 :   RepoIdBuilder builder;
      41          12 :   builder.federationId(federation_);
      42             : 
      43             :   // Generate a Participant GUID value.
      44          12 :   if (kind_ == KIND_PARTICIPANT) {
      45             : 
      46             :     // Rudimentary validity checking.
      47           0 :     if (lastKey_ == 0) {
      48             :       // We have rolled over and there can now exist objects with
      49             :       // the same key.
      50           0 :       ACE_ERROR((LM_ERROR,
      51             :                  ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ")
      52             :                  ACE_TEXT("Exceeded Maximum number of participant keys!")
      53             :                  ACE_TEXT("Next key will be a duplicate!\n")));
      54             :     }
      55             : 
      56           0 :     builder.participantId(lastKey_);
      57           0 :     builder.entityId(ENTITYID_PARTICIPANT);
      58             : 
      59             :     // Generate an Entity GUID value.
      60             : 
      61             :   } else {
      62             : 
      63             :     // Rudimentary validity checking.
      64          12 :     if ((lastKey_ & ~KeyMask) != 0) {
      65             :       // We have rolled over and there can now exist objects with
      66             :       // the same key.
      67           0 :       ACE_ERROR((LM_ERROR,
      68             :                  ACE_TEXT("(%P|%t) ERROR: RepoIdGenerator::next: ")
      69             :                  ACE_TEXT("Exceeded Maximum number of entity keys!")
      70             :                  ACE_TEXT("Next key will be a duplicate!\n")));
      71             :     }
      72             : 
      73          12 :     builder.participantId(participant_);
      74          12 :     builder.entityKey(lastKey_);
      75          12 :     builder.entityKind(kind_, builtin);
      76             :   }
      77             : 
      78          24 :   return GUID_t(builder);
      79          12 : }
      80             : 
      81             : void
      82           0 : RepoIdGenerator::last(long key)
      83             : {
      84           0 :   if (key > lastKey_) {
      85           0 :     lastKey_ = key;
      86             :   }
      87           0 : }
      88             : 
      89             : } // namespace DCPS
      90             : } // namespace OpenDDS
      91             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16