26 #include <unordered_map> 27 #include <boost/range/adaptor/map.hpp> 28 #include <boost/range/algorithm/copy.hpp> 38 : m_capabilities(capabilities)
45 return m_capabilities;
48 shared_ptr<const NetworkInterface>
51 auto i = m_interfaces.find(ifname);
52 return i == m_interfaces.end() ?
nullptr : i->second;
55 std::vector<shared_ptr<const NetworkInterface>>
58 std::vector<shared_ptr<const NetworkInterface>> v;
59 boost::copy(m_interfaces | boost::adaptors::map_values, std::back_inserter(v));
69 BOOST_ASSERT(netif !=
nullptr);
70 bool isNew = m_interfaces.emplace(netif->getName(), netif).second;
72 BOOST_THROW_EXCEPTION(std::invalid_argument(
"duplicate 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);
96 uint32_t m_capabilities;
97 std::unordered_map<std::string, shared_ptr<NetworkInterface>> m_interfaces;
106 NetworkMonitorStub::getImpl()
111 shared_ptr<NetworkInterface>
uint32_t getCapabilities() const final
Copyright (c) 2011-2015 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 emitEnumerationCompleted()
void removeInterface(const std::string &ifname)
emit the onInterfaceRemoved signal and remove netif internally
Network interface monitor.
NetworkMonitorStub(uint32_t capabilities)
constructor
util::Signal< NetworkMonitorImpl > onEnumerationCompleted
std::vector< shared_ptr< const NetworkInterface > > listNetworkInterfaces() const final
NetworkMonitorImplStub(uint32_t capabilities)
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceRemoved
util::Signal< NetworkMonitorImpl, shared_ptr< const NetworkInterface > > onInterfaceAdded
NetworkMonitorImpl & getImpl()
void addInterface(shared_ptr< NetworkInterface > netif)
shared_ptr< const NetworkInterface > getNetworkInterface(const std::string &ifname) const final
void removeInterface(const std::string &ifname)