network-monitor.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2017 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  *
21  * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
22  * @author Davide Pesavento <davide.pesavento@lip6.fr>
23  */
24 
25 #ifndef NDN_NET_NETWORK_MONITOR_HPP
26 #define NDN_NET_NETWORK_MONITOR_HPP
27 
28 #include "asio-fwd.hpp"
29 #include "network-interface.hpp"
30 
31 #include <vector>
32 
33 namespace ndn {
34 namespace net {
35 
36 class NetworkMonitorImpl;
37 
50 class NetworkMonitor : noncopyable
51 {
52 public:
53  class Error : public std::runtime_error
54  {
55  public:
56  explicit
57  Error(const std::string& what)
58  : std::runtime_error(what)
59  {
60  }
61  };
62 
70  explicit
71  NetworkMonitor(boost::asio::io_service& io);
72 
73  enum Capability : uint32_t {
75  CAP_NONE = 0,
77  CAP_ENUM = 1 << 0,
81  CAP_STATE_CHANGE = 1 << 2,
83  CAP_MTU_CHANGE = 1 << 3,
86  };
87 
89  uint32_t
90  getCapabilities() const;
91 
93  shared_ptr<const NetworkInterface>
94  getNetworkInterface(const std::string& ifname) const;
95 
101  std::vector<shared_ptr<const NetworkInterface>>
102  listNetworkInterfaces() const;
103 
104 protected:
105  explicit
106  NetworkMonitor(unique_ptr<NetworkMonitorImpl> impl);
107 
110  {
111  return *m_impl;
112  }
113 
114 private:
115  const unique_ptr<NetworkMonitorImpl> m_impl;
116  // Intentional violation of code-style rule 1.4: m_impl must be assigned before its signals can
117  // be assigned to references below.
118 
119 public: // signals
121  util::Signal<NetworkMonitorImpl>& onEnumerationCompleted;
122 
124  util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface>>& onInterfaceAdded;
125 
131  util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface>>& onInterfaceRemoved;
132 
134  util::Signal<NetworkMonitorImpl>& onNetworkStateChanged;
135 };
136 
137 class NetworkMonitorImpl : noncopyable
138 {
139 public:
140  virtual
141  ~NetworkMonitorImpl() = default;
142 
143  virtual uint32_t
144  getCapabilities() const = 0;
145 
146  virtual shared_ptr<const NetworkInterface>
147  getNetworkInterface(const std::string&) const = 0;
148 
149  virtual std::vector<shared_ptr<const NetworkInterface>>
150  listNetworkInterfaces() const = 0;
151 
152 protected:
153  static shared_ptr<NetworkInterface>
154  makeNetworkInterface();
155 
156 public:
157  util::Signal<NetworkMonitorImpl> onEnumerationCompleted;
158  util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface>> onInterfaceAdded;
159  util::Signal<NetworkMonitorImpl, shared_ptr<const NetworkInterface>> onInterfaceRemoved;
160  util::Signal<NetworkMonitorImpl> onNetworkStateChanged;
161 
162 protected:
163  DECLARE_SIGNAL_EMIT(onEnumerationCompleted)
164  DECLARE_SIGNAL_EMIT(onInterfaceAdded)
165  DECLARE_SIGNAL_EMIT(onInterfaceRemoved)
166  DECLARE_SIGNAL_EMIT(onNetworkStateChanged)
167 };
168 
169 } // namespace net
170 } // namespace ndn
171 
172 #endif // NDN_NET_NETWORK_MONITOR_HPP
Copyright (c) 2013-2017 Regents of the University of California.
Definition: common.hpp:66
listNetworkInterfaces() and getNetworkInterface() are supported
NetworkMonitor(boost::asio::io_service &io)
Construct instance, request enumeration of all network interfaces, and start monitoring for network s...
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceAdded
Fires when a new interface is added.
NetworkInterface onAddressAdded and onAddressRemoved signals are supported.
NetworkInterface onMtuChanged signal is supported.
NetworkInterface onStateChanged signal is supported.
util::Signal< NetworkMonitorImpl > & onNetworkStateChanged
shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &ifname) const
Returns the NetworkInterface with the given name, or nullptr if it does not exist.
STL namespace.
Network interface monitor.
util::Signal< NetworkMonitorImpl > onEnumerationCompleted
uint32_t getCapabilities() const
Returns a bitwise OR&#39;ed set of Capability flags supported on the current platform.
NetworkMonitor is not supported and is a no-op.
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
std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const
Lists all network interfaces currently available on the system.
NetworkMonitorImpl & getImpl()
NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported.
Error(const std::string &what)
util::Signal< NetworkMonitorImpl > onNetworkStateChanged
util::Signal< NetworkMonitorImpl > & onEnumerationCompleted
Fires when network interfaces enumeration is complete.