util: NetworkMonitor helper to detect network state changes

This commit includes only OS X implementation using CoreFoundation framework

Change-Id: I8d5488ec5780e2a33bb20595391208a76b9e69dd
Refs: #2443
diff --git a/src/util/network-monitor.hpp b/src/util/network-monitor.hpp
new file mode 100644
index 0000000..9c7dc31
--- /dev/null
+++ b/src/util/network-monitor.hpp
@@ -0,0 +1,84 @@
+/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
+/**
+ * Copyright (c) 2013-2015 Regents of the University of California.
+ *
+ * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
+ *
+ * ndn-cxx library is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ *
+ * You should have received copies of the GNU General Public License and GNU Lesser
+ * General Public License along with ndn-cxx, e.g., in COPYING.md file.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ *
+ * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
+ */
+
+#ifndef NDN_UTIL_NETWORK_MONITOR_HPP
+#define NDN_UTIL_NETWORK_MONITOR_HPP
+
+#include "signal.hpp"
+
+#include <boost/asio/io_service.hpp>
+
+namespace ndn {
+namespace util {
+
+/**
+ * @brief Network state change monitor
+ *
+ * When network change is detected, onNetworkStateChanged signal will be fired.
+ * Monitoring is run for the lifetime of the NetworkMonitor instance.
+ *
+ * @note Implementation of this class is platform dependent and not all supported platforms
+ *       are supported:
+ *       - OS X: CFNotificationCenterAddObserver
+ *       - Linux: NetworkManager notifications through DBus IPC
+ *
+ * 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
+ */
+class NetworkMonitor : boost::noncopyable
+{
+public:
+  class Error : public std::runtime_error
+  {
+  public:
+    explicit
+    Error(const std::string& what)
+      : std::runtime_error(what)
+    {
+    }
+  };
+
+  /**
+   * @brief Construct instance 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();
+
+  Signal<NetworkMonitor> onNetworkStateChanged;
+
+private:
+  class Impl;
+  std::unique_ptr<Impl> m_impl;
+};
+
+} // namespace util
+} // namespace autoconfig
+
+#endif // NDN_UTIL_NETWORK_MONITOR_HPP