Alexander Afanasyev | e6c65e2 | 2015-01-28 19:56:03 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /** |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2017 Regents of the University of California. |
Alexander Afanasyev | e6c65e2 | 2015-01-28 19:56:03 -0800 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 6 | * |
| 7 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 8 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 9 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 13 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 14 | * |
| 15 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 16 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 17 | * <http://www.gnu.org/licenses/>. |
| 18 | * |
| 19 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 20 | * |
| 21 | * @author Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 22 | * @author Davide Pesavento <davide.pesavento@lip6.fr> |
Alexander Afanasyev | e6c65e2 | 2015-01-28 19:56:03 -0800 | [diff] [blame] | 23 | */ |
| 24 | |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 25 | #include "network-monitor.hpp" |
Alexander Afanasyev | e6c65e2 | 2015-01-28 19:56:03 -0800 | [diff] [blame] | 26 | #include "ndn-cxx-config.hpp" |
| 27 | |
Alexander Afanasyev | 0cf887d | 2017-03-26 16:58:59 -0500 | [diff] [blame] | 28 | #if defined(NDN_CXX_HAVE_OSX_FRAMEWORKS) |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 29 | #include "detail/network-monitor-impl-osx.hpp" |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 30 | #define NETWORK_MONITOR_IMPL_TYPE NetworkMonitorImplOsx |
Alexander Afanasyev | 7b3080f | 2015-01-28 21:21:01 -0800 | [diff] [blame] | 31 | #elif defined(NDN_CXX_HAVE_RTNETLINK) |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 32 | #include "detail/network-monitor-impl-rtnl.hpp" |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 33 | #define NETWORK_MONITOR_IMPL_TYPE NetworkMonitorImplRtnl |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 34 | #else |
Junxiao Shi | f4c1eb3 | 2017-05-30 17:05:10 +0000 | [diff] [blame] | 35 | #include "detail/network-monitor-impl-noop.hpp" |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 36 | #define NETWORK_MONITOR_IMPL_TYPE NetworkMonitorImplNoop |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 37 | #endif |
| 38 | |
| 39 | namespace ndn { |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 40 | namespace net { |
Alexander Afanasyev | 7b3080f | 2015-01-28 21:21:01 -0800 | [diff] [blame] | 41 | |
| 42 | NetworkMonitor::NetworkMonitor(boost::asio::io_service& io) |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 43 | : NetworkMonitor(make_unique<NETWORK_MONITOR_IMPL_TYPE>(io)) |
Alexander Afanasyev | 7b3080f | 2015-01-28 21:21:01 -0800 | [diff] [blame] | 44 | { |
Alexander Afanasyev | e6c65e2 | 2015-01-28 19:56:03 -0800 | [diff] [blame] | 45 | } |
| 46 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 47 | NetworkMonitor::NetworkMonitor(unique_ptr<NetworkMonitorImpl> impl) |
| 48 | : m_impl(std::move(impl)) |
| 49 | , onEnumerationCompleted(m_impl->onEnumerationCompleted) |
| 50 | , onInterfaceAdded(m_impl->onInterfaceAdded) |
| 51 | , onInterfaceRemoved(m_impl->onInterfaceRemoved) |
| 52 | , onNetworkStateChanged(m_impl->onNetworkStateChanged) |
| 53 | { |
| 54 | } |
Alexander Afanasyev | e6c65e2 | 2015-01-28 19:56:03 -0800 | [diff] [blame] | 55 | |
Junxiao Shi | f4c1eb3 | 2017-05-30 17:05:10 +0000 | [diff] [blame] | 56 | uint32_t |
| 57 | NetworkMonitor::getCapabilities() const |
| 58 | { |
| 59 | return m_impl->getCapabilities(); |
| 60 | } |
| 61 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 62 | shared_ptr<const NetworkInterface> |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 63 | NetworkMonitor::getNetworkInterface(const std::string& ifname) const |
| 64 | { |
| 65 | return m_impl->getNetworkInterface(ifname); |
| 66 | } |
| 67 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 68 | std::vector<shared_ptr<const NetworkInterface>> |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 69 | NetworkMonitor::listNetworkInterfaces() const |
| 70 | { |
| 71 | return m_impl->listNetworkInterfaces(); |
| 72 | } |
| 73 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 74 | shared_ptr<NetworkInterface> |
| 75 | NetworkMonitorImpl::makeNetworkInterface() |
| 76 | { |
| 77 | // cannot use make_shared because NetworkInterface constructor is private |
| 78 | return shared_ptr<NetworkInterface>(new NetworkInterface); |
| 79 | } |
| 80 | |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 81 | } // namespace net |
Alexander Afanasyev | e6c65e2 | 2015-01-28 19:56:03 -0800 | [diff] [blame] | 82 | } // namespace ndn |