ndn::util::NetworkMonitor Class Reference

Network interfaces monitor. More...

#include <network-monitor.hpp>

Inheritance diagram for ndn::util::NetworkMonitor:
[legend]
Collaboration diagram for ndn::util::NetworkMonitor:
[legend]

Data Structures

class  Error
 
class  Impl
 

Public Types

enum  Capability : uint32_t {
  CAP_NONE = 0, CAP_ENUM = 1 << 0, CAP_IF_ADD_REMOVE = 1 << 1, CAP_STATE_CHANGE = 1 << 2,
  CAP_MTU_CHANGE = 1 << 3, CAP_ADDR_ADD_REMOVE = 1 << 4
}
 

Public Member Functions

 NetworkMonitor (boost::asio::io_service &io)
 Construct instance, request enumeration of all network interfaces, and start monitoring for network state changes. More...
 
 ~NetworkMonitor ()
 
uint32_t getCapabilities () const
 
shared_ptr< NetworkInterfacegetNetworkInterface (const std::string &ifname) const
 
std::vector< shared_ptr< NetworkInterface > > listNetworkInterfaces () const
 

Data Fields

Signal< NetworkMonitoronEnumerationCompleted
 Fires when network interfaces enumeration is complete. More...
 
Signal< NetworkMonitor, shared_ptr< NetworkInterface > > onInterfaceAdded
 Fires when a new interface is added. More...
 
Signal< NetworkMonitor, shared_ptr< NetworkInterface > > onInterfaceRemoved
 Fires when an interface is removed. More...
 
Signal< NetworkMonitoronNetworkStateChanged
 

Detailed Description

Network interfaces monitor.

Maintains an up-to-date view of every system network interface and notifies when an interface is added or removed.

Note
Implementation of this class is platform dependent and not all supported platforms are supported:
  • OS X: CFNotificationCenterAddObserver (incomplete)
  • Linux: rtnetlink notifications
Todo:
macOS implementation needs to be updated to emit the new signals and keep track of interfaces (links) and addresses

Definition at line 58 of file network-monitor.hpp.

Member Enumeration Documentation

Enumerator
CAP_NONE 

NetworkMonitor is not supported and is a no-op.

CAP_ENUM 

listNetworkInterfaces() and getNetworkInterface() are supported

CAP_IF_ADD_REMOVE 

NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported.

CAP_STATE_CHANGE 

NetworkInterface onStateChanged signal is supported.

CAP_MTU_CHANGE 

NetworkInterface onMtuChanged signal is supported.

CAP_ADDR_ADD_REMOVE 

NetworkInterface onAddressAdded and onAddressRemoved signals are supported.

Definition at line 85 of file network-monitor.hpp.

Constructor & Destructor Documentation

ndn::util::NetworkMonitor::NetworkMonitor ( boost::asio::io_service &  io)
explicit

Construct instance, request enumeration of all network interfaces, and start monitoring for network state changes.

Parameters
ioio_service thread that will dispatch events
Exceptions
Errorwhen network monitoring is not supported or there is an error starting monitoring

Definition at line 39 of file network-monitor.cpp.

ndn::util::NetworkMonitor::~NetworkMonitor ( )
default

Member Function Documentation

uint32_t ndn::util::NetworkMonitor::getCapabilities ( ) const
Returns
bitwise OR'ed Capability supported on current platform

Definition at line 47 of file network-monitor.cpp.

shared_ptr< NetworkInterface > ndn::util::NetworkMonitor::getNetworkInterface ( const std::string &  ifname) const

Definition at line 53 of file network-monitor.cpp.

std::vector< shared_ptr< NetworkInterface > > ndn::util::NetworkMonitor::listNetworkInterfaces ( ) const

Definition at line 59 of file network-monitor.cpp.

Field Documentation

Signal<NetworkMonitor> ndn::util::NetworkMonitor::onEnumerationCompleted

Fires when network interfaces enumeration is complete.

Definition at line 114 of file network-monitor.hpp.

Signal<NetworkMonitor, shared_ptr<NetworkInterface> > ndn::util::NetworkMonitor::onInterfaceAdded

Fires when a new interface is added.

Definition at line 118 of file network-monitor.hpp.

Signal<NetworkMonitor, shared_ptr<NetworkInterface> > ndn::util::NetworkMonitor::onInterfaceRemoved

Fires when an interface is removed.

Note
The NetworkInterface object is no longer present in the network interfaces map when the signal is emitted

Definition at line 125 of file network-monitor.hpp.

Signal<NetworkMonitor> ndn::util::NetworkMonitor::onNetworkStateChanged

Definition at line 128 of file network-monitor.hpp.