interest-filter-table.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_INTEREST_FILTER_TABLE_HPP
23 #define NDN_INTEREST_FILTER_TABLE_HPP
24 
25 #include <ndn-cpp/face.hpp>
26 
27 namespace ndn {
28 
34 public:
39  class Entry {
40  public:
50  Entry
51  (uint64_t interestFilterId,
52  const ptr_lib::shared_ptr<const InterestFilter>& filter,
53  const OnInterestCallback& onInterest, Face* face)
54  : interestFilterId_(interestFilterId), filter_(filter),
55  prefix_(new Name(filter->getPrefix())), onInterest_(onInterest), face_(face)
56  {
57  }
58 
63  uint64_t
64  getInterestFilterId() { return interestFilterId_; }
65 
70  const ptr_lib::shared_ptr<const InterestFilter>&
71  getFilter() { return filter_; }
72 
79  const ptr_lib::shared_ptr<const Name>&
80  getPrefix() { return prefix_; }
81 
86  const OnInterestCallback&
87  getOnInterest() { return onInterest_; }
88 
93  Face&
94  getFace() { return *face_; }
95 
96  private:
97  uint64_t interestFilterId_;
98  ptr_lib::shared_ptr<const InterestFilter> filter_;
99  ptr_lib::shared_ptr<const Name> prefix_;
100  const OnInterestCallback onInterest_;
101  Face* face_;
102  };
103 
112  void
114  (uint64_t interestFilterId,
115  const ptr_lib::shared_ptr<const InterestFilter>& filterCopy,
116  const OnInterestCallback& onInterest, Face* face)
117  {
118  table_.push_back(ptr_lib::make_shared<Entry>
119  (interestFilterId, filterCopy, onInterest, face));
120  }
121 
130  void
132  (const Interest& interest,
133  std::vector<ptr_lib::shared_ptr<Entry> > &matchedFilters);
134 
142  void
143  unsetInterestFilter(uint64_t interestFilterId);
144 
145 private:
146  std::vector<ptr_lib::shared_ptr<Entry> > table_;
147 };
148 
149 }
150 
151 #endif
const ptr_lib::shared_ptr< const Name > & getPrefix()
Get the prefix from the filter as a shared_ptr.
Definition: interest-filter-table.hpp:80
Copyright (C) 2013-2016 Regents of the University of California.
Definition: common.hpp:35
The Face class provides the main methods for NDN communication.
Definition: face.hpp:86
An Entry holds an interestFilterId, an InterestFilter and the OnInterestCallback with its related Fac...
Definition: interest-filter-table.hpp:39
A Name holds an array of Name::Component and represents an NDN name.
Definition: name.hpp:40
Entry(uint64_t interestFilterId, const ptr_lib::shared_ptr< const InterestFilter > &filter, const OnInterestCallback &onInterest, Face *face)
Create a new Entry with the given values.
Definition: interest-filter-table.hpp:51
An Interest holds a Name and other fields for an interest.
Definition: interest.hpp:41
func_lib::function< void(const ptr_lib::shared_ptr< const Name > &, const ptr_lib::shared_ptr< const Interest > &, Face &, uint64_t, const ptr_lib::shared_ptr< const InterestFilter > &)> OnInterestCallback
An OnInterestCallback function object is used to pass a callback to setInterestFilter and optionally ...
Definition: face.hpp:67
const OnInterestCallback & getOnInterest()
Get the OnInterestCallback given to the constructor.
Definition: interest-filter-table.hpp:87
void getMatchedFilters(const Interest &interest, std::vector< ptr_lib::shared_ptr< Entry > > &matchedFilters)
Find all entries from the interest filter table where the interest conforms to the entry's filter...
Definition: interest-filter-table.cpp:33
An InterestFilterTable is an internal class to hold a list of entries with an interest Filter and its...
Definition: interest-filter-table.hpp:33
uint64_t getInterestFilterId()
Return the interestFilterId given to the constructor.
Definition: interest-filter-table.hpp:64
void setInterestFilter(uint64_t interestFilterId, const ptr_lib::shared_ptr< const InterestFilter > &filterCopy, const OnInterestCallback &onInterest, Face *face)
Add a new entry to the table.
Definition: interest-filter-table.hpp:114
void unsetInterestFilter(uint64_t interestFilterId)
Remove the interest filter entry which has the interestFilterId from the interest filter table...
Definition: interest-filter-table.cpp:44
const ptr_lib::shared_ptr< const InterestFilter > & getFilter()
Get the InterestFilter given to the constructor.
Definition: interest-filter-table.hpp:71
Face & getFace()
Get the Face given to the constructor.
Definition: interest-filter-table.hpp:94