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;
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;
270 if (m_lastNackSequenceNo == nackSequenceNo) {
276 time::milliseconds delayTime =
279 m_lastNackSequenceNo = nackSequenceNo;
287 uint64_t m_lastSequenceNo;
288 uint64_t m_lastNackSequenceNo;
292 const PendingInterestId* m_lastInterestId;
293 time::milliseconds m_interestLifetime;
299 #endif // NDN_UTIL_NOTIFICATION_SUBSCRIBER_HPP time::milliseconds getInterestLifetime() const
Copyright (c) 2011-2015 Regents of the University of California.
uint64_t toSequenceNumber() const
Interpret as sequence number component using NDN naming conventions.
const Block & getContent() const
Get content Block.
const Component & get(ssize_t i) const
Get the component at the given index.
NotificationSubscriber(Face &face, const Name &prefix, const time::milliseconds &interestLifetime=time::milliseconds(60000))
construct a NotificationSubscriber
const Name & getName() const
Get name of the Data packet.
EventId scheduleEvent(const time::nanoseconds &after, const Event &event)
Schedule a one-time event after the specified delay.
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.
represents a Network Nack
uint32_t generateWord32()
Generate a non-cryptographically-secure random integer in 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
Event that is automatically cancelled upon destruction.
Block blockFromValue() const
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 ...
const Interest & getInterest() const
void removePendingInterest(const PendingInterestId *pendingInterestId)
Cancel previously expressed Interest.
represents an error in TLV encoding or decoding
Error that can be thrown from name::Component.
const Name & getName() const