blob: dae4941cc8bf00e17bdc8083c31065119bfe1d30 [file] [log] [blame]
Alexander Afanasyeve6c65e22015-01-28 19:56:03 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
Davide Pesavento537dc3a2016-02-18 19:35:26 +01003 * Copyright (c) 2013-2016 Regents of the University of California.
Alexander Afanasyeve6c65e22015-01-28 19:56:03 -08004 *
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_HPP
23#define NDN_UTIL_NETWORK_MONITOR_HPP
24
25#include "signal.hpp"
26
Davide Pesavento537dc3a2016-02-18 19:35:26 +010027// forward declaration
28namespace boost {
29namespace asio {
30class io_service;
31} // namespace asio
32} // namespace boost
Alexander Afanasyeve6c65e22015-01-28 19:56:03 -080033
34namespace ndn {
35namespace util {
36
37/**
38 * @brief Network state change monitor
39 *
40 * When network change is detected, onNetworkStateChanged signal will be fired.
41 * Monitoring is run for the lifetime of the NetworkMonitor instance.
42 *
43 * @note Implementation of this class is platform dependent and not all supported platforms
44 * are supported:
45 * - OS X: CFNotificationCenterAddObserver
Alexander Afanasyev7b3080f2015-01-28 21:21:01 -080046 * - Linux: rtnetlink notifications
Alexander Afanasyeve6c65e22015-01-28 19:56:03 -080047 *
48 * Network state change detection is not guaranteed to be precise and (zero or more)
49 * notifications are expected to be fired for the following events:
50 * - any network interface going up or down
51 * - IPv4 or IPv6 address changes on any of the interfaces
52 */
53class NetworkMonitor : boost::noncopyable
54{
55public:
56 class Error : public std::runtime_error
57 {
58 public:
59 explicit
60 Error(const std::string& what)
61 : std::runtime_error(what)
62 {
63 }
64 };
65
66 /**
67 * @brief Construct instance and start monitoring for network state changes
68 * @param io io_service thread that will dispatch events
69 * @throw Error when network monitoring is not supported or there is an error starting monitoring
70 */
71 explicit
72 NetworkMonitor(boost::asio::io_service& io);
73
74 /**
75 * @brief Terminate network state monitoring
76 */
77 ~NetworkMonitor();
78
79 Signal<NetworkMonitor> onNetworkStateChanged;
80
81private:
82 class Impl;
83 std::unique_ptr<Impl> m_impl;
84};
85
86} // namespace util
87} // namespace autoconfig
88
89#endif // NDN_UTIL_NETWORK_MONITOR_HPP