util: NetworkMonitor: fine-grained signals on interface/address changes
Change-Id: I60d4cc6d673b920ba81d57502977f0340be0da48
Refs: #3353
diff --git a/src/util/network-monitor.hpp b/src/util/network-monitor.hpp
index dae4941..b48d5e9 100644
--- a/src/util/network-monitor.hpp
+++ b/src/util/network-monitor.hpp
@@ -1,6 +1,6 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/**
- * Copyright (c) 2013-2016 Regents of the University of California.
+ * Copyright (c) 2013-2017 Regents of the University of California.
*
* This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
*
@@ -17,6 +17,9 @@
* <http://www.gnu.org/licenses/>.
*
* See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ *
+ * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu>
+ * @author Davide Pesavento <davide.pesavento@lip6.fr>
*/
#ifndef NDN_UTIL_NETWORK_MONITOR_HPP
@@ -24,6 +27,8 @@
#include "signal.hpp"
+#include <vector>
+
// forward declaration
namespace boost {
namespace asio {
@@ -34,23 +39,23 @@
namespace ndn {
namespace util {
+class NetworkInterface;
+
/**
- * @brief Network state change monitor
+ * @brief Network interfaces monitor
*
- * When network change is detected, onNetworkStateChanged signal will be fired.
- * Monitoring is run for the lifetime of the NetworkMonitor instance.
+ * Maintains an up-to-date view of every system network interface and notifies when an interface
+ * is added or removed.
*
* @note Implementation of this class is platform dependent and not all supported platforms
* are supported:
- * - OS X: CFNotificationCenterAddObserver
+ * - OS X: CFNotificationCenterAddObserver (incomplete)
* - Linux: rtnetlink notifications
*
- * Network state change detection is not guaranteed to be precise and (zero or more)
- * notifications are expected to be fired for the following events:
- * - any network interface going up or down
- * - IPv4 or IPv6 address changes on any of the interfaces
+ * @todo macOS implementation needs to be updated to emit the new signals and keep track of
+ * interfaces (links) and addresses
*/
-class NetworkMonitor : boost::noncopyable
+class NetworkMonitor : noncopyable
{
public:
class Error : public std::runtime_error
@@ -63,27 +68,50 @@
}
};
+ class Impl;
+
/**
- * @brief Construct instance and start monitoring for network state changes
+ * @brief Construct instance, request enumeration of all network interfaces, and start
+ * monitoring for network state changes
+ *
* @param io io_service thread that will dispatch events
* @throw Error when network monitoring is not supported or there is an error starting monitoring
*/
explicit
NetworkMonitor(boost::asio::io_service& io);
- /**
- * @brief Terminate network state monitoring
- */
~NetworkMonitor();
+ shared_ptr<NetworkInterface>
+ getNetworkInterface(const std::string& ifname) const;
+
+ std::vector<shared_ptr<NetworkInterface>>
+ listNetworkInterfaces() const;
+
+public: // signals
+ /** @brief Fires when network interfaces enumeration is complete
+ */
+ Signal<NetworkMonitor> onEnumerationCompleted;
+
+ /** @brief Fires when a new interface is added
+ */
+ Signal<NetworkMonitor, shared_ptr<NetworkInterface>> onInterfaceAdded;
+
+ /**
+ * @brief Fires when an interface is removed
+ * @note The NetworkInterface object is no longer present in the network
+ * interfaces map when the signal is emitted
+ */
+ Signal<NetworkMonitor, shared_ptr<NetworkInterface>> onInterfaceRemoved;
+
+ // only for backward compatibility
Signal<NetworkMonitor> onNetworkStateChanged;
private:
- class Impl;
std::unique_ptr<Impl> m_impl;
};
} // namespace util
-} // namespace autoconfig
+} // namespace ndn
#endif // NDN_UTIL_NETWORK_MONITOR_HPP