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