Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [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. |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [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. |
| 20 | */ |
| 21 | |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 22 | #ifndef NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP |
| 23 | #define NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 24 | |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 25 | #include "ndn-cxx-config.hpp" |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 26 | #include "../network-monitor.hpp" |
| 27 | |
Alexander Afanasyev | 0cf887d | 2017-03-26 16:58:59 -0500 | [diff] [blame] | 28 | #ifndef NDN_CXX_HAVE_OSX_FRAMEWORKS |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 29 | #error "This file should not be compiled ..." |
| 30 | #endif |
| 31 | |
Junxiao Shi | 0b1b467 | 2017-07-02 22:02:31 -0700 | [diff] [blame^] | 32 | #include "../../util/cf-releaser-osx.hpp" |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 33 | #include "../../util/scheduler.hpp" |
| 34 | #include "../../util/scheduler-scoped-event-id.hpp" |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 35 | |
| 36 | #include <CoreFoundation/CoreFoundation.h> |
| 37 | #include <SystemConfiguration/SystemConfiguration.h> |
| 38 | |
Alexander Afanasyev | 3b3355c | 2017-03-26 11:57:13 -0500 | [diff] [blame] | 39 | #include <boost/asio/ip/udp.hpp> |
| 40 | |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 41 | namespace ndn { |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 42 | namespace net { |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 43 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 44 | class NetworkMonitorImplOsx : public NetworkMonitorImpl |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 45 | { |
| 46 | public: |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 47 | using Error = NetworkMonitor::Error; |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 48 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 49 | NetworkMonitorImplOsx(boost::asio::io_service& io); |
| 50 | |
| 51 | ~NetworkMonitorImplOsx(); |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 52 | |
Junxiao Shi | f4c1eb3 | 2017-05-30 17:05:10 +0000 | [diff] [blame] | 53 | uint32_t |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 54 | getCapabilities() const final |
Junxiao Shi | f4c1eb3 | 2017-05-30 17:05:10 +0000 | [diff] [blame] | 55 | { |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 56 | return NetworkMonitor::CAP_ENUM | |
| 57 | NetworkMonitor::CAP_IF_ADD_REMOVE | |
| 58 | NetworkMonitor::CAP_STATE_CHANGE | |
| 59 | NetworkMonitor::CAP_ADDR_ADD_REMOVE; |
Junxiao Shi | f4c1eb3 | 2017-05-30 17:05:10 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 62 | shared_ptr<const NetworkInterface> |
| 63 | getNetworkInterface(const std::string& ifname) const final; |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 64 | |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 65 | std::vector<shared_ptr<const NetworkInterface>> |
| 66 | listNetworkInterfaces() const final; |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 67 | |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 68 | static void |
| 69 | afterNotificationCenterEvent(CFNotificationCenterRef center, |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 70 | void* observer, |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 71 | CFStringRef name, |
Davide Pesavento | 2bf35a6 | 2017-04-02 00:41:06 -0400 | [diff] [blame] | 72 | const void* object, |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 73 | CFDictionaryRef userInfo); |
| 74 | |
| 75 | private: |
| 76 | void |
| 77 | scheduleCfLoop(); |
| 78 | |
| 79 | void |
| 80 | pollCfLoop(); |
| 81 | |
Alexander Afanasyev | 3b3355c | 2017-03-26 11:57:13 -0500 | [diff] [blame] | 82 | void |
| 83 | addNewInterface(const std::string& ifName); |
| 84 | |
| 85 | void |
| 86 | enumerateInterfaces(); |
| 87 | |
| 88 | std::set<std::string> |
| 89 | getInterfaceNames(); |
| 90 | |
| 91 | InterfaceState |
| 92 | getInterfaceState(const std::string& ifName); |
| 93 | |
| 94 | void |
| 95 | updateInterfaceInfo(NetworkInterface& netif); |
| 96 | |
| 97 | size_t |
| 98 | getInterfaceMtu(const std::string& ifName); |
| 99 | |
| 100 | static void |
| 101 | onConfigChanged(SCDynamicStoreRef store, CFArrayRef changedKeys, void* context); |
| 102 | |
| 103 | void |
| 104 | onConfigChanged(CFArrayRef changedKeys); |
| 105 | |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 106 | private: |
Junxiao Shi | 2dc416d | 2017-07-03 04:46:16 +0000 | [diff] [blame] | 107 | std::map<std::string, shared_ptr<NetworkInterface>> m_interfaces; ///< ifname => interface |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 108 | |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 109 | util::Scheduler m_scheduler; |
| 110 | util::scheduler::ScopedEventId m_cfLoopEvent; |
Alexander Afanasyev | 3b3355c | 2017-03-26 11:57:13 -0500 | [diff] [blame] | 111 | |
| 112 | SCDynamicStoreContext m_context; |
Junxiao Shi | 0b1b467 | 2017-07-02 22:02:31 -0700 | [diff] [blame^] | 113 | util::CFReleaser<SCDynamicStoreRef> m_scStore; |
| 114 | util::CFReleaser<CFRunLoopSourceRef> m_loopSource; |
Alexander Afanasyev | 3b3355c | 2017-03-26 11:57:13 -0500 | [diff] [blame] | 115 | |
| 116 | boost::asio::ip::udp::socket m_nullUdpSocket; |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 117 | }; |
| 118 | |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 119 | } // namespace net |
Davide Pesavento | 9a8bae5 | 2016-02-24 20:33:08 +0100 | [diff] [blame] | 120 | } // namespace ndn |
| 121 | |
Junxiao Shi | 2546794 | 2017-06-30 02:53:14 +0000 | [diff] [blame] | 122 | #endif // NDN_NET_NETWORK_MONITOR_IMPL_OSX_HPP |