OpenDDS  Snapshot(2023/04/28-20:55)
LinuxNetworkConfigMonitor.h
Go to the documentation of this file.
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 
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  OpenHandler(const RcHandle<LinuxNetworkConfigMonitor>& lncm)
42  : lncm_(lncm)
43  , condition_(mutex_)
44  , done_(false)
45  , retval_(false)
46  {}
47 
48  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  CloseHandler(const RcHandle<LinuxNetworkConfigMonitor>& lncm)
67  : lncm_(lncm)
68  , condition_(mutex_)
69  , done_(false)
70  , retval_(false)
71  {}
72 
73  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 {
100  bool can_multicast;
101 
102  NetworkInterface()
103  : can_multicast(false)
104  {}
105 
106  NetworkInterface(const OPENDDS_STRING& a_name,
107  bool a_can_multicast)
108  : name(a_name)
109  , can_multicast(a_can_multicast)
110  {}
111  };
112 
113  typedef OPENDDS_MAP(int, NetworkInterface) NetworkInterfaceMap;
114  NetworkInterfaceMap network_interface_map_;
115 };
116 
117 } // DCPS
118 } // OpenDDS
119 
121 
122 #endif // ACE_LINUX || ACE_ANDROID
123 
124 #endif // OPENDDS_DCPS_LINUXNETWORKCONFIGPUBLISHER_H
#define OpenDDS_Dcps_Export
Definition: dcps_export.h:24
pid_t wait(int *=0)
int close(ACE_HANDLE handle)
#define OPENDDS_STRING
ACE_HANDLE open(const char *filename, int mode, mode_t perms=ACE_DEFAULT_OPEN_PERMS, LPSECURITY_ATTRIBUTES sa=0)
Christopher Diggins *renamed files *fixing compilation errors *adding Visual C project file *removed make Max Lybbert *removed references to missing and unused header
Definition: CHANGELOG.txt:8
const char *const name
Definition: debug.cpp:60
ACE_HANDLE get_handle(void)
WeakRcHandle< ReactorInterceptor > ReactorInterceptor_wrch
RcHandle< ReactorInterceptor > ReactorInterceptor_rch
#define OPENDDS_END_VERSIONED_NAMESPACE_DECL
The Internal API and Implementation of OpenDDS.
Definition: AddressCache.h:28
typedef OPENDDS_MAP(OPENDDS_STRING, OPENDDS_STRING) ValueMap
Helper types and functions for config file parsing.