blob: 6ce659555204324818a6eeae61254045fb48e960 [file] [log] [blame]
Alexander Afanasyev3ecec502014-04-16 13:42:44 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014 Regents of the University of California,
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 NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 **/
25
26#ifndef NFD_CORE_FACE_MONITOR_HPP
27#define NFD_CORE_FACE_MONITOR_HPP
28
29#include "common.hpp"
30
31#include <ndn-cpp-dev/management/nfd-face-event-notification.hpp>
32
33namespace ndn {
34class Face;
35struct PendingInterestId;
36}
37
38namespace nfd {
39
40using ndn::nfd::FaceEventNotification;
41
42/**
43 * \brief Helper class to subscribe to face notification events
44 *
45 * \todo Write test cases
46 */
47class FaceMonitor : noncopyable
48{
49public:
50 typedef function<void(const ndn::nfd::FaceEventNotification&)> NotificationCallback;
51 typedef function<void()> TimeoutCallback;
52
53 typedef std::vector<NotificationCallback> NotificationCallbacks;
54 typedef std::vector<TimeoutCallback> TimeoutCallbacks;
55
56 explicit
57 FaceMonitor(ndn::Face& face);
58
59 ~FaceMonitor();
60
61 /** \brief Stops all notifications. This method doesn't remove registered callbacks.
62 */
63 void
64 stopNotifications();
65
66 /** \brief Resumes notifications for added subscribers.
67 */
68 void
69 startNotifications();
70
71 /** \brief Removes all notification subscribers.
72 */
73 void
74 removeAllSubscribers();
75
76 /** \brief Adds a notification subscriber. This method doesn't return on timeouts.
77 */
78 void
79 addSubscriber(const NotificationCallback& notificationCallback);
80
81 /** \brief Adds a notification subscriber.
82 */
83 void
84 addSubscriber(const NotificationCallback& notificationCallback,
85 const TimeoutCallback& timeoutCallback);
86
87private:
88 void
89 onTimeout();
90
91 void
92 onNotification(const Data& data);
93
94private:
95 ndn::Face& m_face;
96 uint64_t m_lastSequence;
97 bool m_isStopped;
98 NotificationCallbacks m_notificationCallbacks;
99 TimeoutCallbacks m_timeoutCallbacks;
100 const ndn::PendingInterestId* m_lastInterestId;
101};
102
103} // namespace nfd
104
105#endif // NFD_CORE_FACE_MONITOR_HPP