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-2021 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_CXX_NET_NETWORK_MONITOR_HPP
26 #define NDN_CXX_NET_NETWORK_MONITOR_HPP
27 
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  using std::runtime_error::runtime_error;
57  };
58 
64  explicit
65  NetworkMonitor(boost::asio::io_service& io);
66 
67  enum Capability : uint32_t {
69  CAP_NONE = 0,
71  CAP_ENUM = 1 << 0,
75  CAP_STATE_CHANGE = 1 << 2,
77  CAP_MTU_CHANGE = 1 << 3,
79  CAP_ADDR_ADD_REMOVE = 1 << 4
80  };
81 
83  uint32_t
84  getCapabilities() const;
85 
87  shared_ptr<const NetworkInterface>
88  getNetworkInterface(const std::string& ifname) const;
89 
95  NDN_CXX_NODISCARD std::vector<shared_ptr<const NetworkInterface>>
96  listNetworkInterfaces() const;
97 
98 protected:
99  explicit
100  NetworkMonitor(unique_ptr<NetworkMonitorImpl> impl);
101 
104  {
105  return *m_impl;
106  }
107 
108 private:
109  const unique_ptr<NetworkMonitorImpl> m_impl;
110  // Intentional violation of code-style rule 1.4: m_impl must be assigned before its signals can
111  // be assigned to references below.
112 
113 public: // signals
116 
119 
126 
129 };
130 
131 class NetworkMonitorImpl : noncopyable
132 {
133 public:
135 
136  virtual
137  ~NetworkMonitorImpl() = default;
138 
139  virtual uint32_t
140  getCapabilities() const = 0;
141 
142  virtual shared_ptr<const NetworkInterface>
143  getNetworkInterface(const std::string&) const = 0;
144 
145  virtual std::vector<shared_ptr<const NetworkInterface>>
147 
148 protected:
149  static shared_ptr<NetworkInterface>
151 
152 public:
157 
158 protected:
163 };
164 
165 } // namespace net
166 } // namespace ndn
167 
168 #endif // NDN_CXX_NET_NETWORK_MONITOR_HPP
#define NDN_CXX_NODISCARD
Definition: backports.hpp:68
virtual uint32_t getCapabilities() const =0
virtual std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const =0
static shared_ptr< NetworkInterface > makeNetworkInterface()
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceRemoved
virtual shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &) const =0
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceAdded
util::Signal< NetworkMonitorImpl > onEnumerationCompleted
virtual ~NetworkMonitorImpl()=default
util::Signal< NetworkMonitorImpl > onNetworkStateChanged
Network interface monitor.
NetworkMonitor(boost::asio::io_service &io)
Construct instance, request enumeration of all network interfaces, and start monitoring for network s...
util::Signal< NetworkMonitorImpl > & onEnumerationCompleted
Fires when the enumeration of all network interfaces on the system is complete.
uint32_t getCapabilities() const
Returns a bitwise OR'ed set of Capability flags supported on the current platform.
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceAdded
Fires whenever a new interface is detected on the system.
std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const
Lists all network interfaces currently available on the system.
shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &ifname) const
Returns the NetworkInterface with the given name, or nullptr if it does not exist.
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceRemoved
Fires whenever an interface disappears from the system.
@ CAP_NONE
NetworkMonitor is not supported and is a no-op.
@ CAP_IF_ADD_REMOVE
NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported.
@ CAP_ENUM
listNetworkInterfaces() and getNetworkInterface() are supported
@ CAP_MTU_CHANGE
NetworkInterface onMtuChanged signal is supported.
@ CAP_STATE_CHANGE
NetworkInterface onStateChanged signal is supported.
@ CAP_ADDR_ADD_REMOVE
NetworkInterface onAddressAdded and onAddressRemoved signals are supported.
NetworkMonitorImpl & getImpl()
util::Signal< NetworkMonitorImpl > & onNetworkStateChanged
provides a lightweight signal / event system
Definition: signal.hpp:53
#define DECLARE_SIGNAL_EMIT(signalName)
(implementation detail) declares a 'emit_signalName' method
Definition: emit.hpp:59
Definition: data.cpp:25