48 #ifndef NDN_UTIL_NOTIFICATION_SUBSCRIBER_HPP
49 #define NDN_UTIL_NOTIFICATION_SUBSCRIBER_HPP
51 #include "../face.hpp"
58 #include <boost/concept_check.hpp>
67 template<
typename Notification>
71 BOOST_CONCEPT_ASSERT((boost::DefaultConstructible<Notification>));
79 const time::milliseconds& interestLifetime = time::milliseconds(60000))
83 , m_lastSequenceNo(
std::numeric_limits<uint64_t>::max())
84 , m_lastNackSequenceNo(
std::numeric_limits<uint64_t>::max())
86 , m_scheduler(face.getIoService())
87 , m_nackEvent(m_scheduler)
88 , m_interestLifetime(interestLifetime)
104 return m_interestLifetime;
124 this->sendInitialInterest();
136 if (m_lastInterestId != 0)
138 m_lastInterestId = 0;
161 sendInitialInterest()
163 if (this->shouldStop())
166 shared_ptr<Interest> interest = make_shared<Interest>(m_prefix);
167 interest->setMustBeFresh(
true);
168 interest->setChildSelector(1);
180 if (this->shouldStop())
183 BOOST_ASSERT(m_lastSequenceNo !=
184 std::numeric_limits<uint64_t>::max());
186 Name nextName = m_prefix;
189 shared_ptr<Interest> interest = make_shared<Interest>(nextName);
206 if (onNotification.isEmpty() && onNack.isEmpty()) {
214 afterReceiveData(
const Data& data)
216 if (this->shouldStop())
219 Notification notification;
221 m_lastSequenceNo = data.getName().get(-1).toSequenceNumber();
222 notification.wireDecode(data.getContent().blockFromValue());
224 catch (tlv::Error&) {
226 this->sendInitialInterest();
232 this->sendNextInterest();
236 afterReceiveNack(
const lp::Nack& nack)
238 if (this->shouldStop())
243 time::milliseconds delay = exponentialBackoff(nack);
244 m_nackEvent = m_scheduler.
scheduleEvent(delay, [
this] {this->sendInitialInterest();});
250 if (this->shouldStop())
255 this->sendInitialInterest();
261 uint64_t nackSequenceNo;
264 nackSequenceNo = nack.getInterest().getName().get(-1).toSequenceNumber();
266 catch (name::Component::Error&) {
270 if (m_lastNackSequenceNo == nackSequenceNo) {
276 time::milliseconds delayTime =
279 m_lastNackSequenceNo = nackSequenceNo;
287 uint64_t m_lastSequenceNo;
288 uint64_t m_lastNackSequenceNo;
290 util::scheduler::Scheduler m_scheduler;
291 util::scheduler::ScopedEventId m_nackEvent;
292 const PendingInterestId* m_lastInterestId;
293 time::milliseconds m_interestLifetime;
299 #endif // NDN_UTIL_NOTIFICATION_SUBSCRIBER_HPP
Copyright (c) 2013-2016 Regents of the University of California.
NotificationSubscriber(Face &face, const Name &prefix, const time::milliseconds &interestLifetime=time::milliseconds(60000))
construct a NotificationSubscriber
time::milliseconds getInterestLifetime() const
void start()
start or resume receiving notifications
provides a lightweight signal / event system
signal::Signal< NotificationSubscriber > onTimeout
fires when no Notification is received within .getInterestLifetime period
signal::Signal< NotificationSubscriber, Notification > onNotification
fires when a Notification is received
signal::Signal< NotificationSubscriber, lp::Nack > onNack
fires when a NACK is received
virtual ~NotificationSubscriber()
Name & appendSequenceNumber(uint64_t seqNo)
Append sequence number using NDN naming conventions.
uint32_t generateWord32()
Generate a cryptographically non-secure random integer from the range [0, 2^32)
signal::Signal< NotificationSubscriber, Data > onDecodeError
fires when a Data packet in the Notification Stream cannot be decoded as Notification ...
Provide a communication channel with local or remote NDN forwarder.
provides a subscriber of Notification Stream
Name abstraction to represent an absolute name.
void stop()
stop receiving notifications
EventId scheduleEvent(const time::nanoseconds &after, const EventCallback &callback)
Schedule a one-time event after the specified delay.
const PendingInterestId * expressInterest(const Interest &interest, const DataCallback &afterSatisfied, const NackCallback &afterNacked, const TimeoutCallback &afterTimeout)
Express Interest.
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
void removePendingInterest(const PendingInterestId *pendingInterestId)
Cancel previously expressed Interest.