Yanbiao Li | ac8b4ca | 2017-07-10 02:27:50 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
| 2 | /* |
Davide Pesavento | 74daf74 | 2018-11-23 18:14:13 -0500 | [diff] [blame] | 3 | * Copyright (c) 2013-2018 Regents of the University of California, |
Yanbiao Li | ac8b4ca | 2017-07-10 02:27:50 -0700 | [diff] [blame] | 4 | * Arizona Board of Regents, |
| 5 | * Colorado State University, |
| 6 | * University Pierre & Marie Curie, Sorbonne University, |
| 7 | * Washington University in St. Louis, |
| 8 | * Beijing Institute of Technology, |
| 9 | * The University of Memphis. |
| 10 | * |
| 11 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 12 | * |
| 13 | * ndn-cxx library is free software: you can redistribute it and/or modify it under the |
| 14 | * terms of the GNU Lesser General Public License as published by the Free Software |
| 15 | * Foundation, either version 3 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY |
| 18 | * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 19 | * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. |
| 20 | * |
| 21 | * You should have received copies of the GNU General Public License and GNU Lesser |
| 22 | * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see |
| 23 | * <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 26 | */ |
| 27 | |
Davide Pesavento | 7e78064 | 2018-11-24 15:51:34 -0500 | [diff] [blame] | 28 | #include "tests/unit/net/collect-netifs.hpp" |
| 29 | #include "ndn-cxx/net/network-monitor.hpp" |
Yanbiao Li | ac8b4ca | 2017-07-10 02:27:50 -0700 | [diff] [blame] | 30 | |
| 31 | #include <boost/asio/io_service.hpp> |
| 32 | |
| 33 | namespace ndn { |
| 34 | namespace net { |
| 35 | namespace tests { |
| 36 | |
| 37 | std::vector<shared_ptr<const NetworkInterface>> |
| 38 | collectNetworkInterfaces(bool allowCached) |
| 39 | { |
Davide Pesavento | 22f7bc3 | 2018-12-19 01:46:08 -0500 | [diff] [blame] | 40 | static optional<std::vector<shared_ptr<const NetworkInterface>>> cached; |
Yanbiao Li | ac8b4ca | 2017-07-10 02:27:50 -0700 | [diff] [blame] | 41 | |
Davide Pesavento | 22f7bc3 | 2018-12-19 01:46:08 -0500 | [diff] [blame] | 42 | if (!allowCached || !cached) { |
Yanbiao Li | ac8b4ca | 2017-07-10 02:27:50 -0700 | [diff] [blame] | 43 | boost::asio::io_service io; |
| 44 | NetworkMonitor netmon(io); |
Davide Pesavento | 22f7bc3 | 2018-12-19 01:46:08 -0500 | [diff] [blame] | 45 | |
| 46 | if (netmon.getCapabilities() & NetworkMonitor::CAP_ENUM) { |
| 47 | netmon.onEnumerationCompleted.connect([&io] { io.stop(); }); |
| 48 | io.run(); |
| 49 | io.reset(); |
Yanbiao Li | ac8b4ca | 2017-07-10 02:27:50 -0700 | [diff] [blame] | 50 | } |
Yanbiao Li | ac8b4ca | 2017-07-10 02:27:50 -0700 | [diff] [blame] | 51 | cached = netmon.listNetworkInterfaces(); |
| 52 | } |
| 53 | |
Davide Pesavento | 22f7bc3 | 2018-12-19 01:46:08 -0500 | [diff] [blame] | 54 | return *cached; |
Yanbiao Li | ac8b4ca | 2017-07-10 02:27:50 -0700 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | } // namespace tests |
| 58 | } // namespace net |
| 59 | } // namespace ndn |