| /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| /** |
| * Copyright (c) 2013-2017 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. |
| * |
| * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| * @author Davide Pesavento <davide.pesavento@lip6.fr> |
| */ |
| |
| #ifndef NDN_NET_NETWORK_MONITOR_HPP |
| #define NDN_NET_NETWORK_MONITOR_HPP |
| |
| #include "../util/signal.hpp" |
| |
| #include <vector> |
| |
| // forward declaration |
| namespace boost { |
| namespace asio { |
| class io_service; |
| } // namespace asio |
| } // namespace boost |
| |
| namespace ndn { |
| namespace net { |
| |
| class NetworkInterface; |
| |
| /** |
| * @brief Network interfaces monitor |
| * |
| * 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: SystemConfiguration and CFNotificationCenterAddObserver notifications (no |
| * notification on MTU change) |
| * - Linux: rtnetlink notifications |
| */ |
| class NetworkMonitor : noncopyable |
| { |
| public: |
| class Error : public std::runtime_error |
| { |
| public: |
| explicit |
| Error(const std::string& what) |
| : std::runtime_error(what) |
| { |
| } |
| }; |
| |
| class Impl; |
| |
| /** |
| * @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); |
| |
| ~NetworkMonitor(); |
| |
| enum Capability : uint32_t { |
| /// NetworkMonitor is not supported and is a no-op |
| CAP_NONE = 0, |
| /// listNetworkInterfaces() and getNetworkInterface() are supported |
| CAP_ENUM = 1 << 0, |
| /// NetworkMonitor onInterfaceAdded and onInterfaceRemoved signals are supported |
| CAP_IF_ADD_REMOVE = 1 << 1, |
| /// NetworkInterface onStateChanged signal is supported |
| CAP_STATE_CHANGE = 1 << 2, |
| /// NetworkInterface onMtuChanged signal is supported |
| CAP_MTU_CHANGE = 1 << 3, |
| /// NetworkInterface onAddressAdded and onAddressRemoved signals are supported |
| CAP_ADDR_ADD_REMOVE = 1 << 4 |
| }; |
| |
| /** \return bitwise OR'ed \p Capability supported on current platform |
| */ |
| uint32_t |
| getCapabilities() const; |
| |
| 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 |
| */ |
| util::Signal<NetworkMonitor> onEnumerationCompleted; |
| |
| /** @brief Fires when a new interface is added |
| */ |
| util::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 |
| */ |
| util::Signal<NetworkMonitor, shared_ptr<NetworkInterface>> onInterfaceRemoved; |
| |
| // only for backward compatibility |
| util::Signal<NetworkMonitor> onNetworkStateChanged; |
| |
| private: |
| const unique_ptr<Impl> m_impl; |
| }; |
| |
| } // namespace net |
| } // namespace ndn |
| |
| #endif // NDN_NET_NETWORK_MONITOR_HPP |