LCOV - code coverage report
Current view: top level - DCPS - LinuxNetworkConfigMonitor.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 21 21 100.0 %
Date: 2023-04-30 01:32:43 Functions: 8 8 100.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             : #ifndef OPENDDS_DCPS_LINUXNETWORKCONFIGMONITOR_H
       9             : #define OPENDDS_DCPS_LINUXNETWORKCONFIGMONITOR_H
      10             : 
      11             : #include "ace/config.h"
      12             : 
      13             : #if (defined(ACE_LINUX) || defined(ACE_ANDROID)) && !defined(OPENDDS_SAFETY_PROFILE)
      14             : 
      15             : #define OPENDDS_LINUX_NETWORK_CONFIG_MONITOR
      16             : 
      17             : #include "NetworkConfigMonitor.h"
      18             : #include "RcEventHandler.h"
      19             : #include "ReactorInterceptor.h"
      20             : #include "dcps_export.h"
      21             : 
      22             : #include <ace/SOCK_Netlink.h>
      23             : 
      24             : OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
      25             : 
      26             : namespace OpenDDS {
      27             : namespace DCPS {
      28             : 
      29             : class OpenDDS_Dcps_Export LinuxNetworkConfigMonitor
      30             :   : public virtual RcEventHandler
      31             :   , public virtual NetworkConfigMonitor
      32             : {
      33             : public:
      34             :   explicit LinuxNetworkConfigMonitor(ReactorInterceptor_rch interceptor);
      35             :   bool open();
      36             :   bool close();
      37             : 
      38             : private:
      39             :   class OpenHandler : public ReactorInterceptor::Command {
      40             :   public:
      41           9 :     OpenHandler(const RcHandle<LinuxNetworkConfigMonitor>& lncm)
      42          18 :       : lncm_(lncm)
      43           9 :       , condition_(mutex_)
      44           9 :       , done_(false)
      45           9 :       , retval_(false)
      46           9 :     {}
      47             : 
      48          18 :     virtual ~OpenHandler() {}
      49             : 
      50             :     bool wait() const;
      51             : 
      52             :   private:
      53             :     void execute();
      54             : 
      55             :     WeakRcHandle<LinuxNetworkConfigMonitor> lncm_;
      56             :     mutable ACE_Thread_Mutex mutex_;
      57             :     mutable ConditionVariable<ACE_Thread_Mutex> condition_;
      58             :     bool done_;
      59             :     bool retval_;
      60             :   };
      61             : 
      62             :   bool open_i();
      63             : 
      64             :   class CloseHandler : public ReactorInterceptor::Command {
      65             :   public:
      66           9 :     CloseHandler(const RcHandle<LinuxNetworkConfigMonitor>& lncm)
      67          18 :       : lncm_(lncm)
      68           9 :       , condition_(mutex_)
      69           9 :       , done_(false)
      70           9 :       , retval_(false)
      71           9 :     {}
      72             : 
      73          18 :     virtual ~CloseHandler() {}
      74             : 
      75             :     bool wait() const;
      76             : 
      77             :   private:
      78             :     void execute();
      79             : 
      80             :     WeakRcHandle<LinuxNetworkConfigMonitor> lncm_;
      81             :     mutable ACE_Thread_Mutex mutex_;
      82             :     mutable ConditionVariable<ACE_Thread_Mutex> condition_;
      83             :     bool done_;
      84             :     bool retval_;
      85             :   };
      86             : 
      87             :   bool close_i();
      88             : 
      89             :   ACE_HANDLE get_handle() const;
      90             :   int handle_input(ACE_HANDLE);
      91             :   void read_messages();
      92             :   void process_message(const nlmsghdr* header);
      93             : 
      94             :   ACE_SOCK_Netlink socket_;
      95             :   ACE_Thread_Mutex socket_mutex_;
      96             :   ReactorInterceptor_wrch interceptor_;
      97             : 
      98             :   struct NetworkInterface {
      99             :     OPENDDS_STRING name;
     100             :     bool can_multicast;
     101             : 
     102          45 :     NetworkInterface()
     103          45 :       : can_multicast(false)
     104          45 :     {}
     105             : 
     106          45 :     NetworkInterface(const OPENDDS_STRING& a_name,
     107             :                      bool a_can_multicast)
     108          45 :       : name(a_name)
     109          45 :       , can_multicast(a_can_multicast)
     110          45 :     {}
     111             :   };
     112             : 
     113             :   typedef OPENDDS_MAP(int, NetworkInterface) NetworkInterfaceMap;
     114             :   NetworkInterfaceMap network_interface_map_;
     115             : };
     116             : 
     117             : } // DCPS
     118             : } // OpenDDS
     119             : 
     120             : OPENDDS_END_VERSIONED_NAMESPACE_DECL
     121             : 
     122             : #endif // ACE_LINUX || ACE_ANDROID
     123             : 
     124             : #endif // OPENDDS_DCPS_LINUXNETWORKCONFIGPUBLISHER_H

Generated by: LCOV version 1.16