blob: e0eeaa6089c20df177f5288d515797834ba391d6 [file] [log] [blame]
Obaid81fb2d22014-04-07 18:10:35 -05001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
3 * Copyright (C) 2014 Regents of the University of California.
4 * See COPYING for copyright and distribution information.
5 */
6#ifndef FACE_MONITOR_HPP
7#define FACE_MONITOR_HPP
8
9#include "common.hpp"
10#include <ndn-cpp-dev/management/nfd-face-event-notification.hpp>
11#include <ndn-cpp-dev/management/nrd-controller.hpp>
12
13namespace ndn {
14
15class FaceMonitor
16{
17public:
18 typedef function<void(const nfd::FaceEventNotification&)> NotificationCallback;
19 typedef function<void()> TimeoutCallback;
20
21 typedef std::vector<NotificationCallback> NotificationCallbacks;
22 typedef std::vector<TimeoutCallback> TimeoutCallbacks;
23
24 explicit
25 FaceMonitor(Face& face);
26
27 ~FaceMonitor();
28
29 /** \brief Stops all notifications. This method doesn't remove registered callbacks.
30 */
31 void
32 stopNotifications();
33
34 /** \brief Resumes notifications for added subscribers.
35 */
36 void
37 startNotifications();
38
39 /** \brief Removes all notification subscribers.
40 */
41 void
42 removeAllSubscribers();
43
44 /** \brief Adds a notification subscriber. This method doesn't return on timeouts.
45 */
46 void
47 addSubscriber(const NotificationCallback& notificationCallback);
48
49 /** \brief Adds a notification subscriber.
50 */
51 void
52 addSubscriber(const NotificationCallback& notificationCallback,
53 const TimeoutCallback& timeoutCallback);
54
55private:
56 void
57 onTimeout();
58
59 void
60 onNotification(const Data& data);
61
62private:
63 Face& m_face;
64 uint64_t m_lastSequence;
65 bool m_isStopped;
66 NotificationCallbacks m_notificationCallbacks;
67 TimeoutCallbacks m_timeoutCallbacks;
68 const PendingInterestId* m_lastInterestId;
69};
70
71}//namespace ndn
72#endif //FACE_MONITOR_HPP