NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.0: NDN, CCN, CCNx, content centric networks
API Documentation
pending-interest.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_DETAIL_PENDING_INTEREST_HPP
23 #define NDN_DETAIL_PENDING_INTEREST_HPP
24 
25 #include "../common.hpp"
26 #include "../interest.hpp"
27 #include "../data.hpp"
28 #include "../util/time.hpp"
29 #include "../util/scheduler.hpp"
30 #include "../util/scheduler-scoped-event-id.hpp"
31 #include "../lp/nack.hpp"
32 
33 namespace ndn {
34 
35 class PendingInterest : noncopyable
36 {
37 public:
48  PendingInterest(shared_ptr<const Interest> interest,
49  const DataCallback& dataCallback,
50  const NackCallback& nackCallback,
51  const TimeoutCallback& timeoutCallback,
52  Scheduler& scheduler)
53  : m_interest(interest)
54  , m_dataCallback(dataCallback)
55  , m_nackCallback(nackCallback)
56  , m_timeoutCallback(timeoutCallback)
57  , m_timeoutEvent(scheduler)
58  {
59  m_timeoutEvent =
60  scheduler.scheduleEvent(m_interest->getInterestLifetime() > time::milliseconds::zero() ?
61  m_interest->getInterestLifetime() :
63  bind(&PendingInterest::invokeTimeoutCallback, this));
64  }
65 
69  shared_ptr<const Interest>
70  getInterest() const
71  {
72  return m_interest;
73  }
74 
79  void
80  invokeDataCallback(const Data& data)
81  {
82  m_dataCallback(*m_interest, data);
83  }
84 
89  void
91  {
92  m_nackCallback(*m_interest, nack);
93  }
94 
98  void
99  setDeleter(const std::function<void()>& deleter)
100  {
101  m_deleter = deleter;
102  }
103 
104 private:
109  void
110  invokeTimeoutCallback()
111  {
112  if (m_timeoutCallback) {
113  m_timeoutCallback(*m_interest);
114  }
115 
116  BOOST_ASSERT(m_deleter);
117  m_deleter();
118  }
119 
120 private:
121  shared_ptr<const Interest> m_interest;
122  DataCallback m_dataCallback;
123  NackCallback m_nackCallback;
124  TimeoutCallback m_timeoutCallback;
125  util::scheduler::ScopedEventId m_timeoutEvent;
126  std::function<void()> m_deleter;
127 };
128 
129 
130 class PendingInterestId;
131 
136 {
137 public:
138  explicit
139  MatchPendingInterestId(const PendingInterestId* pendingInterestId)
140  : m_id(pendingInterestId)
141  {
142  }
143 
144  bool
145  operator()(const shared_ptr<const PendingInterest>& pendingInterest) const
146  {
147  return (reinterpret_cast<const PendingInterestId*>(
148  pendingInterest->getInterest().get()) == m_id);
149  }
150 private:
151  const PendingInterestId* m_id;
152 };
153 
154 
155 } // namespace ndn
156 
157 #endif // NDN_DETAIL_PENDING_INTEREST_HPP
Copyright (c) 2011-2015 Regents of the University of California.
shared_ptr< const Interest > getInterest() const
void setDeleter(const std::function< void()> &deleter)
Set cleanup function to be called after interest times out.
EventId scheduleEvent(const time::nanoseconds &after, const Event &event)
Schedule one time event after the specified delay.
Definition: scheduler.cpp:85
Functor to match pending interests against PendingInterestId.
represents a Network Nack
Definition: nack.hpp:40
bool operator()(const shared_ptr< const PendingInterest > &pendingInterest) const
void invokeNackCallback(const lp::Nack &nack)
invokes the NackCallback
PendingInterest(shared_ptr< const Interest > interest, const DataCallback &dataCallback, const NackCallback &nackCallback, const TimeoutCallback &timeoutCallback, Scheduler &scheduler)
Create a new PitEntry and set the timeout based on the current time and the Interest lifetime...
MatchPendingInterestId(const PendingInterestId *pendingInterestId)
Event that is automatically cancelled upon destruction.
const time::milliseconds DEFAULT_INTEREST_LIFETIME
default value for InterestLifetime
Definition: interest.hpp:41
function< void(const Interest &)> TimeoutCallback
Callback called when expressed Interest times out.
Definition: face.hpp:77
function< void(const Interest &, const lp::Nack &)> NackCallback
Callback called when Nack is sent in response to expressed Interest.
Definition: face.hpp:72
represents a Data packet
Definition: data.hpp:39
function< void(const Interest &, const Data &)> DataCallback
Callback called when expressed Interest gets satisfied with a Data packet.
Definition: face.hpp:67
void invokeDataCallback(const Data &data)
invokes the DataCallback