26 #include <unordered_map> 27 #include <boost/range/adaptor/map.hpp> 28 #include <boost/range/algorithm/copy.hpp> 33 class NetworkMonitorImplStub :
public NetworkMonitorImpl
37 NetworkMonitorImplStub(uint32_t capabilities)
38 : m_capabilities(capabilities)
43 getCapabilities() const final
45 return m_capabilities;
48 shared_ptr<const NetworkInterface>
49 getNetworkInterface(
const std::string& ifname)
const final 51 auto i = m_interfaces.find(ifname);
52 return i == m_interfaces.end() ?
nullptr : i->second;
55 std::vector<shared_ptr<const NetworkInterface>>
56 listNetworkInterfaces() const final
58 std::vector<shared_ptr<const NetworkInterface>> v;
59 boost::copy(m_interfaces | boost::adaptors::map_values, std::back_inserter(v));
67 addInterface(shared_ptr<NetworkInterface> netif)
69 BOOST_ASSERT(netif !=
nullptr);
70 bool isNew = m_interfaces.emplace(netif->getName(), netif).second;
72 BOOST_THROW_EXCEPTION(std::invalid_argument(
"duplicate ifname"));
78 removeInterface(
const std::string& ifname)
80 auto i = m_interfaces.find(ifname);
81 if (i == m_interfaces.end()) {
84 shared_ptr<NetworkInterface> netif = i->second;
85 m_interfaces.erase(i);
90 emitEnumerationCompleted()
96 uint32_t m_capabilities;
97 std::unordered_map<std::string, shared_ptr<NetworkInterface>> m_interfaces;
105 NetworkMonitorImplStub&
106 NetworkMonitorStub::getImpl()
111 shared_ptr<NetworkInterface>
114 return NetworkMonitorImplStub::makeNetworkInterface();
120 this->getImpl().addInterface(std::move(netif));
126 this->getImpl().removeInterface(ifname);
132 this->getImpl().emitEnumerationCompleted();
Copyright (c) 2013-2017 Regents of the University of California.
void addInterface(shared_ptr< NetworkInterface > netif)
emit the onInterfaceAdded signal and add netif internally
static shared_ptr< NetworkInterface > makeNetworkInterface()
static shared_ptr< NetworkInterface > makeNetworkInterface()
create a NetworkInterface instance
void emitEnumerationCompleted()
emit the onEnumerationCompleted signal
unique_ptr< T > make_unique(Args &&...args)
#define emitSignal(...)
(implementation detail)
void removeInterface(const std::string &ifname)
emit the onInterfaceRemoved signal and remove netif internally
Network interface monitor.
NetworkMonitorStub(uint32_t capabilities)
constructor
NetworkMonitorImpl & getImpl()