pending-interest-table.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_PENDING_INTEREST_TABLE_HPP
23 #define NDN_PENDING_INTEREST_TABLE_HPP
24 
25 #include <ndn-cpp/face.hpp>
26 
27 namespace ndn {
28 
34 public:
39  class Entry {
40  public:
45  Entry
46  (uint64_t pendingInterestId,
47  const ptr_lib::shared_ptr<const Interest>& interest, const OnData& onData,
48  const OnTimeout& onTimeout, const OnNetworkNack& onNetworkNack)
49  : pendingInterestId_(pendingInterestId), interest_(interest), onData_(onData),
50  onTimeout_(onTimeout), onNetworkNack_(onNetworkNack), isRemoved_(false)
51  {
52  }
53 
58  uint64_t
59  getPendingInterestId() { return pendingInterestId_; }
60 
66  const ptr_lib::shared_ptr<const Interest>&
67  getInterest() { return interest_; }
68 
73  const OnData&
74  getOnData() { return onData_; }
75 
80  const OnNetworkNack&
81  getOnNetworkNack() { return onNetworkNack_; }
82 
86  void
87  setIsRemoved() { isRemoved_ = true; }
88 
93  bool
94  getIsRemoved() { return isRemoved_; }
95 
100  void
101  callTimeout();
102 
103  private:
104  ptr_lib::shared_ptr<const Interest> interest_;
105  uint64_t pendingInterestId_;
106  const OnData onData_;
107  const OnTimeout onTimeout_;
108  const OnNetworkNack onNetworkNack_;
109  bool isRemoved_;
110  };
111 
128  ptr_lib::shared_ptr<Entry>
129  add(uint64_t pendingInterestId,
130  const ptr_lib::shared_ptr<const Interest>& interestCopy,
131  const OnData& onData, const OnTimeout& onTimeout,
132  const OnNetworkNack& onNetworkNack);
133 
142  void
144  (const Name& name, std::vector<ptr_lib::shared_ptr<Entry> > &entries);
145 
159  void
161  (const Interest& interest, std::vector<ptr_lib::shared_ptr<Entry> > &entries);
162 
171  void
172  removePendingInterest(uint64_t pendingInterestId);
173 
180  bool
181  removeEntry(const ptr_lib::shared_ptr<Entry>& pendingInterest);
182 
183 private:
184  std::vector<ptr_lib::shared_ptr<Entry> > table_;
185  std::vector<uint64_t> removeRequests_;
186 };
187 
188 }
189 
190 #endif
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &)> OnTimeout
An OnTimeout function object is used to pass a callback to expressInterest.
Definition: face.hpp:46
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
Entry holds the callbacks and other fields for an entry in the pending interest table.
Definition: pending-interest-table.hpp:39
bool getIsRemoved()
Check if setIsRemoved() was called.
Definition: pending-interest-table.hpp:94
const ptr_lib::shared_ptr< const Interest > & getInterest()
Get the interest given to the constructor (from Face.expressInterest).
Definition: pending-interest-table.hpp:67
const OnData & getOnData()
Get the OnData callback given to the constructor.
Definition: pending-interest-table.hpp:74
void setIsRemoved()
Set the isRemoved flag which is returned by getIsRemoved().
Definition: pending-interest-table.hpp:87
void callTimeout()
Call onTimeout_ (if defined).
Definition: pending-interest-table.cpp:33
Entry(uint64_t pendingInterestId, const ptr_lib::shared_ptr< const Interest > &interest, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack)
Create a new Entry with the given fields.
Definition: pending-interest-table.hpp:46
A PendingInterestTable is an internal class to hold a list of pending interests with their callbacks...
Definition: pending-interest-table.hpp:33
void extractEntriesForNackInterest(const Interest &interest, std::vector< ptr_lib::shared_ptr< Entry > > &entries)
Find all entries from the pending interest table where the OnNetworkNack callback is not an empty OnN...
Definition: pending-interest-table.cpp:87
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:41
void extractEntriesForExpressedInterest(const Name &name, std::vector< ptr_lib::shared_ptr< Entry > > &entries)
Find all entries from the pending interest table where the name conforms to the entry's interest sele...
Definition: pending-interest-table.cpp:70
bool removeEntry(const ptr_lib::shared_ptr< Entry > &pendingInterest)
Remove the specific pendingInterest entry from the table and set its isRemoved flag.
Definition: pending-interest-table.cpp:141
uint64_t getPendingInterestId()
Get the pendingInterestId given to the constructor.
Definition: pending-interest-table.hpp:59
ptr_lib::shared_ptr< Entry > add(uint64_t pendingInterestId, const ptr_lib::shared_ptr< const Interest > &interestCopy, const OnData &onData, const OnTimeout &onTimeout, const OnNetworkNack &onNetworkNack)
Add a new entry to the pending interest table.
Definition: pending-interest-table.cpp:49
void removePendingInterest(uint64_t pendingInterestId)
Remove the pending interest entry with the pendingInterestId from the pending interest table and set ...
Definition: pending-interest-table.cpp:110
const OnNetworkNack & getOnNetworkNack()
Get the OnNetworkNack callback given to the constructor.
Definition: pending-interest-table.hpp:81
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &, const ptr_lib::shared_ptr< Data > &)> OnData
An OnData function object is used to pass a callback to expressInterest.
Definition: face.hpp:35
func_lib::function< void(const ptr_lib::shared_ptr< const Interest > &, const ptr_lib::shared_ptr< NetworkNack > &)> OnNetworkNack
An OnNetworkNack function object is used to pass a callback to expressInterest.
Definition: face.hpp:52