network-monitor.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
25 #ifndef NDN_NET_NETWORK_MONITOR_HPP
26 #define NDN_NET_NETWORK_MONITOR_HPP
27 
28 #include "network-interface.hpp"
29 #include <vector>
30 
31 namespace boost {
32 namespace asio {
33 class io_service;
34 } // namespace asio
35 } // namespace boost
36 
37 namespace ndn {
38 namespace net {
39 
40 class NetworkMonitorImpl;
41 
54 class NetworkMonitor : noncopyable
55 {
56 public:
57  class Error : public std::runtime_error
58  {
59  public:
60  explicit
61  Error(const std::string& what)
62  : std::runtime_error(what)
63  {
64  }
65  };
66 
74  explicit
75  NetworkMonitor(boost::asio::io_service& io);
76 
77  enum Capability : uint32_t {
79  CAP_NONE = 0,
81  CAP_ENUM = 1 << 0,
83  CAP_IF_ADD_REMOVE = 1 << 1,
85  CAP_STATE_CHANGE = 1 << 2,
87  CAP_MTU_CHANGE = 1 << 3,
89  CAP_ADDR_ADD_REMOVE = 1 << 4
90  };
91 
93  uint32_t
94  getCapabilities() const;
95 
97  shared_ptr<const NetworkInterface>
98  getNetworkInterface(const std::string& ifname) const;
99 
105  std::vector<shared_ptr<const NetworkInterface>>
106  listNetworkInterfaces() const;
107 
108 protected:
109  explicit
110  NetworkMonitor(unique_ptr<NetworkMonitorImpl> impl);
111 
114  {
115  return *m_impl;
116  }
117 
118 private:
119  const unique_ptr<NetworkMonitorImpl> m_impl;
120  // Intentional violation of code-style rule 1.4: m_impl must be assigned before its signals can
121  // be assigned to references below.
122 
123 public: // signals
125  util::Signal<NetworkMonitorImpl>& onEnumerationCompleted;
126 
128  util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface>>& onInterfaceAdded;
129 
135  util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface>>& onInterfaceRemoved;
136 
138  util::Signal<NetworkMonitorImpl>& onNetworkStateChanged;
139 };
140 
141 class NetworkMonitorImpl : noncopyable
142 {
143 public:
144  virtual
145  ~NetworkMonitorImpl() = default;
146 
147  virtual uint32_t
148  getCapabilities() const = 0;
149 
150  virtual shared_ptr<const NetworkInterface>
151  getNetworkInterface(const std::string&) const = 0;
152 
153  virtual std::vector<shared_ptr<const NetworkInterface>>
154  listNetworkInterfaces() const = 0;
155 
156 protected:
157  static shared_ptr<NetworkInterface>
158  makeNetworkInterface();
159 
160 public:
161  util::Signal<NetworkMonitorImpl> onEnumerationCompleted;
162  util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface>> onInterfaceAdded;
163  util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface>> onInterfaceRemoved;
164  util::Signal<NetworkMonitorImpl> onNetworkStateChanged;
165 
166 protected:
167  DECLARE_SIGNAL_EMIT(onEnumerationCompleted)
168  DECLARE_SIGNAL_EMIT(onInterfaceAdded)
169  DECLARE_SIGNAL_EMIT(onInterfaceRemoved)
170  DECLARE_SIGNAL_EMIT(onNetworkStateChanged)
171 };
172 
173 } // namespace net
174 } // namespace ndn
175 
176 #endif // NDN_NET_NETWORK_MONITOR_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
Copyright (c) 2013-2017 Regents of the University of California.
Definition: block.hpp:31
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceAdded
Fires when a new interface is added.
util::Signal< NetworkMonitorImpl > & onNetworkStateChanged
STL namespace.
Network interface monitor.
util::Signal< NetworkMonitorImpl > onEnumerationCompleted
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceRemoved
Fires when an interface is removed.
#define DECLARE_SIGNAL_EMIT(signalName)
(implementation detail) declares a &#39;emit_signalName&#39; method
Definition: emit.hpp:59
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceRemoved
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceAdded
NetworkMonitorImpl & getImpl()
Error(const std::string &what)
util::Signal< NetworkMonitorImpl > onNetworkStateChanged
util::Signal< NetworkMonitorImpl > & onEnumerationCompleted
Fires when network interfaces enumeration is complete.