LCOV - code coverage report
Current view: top level - DCPS - NetworkConfigMonitor.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 20 70.0 %
Date: 2023-04-30 01:32:43 Functions: 4 6 66.7 %

          Line data    Source code
       1             : /*
       2             :  *
       3             :  *
       4             :  * Distributed under the OpenDDS License.
       5             :  * See: http://www.opendds.org/license.html
       6             :  */
       7             : 
       8             : #ifndef OPENDDS_DCPS_NETWORKCONFIGMONITOR_H
       9             : #define OPENDDS_DCPS_NETWORKCONFIGMONITOR_H
      10             : 
      11             : #include "dcps_export.h"
      12             : 
      13             : #include "InternalTopic.h"
      14             : #include "NetworkAddress.h"
      15             : #include "PoolAllocator.h"
      16             : #include "RcObject.h"
      17             : 
      18             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      19             : 
      20             : namespace OpenDDS {
      21             : namespace DCPS {
      22             : 
      23             : struct OpenDDS_Dcps_Export NetworkInterfaceAddress {
      24             :   NetworkInterfaceAddress()
      25             :     : can_multicast(false)
      26             :   {}
      27          54 :   NetworkInterfaceAddress(const OPENDDS_STRING& a_name,
      28             :                           bool a_can_multicast,
      29             :                           const NetworkAddress& a_address)
      30          54 :     : name(a_name)
      31          54 :     , can_multicast(a_can_multicast)
      32          54 :     , address(a_address)
      33          54 :   {}
      34             : 
      35             :   bool is_ipv4() const { return address.get_type() == AF_INET; }
      36             :   bool is_ipv6() const { return address.get_type() == AF_INET6; }
      37             :   bool exclude_from_multicast(const char* configured_interface) const;
      38             : 
      39           0 :   bool operator==(const NetworkInterfaceAddress& other) const
      40             :   {
      41           0 :     return name == other.name &&
      42           0 :       can_multicast == other.can_multicast &&
      43           0 :       address == other.address;
      44             :   }
      45             : 
      46           0 :   bool operator!=(const NetworkInterfaceAddress& other) const
      47             :   {
      48           0 :     return !(*this == other);
      49             :   }
      50             : 
      51         144 :   bool operator<(const NetworkInterfaceAddress& other) const
      52             :   {
      53         144 :     if (name != other.name) {
      54         117 :       return name < other.name;
      55             :     }
      56             : 
      57          27 :     return address < other.address;
      58             :   }
      59             : 
      60             :   OPENDDS_STRING name;
      61             :   bool can_multicast;
      62             :   NetworkAddress address;
      63             : };
      64             : 
      65             : struct NetworkInterfaceAddressKeyEqual {
      66          54 :   explicit NetworkInterfaceAddressKeyEqual(const NetworkInterfaceAddress& nia)
      67          54 :     : nia_(nia)
      68          54 :   {}
      69             : 
      70         135 :   bool operator()(const NetworkInterfaceAddress& other)
      71             :   {
      72         135 :     return nia_.name == other.name && nia_.address == other.address;
      73             :   }
      74             : 
      75             :   const NetworkInterfaceAddress& nia_;
      76             : };
      77             : 
      78             : class OpenDDS_Dcps_Export NetworkConfigMonitor : public virtual RcObject {
      79             : public:
      80             :   typedef OPENDDS_LIST(NetworkInterfaceAddress) List;
      81             : 
      82             :   NetworkConfigMonitor();
      83             :   virtual ~NetworkConfigMonitor();
      84             : 
      85             :   void connect(RcHandle<InternalTopic<NetworkInterfaceAddress> > topic);
      86             :   virtual bool open() = 0;
      87             :   virtual bool close() = 0;
      88             :   void disconnect(RcHandle<InternalTopic<NetworkInterfaceAddress> > topic);
      89             : 
      90             :  protected:
      91             :   void set(const List& list);
      92             :   void clear();
      93             : 
      94             :   void set(const NetworkInterfaceAddress& nia);
      95             :   void remove_interface(const OPENDDS_STRING& name);
      96             :   void remove_address(const OPENDDS_STRING& name, const NetworkAddress& address);
      97             : 
      98             : private:
      99             :   RcHandle<InternalDataWriter<NetworkInterfaceAddress> > writer_;
     100             : 
     101             :   List list_;
     102             : 
     103             :   mutable ACE_Thread_Mutex mutex_;
     104             : };
     105             : 
     106             : typedef RcHandle<NetworkConfigMonitor> NetworkConfigMonitor_rch;
     107             : 
     108             : } // DCPS
     109             : } // OpenDDS
     110             : 
     111             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
     112             : 
     113             : #endif // OPENDDS_DCPS_NETWORKCONFIGMONITOR_H

Generated by: LCOV version 1.16