27 #include <unordered_map>
29 #include <boost/range/adaptor/map.hpp>
30 #include <boost/range/algorithm/copy.hpp>
35 class NetworkMonitorImplStub :
public NetworkMonitorImpl
39 NetworkMonitorImplStub(uint32_t capabilities)
40 : m_capabilities(capabilities)
45 getCapabilities() const final
47 return m_capabilities;
50 shared_ptr<const NetworkInterface>
51 getNetworkInterface(
const std::string& ifname)
const final
53 auto i = m_interfaces.find(ifname);
54 return i == m_interfaces.end() ? nullptr : i->second;
57 std::vector<shared_ptr<const NetworkInterface>>
58 listNetworkInterfaces() const final
60 std::vector<shared_ptr<const NetworkInterface>> v;
61 boost::copy(m_interfaces | boost::adaptors::map_values, std::back_inserter(v));
69 addInterface(shared_ptr<NetworkInterface> netif)
71 BOOST_ASSERT(netif !=
nullptr);
72 bool isNew = m_interfaces.emplace(netif->getName(), netif).second;
74 NDN_THROW(std::invalid_argument(
"duplicate ifname"));
80 removeInterface(
const std::string& ifname)
82 auto i = m_interfaces.find(ifname);
83 if (i == m_interfaces.end()) {
86 shared_ptr<NetworkInterface> netif = i->second;
87 m_interfaces.erase(i);
92 emitEnumerationCompleted()
98 uint32_t m_capabilities;
99 std::unordered_map<std::string, shared_ptr<NetworkInterface>> m_interfaces;
103 :
NetworkMonitor(make_unique<NetworkMonitorImplStub>(capabilities))
107 NetworkMonitorImplStub&
108 NetworkMonitorStub::getImpl()
113 shared_ptr<NetworkInterface>
116 return NetworkMonitorImplStub::makeNetworkInterface();
122 this->getImpl().addInterface(std::move(netif));
128 this->getImpl().removeInterface(ifname);
134 this->getImpl().emitEnumerationCompleted();
static shared_ptr< NetworkInterface > makeNetworkInterface()
NetworkMonitorStub(uint32_t capabilities)
constructor
void removeInterface(const std::string &ifname)
emit the onInterfaceRemoved signal and remove netif internally
void emitEnumerationCompleted()
emit the onEnumerationCompleted signal
static shared_ptr< NetworkInterface > makeNetworkInterface()
create a NetworkInterface instance
void addInterface(shared_ptr< NetworkInterface > netif)
emit the onInterfaceAdded signal and add netif internally
Network interface monitor.
NetworkMonitorImpl & getImpl()
#define emitSignal(...)
(implementation detail)