All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pending-interest.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
7 #ifndef NDN_DETAIL_PENDING_INTEREST_HPP
8 #define NDN_DETAIL_PENDING_INTEREST_HPP
9 
10 #include "../common.hpp"
11 #include "../interest.hpp"
12 #include "../data.hpp"
13 #include "../util/time.hpp"
14 
15 namespace ndn {
16 
18 {
19 public:
20  typedef function<void(const Interest&, Data&)> OnData;
21  typedef function<void(const Interest&)> OnTimeout;
22 
32  PendingInterest(const shared_ptr<const Interest>& interest, const OnData& onData,
33  const OnTimeout& onTimeout)
34  : interest_(interest)
35  , onData_(onData)
36  , m_onTimeout(onTimeout)
37  {
38  if (interest_->getInterestLifetime() >= time::milliseconds::zero())
39  m_timeout = time::steady_clock::now() + interest_->getInterestLifetime();
40  else
41  m_timeout = time::steady_clock::now() + DEFAULT_INTEREST_LIFETIME;
42  }
43 
44  const shared_ptr<const Interest>&
46  {
47  return interest_;
48  }
49 
50  const OnData&
52  {
53  return onData_;
54  }
55 
60  bool
62  {
63  return now >= m_timeout;
64  }
65 
69  void
71  {
72  if (m_onTimeout) {
73  m_onTimeout(*interest_);
74  }
75  }
76 
77 private:
78  shared_ptr<const Interest> interest_;
79  const OnData onData_;
80  const OnTimeout m_onTimeout;
82 };
83 
84 
85 struct PendingInterestId;
86 
91 {
92  MatchPendingInterestId(const PendingInterestId* pendingInterestId)
93  : m_id(pendingInterestId)
94  {
95  }
96 
97  bool
98  operator()(const shared_ptr<const PendingInterest>& pendingInterest) const
99  {
100  return (reinterpret_cast<const PendingInterestId*>(pendingInterest.get()) == m_id);
101  }
102 private:
103  const PendingInterestId* m_id;
104 };
105 
106 
107 } // namespace ndn
108 
109 #endif // NDN_DETAIL_PENDING_INTEREST_HPP
time_point TimePoint
Definition: time.hpp:84
bool operator()(const shared_ptr< const PendingInterest > &pendingInterest) const
MatchPendingInterestId(const PendingInterestId *pendingInterestId)
const shared_ptr< const Interest > & getInterest()
function< void(const Interest &)> OnTimeout
An OnTimeout function object is used to pass a callback to expressInterest.
Definition: face.hpp:37
function< void(const Interest &)> OnTimeout
bool isTimedOut(const time::steady_clock::TimePoint &now)
Check if this interest is timed out.
const time::seconds DEFAULT_INTEREST_LIFETIME
Definition: interest.hpp:19
PendingInterest(const shared_ptr< const Interest > &interest, const OnData &onData, const OnTimeout &onTimeout)
Create a new PitEntry and set the timeout based on the current time and the interest lifetime...
function< void(const Interest &, Data &)> OnData
An OnData function object is used to pass a callback to expressInterest.
Definition: face.hpp:27
Functor to match pending interests against PendingInterestId.
function< void(const Interest &, Data &)> OnData
void callTimeout()
Call m_onTimeout (if defined).
const OnData & getOnData()