27 #include <unordered_map>
29 #include <boost/range/adaptor/map.hpp>
30 #include <boost/range/algorithm/copy.hpp>
34 class NetworkMonitorImplStub final :
public NetworkMonitorImpl
38 NetworkMonitorImplStub(uint32_t capabilities)
39 : m_capabilities(capabilities)
44 getCapabilities() const final
46 return m_capabilities;
49 shared_ptr<const NetworkInterface>
50 getNetworkInterface(
const std::string& ifname)
const final
52 auto i = m_interfaces.find(ifname);
53 return i == m_interfaces.end() ? nullptr : i->second;
56 std::vector<shared_ptr<const NetworkInterface>>
57 listNetworkInterfaces() const final
59 std::vector<shared_ptr<const NetworkInterface>> v;
60 boost::copy(m_interfaces | boost::adaptors::map_values, std::back_inserter(v));
68 addInterface(shared_ptr<NetworkInterface> netif)
70 BOOST_ASSERT(netif !=
nullptr);
71 bool isNew = m_interfaces.try_emplace(netif->getName(), netif).second;
73 NDN_THROW(std::invalid_argument(
"duplicate ifname"));
79 removeInterface(
const std::string& ifname)
81 auto i = m_interfaces.find(ifname);
82 if (i == m_interfaces.end()) {
85 shared_ptr<NetworkInterface> netif = i->second;
86 m_interfaces.erase(i);
91 emitEnumerationCompleted()
97 uint32_t m_capabilities;
98 std::unordered_map<std::string, shared_ptr<NetworkInterface>> m_interfaces;
102 :
NetworkMonitor(make_unique<NetworkMonitorImplStub>(capabilities))
106 NetworkMonitorImplStub&
107 NetworkMonitorStub::getImpl()
112 shared_ptr<NetworkInterface>
115 return NetworkMonitorImplStub::makeNetworkInterface();
121 this->getImpl().addInterface(std::move(netif));
127 this->getImpl().removeInterface(ifname);
133 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)