27 #include <unordered_map> 29 #include <boost/range/adaptor/map.hpp> 30 #include <boost/range/algorithm/copy.hpp> 40 : m_capabilities(capabilities)
47 return m_capabilities;
50 shared_ptr<const NetworkInterface>
53 auto i = m_interfaces.find(ifname);
54 return i == m_interfaces.end() ? nullptr : i->second;
57 std::vector<shared_ptr<const NetworkInterface>>
60 std::vector<shared_ptr<const NetworkInterface>> v;
61 boost::copy(m_interfaces | boost::adaptors::map_values, std::back_inserter(v));
71 BOOST_ASSERT(netif !=
nullptr);
72 bool isNew = m_interfaces.emplace(netif->getName(), netif).second;
74 BOOST_THROW_EXCEPTION(std::invalid_argument(
"duplicate 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);
98 uint32_t m_capabilities;
99 std::unordered_map<std::string, shared_ptr<NetworkInterface>> m_interfaces;
108 NetworkMonitorStub::getImpl()
113 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
#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)