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-2023 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 
32 
33 #include <vector>
34 
35 namespace ndn::net {
36 
37 class NetworkMonitorImpl;
38 
51 class NetworkMonitor : noncopyable
52 {
53 public:
54  class Error : public std::runtime_error
55  {
56  public:
57  using std::runtime_error::runtime_error;
58  };
59 
65  explicit
66  NetworkMonitor(boost::asio::io_context& ioCtx);
67 
68  enum Capability : uint32_t {
70  CAP_NONE = 0,
72  CAP_ENUM = 1 << 0,
76  CAP_STATE_CHANGE = 1 << 2,
78  CAP_MTU_CHANGE = 1 << 3,
80  CAP_ADDR_ADD_REMOVE = 1 << 4
81  };
82 
84  uint32_t
85  getCapabilities() const;
86 
88  shared_ptr<const NetworkInterface>
89  getNetworkInterface(const std::string& ifname) const;
90 
96  [[nodiscard]] std::vector<shared_ptr<const NetworkInterface>>
97  listNetworkInterfaces() const;
98 
99 protected:
100  explicit
101  NetworkMonitor(unique_ptr<NetworkMonitorImpl> impl);
102 
105  {
106  return *m_impl;
107  }
108 
109 private:
110  const unique_ptr<NetworkMonitorImpl> m_impl;
111  // Intentional violation of code-style rule 1.4: m_impl must be assigned before its signals can
112  // be assigned to references below.
113 
114 public: // signals
117 
120 
127 
130 };
131 
132 class NetworkMonitorImpl : noncopyable
133 {
134 public:
136 
137  virtual
138  ~NetworkMonitorImpl() = default;
139 
140  virtual uint32_t
141  getCapabilities() const = 0;
142 
143  virtual shared_ptr<const NetworkInterface>
144  getNetworkInterface(const std::string&) const = 0;
145 
146  virtual std::vector<shared_ptr<const NetworkInterface>>
148 
149 protected:
150  static shared_ptr<NetworkInterface>
152 
153 public:
158 
159 protected:
164 };
165 
166 } // namespace ndn::net
167 
168 #endif // NDN_CXX_NET_NETWORK_MONITOR_HPP
signal::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceRemoved
signal::Signal< NetworkMonitorImpl > onNetworkStateChanged
signal::Signal< NetworkMonitorImpl > onEnumerationCompleted
virtual uint32_t getCapabilities() const =0
virtual std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const =0
static shared_ptr< NetworkInterface > makeNetworkInterface()
virtual shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &) const =0
signal::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceAdded
virtual ~NetworkMonitorImpl()=default
Network interface monitor.
NetworkMonitor(boost::asio::io_context &ioCtx)
Construct instance, request enumeration of all network interfaces, and start monitoring for network s...
signal::Signal< NetworkMonitorImpl > & onNetworkStateChanged
uint32_t getCapabilities() const
Returns a bitwise OR'ed set of Capability flags supported on the current platform.
signal::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceAdded
Fires whenever a new interface is detected on the system.
signal::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & onInterfaceRemoved
Fires whenever an interface disappears from 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.
@ 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()
signal::Signal< NetworkMonitorImpl > & onEnumerationCompleted
Fires when the enumeration of all network interfaces on the system is complete.
Provides a lightweight signal / event system.
Definition: signal.hpp:51
This header provides macros that allows a signal to be emitted from a derived class of its owner.
#define DECLARE_SIGNAL_EMIT(signalName)
(implementation detail) declares a 'emit_signalName' method
Definition: emit.hpp:55