a stub NetworkMonitor for unit testing More...
#include <network-monitor-stub.hpp>
Public Member Functions | |
NetworkMonitorStub (uint32_t capabilities) | |
constructor More... | |
void | addInterface (shared_ptr< NetworkInterface > netif) |
emit the onInterfaceAdded signal and add netif internally More... | |
void | removeInterface (const std::string &ifname) |
emit the onInterfaceRemoved signal and remove netif internally More... | |
void | emitEnumerationCompleted () |
emit the onEnumerationCompleted signal More... | |
Public Member Functions inherited from ndn::net::NetworkMonitor | |
NetworkMonitor (boost::asio::io_service &io) | |
Construct instance, request enumeration of all network interfaces, and start monitoring for network state changes. More... | |
uint32_t | getCapabilities () const |
Returns a bitwise OR'ed set of Capability flags supported on the current platform. More... | |
shared_ptr< const NetworkInterface > | getNetworkInterface (const std::string &ifname) const |
Returns the NetworkInterface with the given name, or nullptr if it does not exist. More... | |
NDN_CXX_NODISCARD std::vector< shared_ptr< const NetworkInterface > > | listNetworkInterfaces () const |
Lists all network interfaces currently available on the system. More... | |
Static Public Member Functions | |
static shared_ptr< NetworkInterface > | makeNetworkInterface () |
create a NetworkInterface instance More... | |
Additional Inherited Members | |
Public Types inherited from ndn::net::NetworkMonitor | |
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 Attributes inherited from ndn::net::NetworkMonitor | |
util::Signal< NetworkMonitorImpl > & | onEnumerationCompleted |
Fires when the enumeration of all network interfaces on the system is complete. More... | |
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & | onInterfaceAdded |
Fires whenever a new interface is detected on the system. More... | |
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > & | onInterfaceRemoved |
Fires whenever an interface disappears from the system. More... | |
util::Signal< NetworkMonitorImpl > & | onNetworkStateChanged |
Protected Member Functions inherited from ndn::net::NetworkMonitor | |
NetworkMonitor (unique_ptr< NetworkMonitorImpl > impl) | |
NetworkMonitorImpl & | getImpl () |
a stub NetworkMonitor for unit testing
Definition at line 34 of file network-monitor-stub.hpp.
|
explicit |
constructor
capabilities | capabilities reported by getCapabilities |
Definition at line 102 of file network-monitor-stub.cpp.
|
static |
create a NetworkInterface instance
Definition at line 114 of file network-monitor-stub.cpp.
References ndn::net::NetworkMonitorImpl::makeNetworkInterface().
void ndn::net::NetworkMonitorStub::addInterface | ( | shared_ptr< NetworkInterface > | netif | ) |
emit the onInterfaceAdded
signal and add netif
internally
netif | new network interface |
std::invalid_argument | a network interface with same name already exists |
Definition at line 120 of file network-monitor-stub.cpp.
References ndn::net::NetworkMonitorImplStub::addInterface(), and nonstd::optional_lite::std11::move().
void ndn::net::NetworkMonitorStub::removeInterface | ( | const std::string & | ifname | ) |
emit the onInterfaceRemoved
signal and remove netif
internally
ifname | network interface name |
Definition at line 126 of file network-monitor-stub.cpp.
References ndn::net::NetworkMonitorImplStub::removeInterface().
void ndn::net::NetworkMonitorStub::emitEnumerationCompleted | ( | ) |
emit the onEnumerationCompleted
signal
A real NetworkMonitor starts with an "enumerating" state, during which the initial information about network interfaces is collected from the OS. Upon discovering a network interface, it emits the onInterfaceAdded
signal. When the initial enumerating completes, it emits the onEnumerationCompleted signal.
To simulate this procedure on a newly constructed MockNetworkMonitor, the caller should invoke addInterface
once for each network interface that already exists, and then invoke signalEnumerationCompleted
.
Definition at line 132 of file network-monitor-stub.cpp.
References ndn::net::NetworkMonitorImplStub::emitEnumerationCompleted().