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