LCOV - code coverage report
Current view: top level - DCPS - NetworkConfigMonitor.cpp (source / functions) Hit Total Coverage
Test: coverage.info Lines: 18 70 25.7 %
Date: 2023-04-30 01:32:43 Functions: 5 13 38.5 %

          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" //Only the _pch include should start with DCPS/
       9             : 
      10             : #include "NetworkConfigMonitor.h"
      11             : 
      12             : #include "Qos_Helper.h"
      13             : #include "Service_Participant.h"
      14             : 
      15             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      16             : 
      17             : namespace OpenDDS {
      18             : namespace DCPS {
      19             : 
      20           0 : bool NetworkInterfaceAddress::exclude_from_multicast(const char* configured_interface) const
      21             : {
      22           0 :   if (!can_multicast) {
      23           0 :     return true;
      24             :   }
      25             : 
      26           0 :   if (configured_interface && *configured_interface && name != configured_interface) {
      27           0 :     OPENDDS_STRING ci_semi(configured_interface);
      28           0 :     if (ci_semi.find_first_of(':') == OPENDDS_STRING::npos) {
      29           0 :       ci_semi += ':';
      30             :     }
      31           0 :     NetworkAddress as_addr(ci_semi.c_str());
      32           0 :     if (as_addr == NetworkAddress() || address != as_addr) {
      33           0 :       return true;
      34             :     }
      35           0 :   }
      36             : 
      37           0 :   const NetworkAddress sp_default = TheServiceParticipant->default_address();
      38           0 :   return sp_default != NetworkAddress() && address != sp_default;
      39             : }
      40             : 
      41           9 : NetworkConfigMonitor::NetworkConfigMonitor()
      42           9 :   : writer_(make_rch<InternalDataWriter<NetworkInterfaceAddress> >(DataWriterQosBuilder().durability_transient_local()))
      43           9 : {}
      44             : 
      45           9 : NetworkConfigMonitor::~NetworkConfigMonitor()
      46           9 : {}
      47             : 
      48           9 : void NetworkConfigMonitor::connect(RcHandle<InternalTopic<NetworkInterfaceAddress> > topic)
      49             : {
      50           9 :   topic->connect(writer_);
      51           9 : }
      52             : 
      53           9 : void NetworkConfigMonitor::disconnect(RcHandle<InternalTopic<NetworkInterfaceAddress> > topic)
      54             : {
      55           9 :   topic->disconnect(writer_);
      56           9 : }
      57             : 
      58           0 : void NetworkConfigMonitor::set(const List& list)
      59             : {
      60           0 :   ACE_GUARD(ACE_Thread_Mutex, g, mutex_);
      61             : 
      62           0 :   for (List::const_iterator pos = list.begin(), limit = list.end(); pos != limit; ++pos) {
      63           0 :     List::const_iterator iter = std::find_if(list_.begin(), list_.end(), NetworkInterfaceAddressKeyEqual(*pos));
      64           0 :     if (iter != list_.end()) {
      65           0 :       if (*iter != *pos) {
      66             :         // Change.
      67           0 :         writer_->write(*pos);
      68             :       }
      69             :     } else {
      70             :       // New.
      71           0 :       writer_->write(*pos);
      72             :     }
      73             :   }
      74             : 
      75           0 :   for (List::const_iterator pos = list_.begin(), limit = list_.end(); pos != limit; ++pos) {
      76           0 :     List::const_iterator iter = std::find_if(list.begin(), list.end(), NetworkInterfaceAddressKeyEqual(*pos));
      77           0 :     if (iter == list.end()) {
      78             :       // Deleted.
      79           0 :       writer_->unregister_instance(*pos);
      80             :     }
      81             :   }
      82             : 
      83           0 :   list_ = list;
      84           0 : }
      85             : 
      86           0 : void NetworkConfigMonitor::clear()
      87             : {
      88           0 :   ACE_GUARD(ACE_Thread_Mutex, g, mutex_);
      89             : 
      90           0 :   for (List::const_iterator pos = list_.begin(), limit = list_.end(); pos != limit; ++pos) {
      91           0 :     writer_->unregister_instance(*pos);
      92             :   }
      93             : 
      94           0 :   list_.clear();
      95           0 : }
      96             : 
      97          54 : void NetworkConfigMonitor::set(const NetworkInterfaceAddress& nia)
      98             : {
      99          54 :   ACE_GUARD(ACE_Thread_Mutex, g, mutex_);
     100             : 
     101          54 :   List::iterator pos = std::find_if(list_.begin(), list_.end(), NetworkInterfaceAddressKeyEqual(nia));
     102          54 :   if (pos != list_.end()) {
     103           0 :     if (*pos != nia) {
     104           0 :       writer_->write(nia);
     105           0 :       *pos = nia;
     106             :     }
     107             :   } else {
     108          54 :     writer_->write(nia);
     109          54 :     list_.push_back(nia);
     110             :   }
     111          54 : }
     112             : 
     113           0 : void NetworkConfigMonitor::remove_interface(const OPENDDS_STRING& name)
     114             : {
     115           0 :   ACE_GUARD(ACE_Thread_Mutex, g, mutex_);
     116             : 
     117           0 :   for (List::iterator pos = list_.begin(), limit = list_.end(); pos != limit;) {
     118           0 :     if (pos->name == name) {
     119           0 :       writer_->unregister_instance(*pos);
     120           0 :       list_.erase(pos++);
     121             :     } else {
     122           0 :       ++pos;
     123             :     }
     124             :   }
     125           0 : }
     126             : 
     127           0 : void NetworkConfigMonitor::remove_address(const OPENDDS_STRING& name, const NetworkAddress& address)
     128             : {
     129           0 :   ACE_GUARD(ACE_Thread_Mutex, g, mutex_);
     130             : 
     131           0 :   for (List::iterator pos = list_.begin(), limit = list_.end(); pos != limit;) {
     132           0 :     if (pos->name == name && pos->address == address) {
     133           0 :       writer_->unregister_instance(*pos);
     134           0 :       list_.erase(pos++);
     135             :     } else {
     136           0 :       ++pos;
     137             :     }
     138             :   }
     139           0 : }
     140             : 
     141             : } // DCPS
     142             : } // OpenDDS
     143             : 
     144             : OPENDDS_END_VERSIONED_NAMESPACE_DECL

Generated by: LCOV version 1.16