NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
API Documentation
interest-filter-record.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013-2017 Regents of the University of California.
4  *
5  * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6  *
7  * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8  * terms of the GNU Lesser General Public License as published by the Free Software
9  * Foundation, either version 3 of the License, or (at your option) any later version.
10  *
11  * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13  * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14  *
15  * You should have received copies of the GNU General Public License and GNU Lesser
16  * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17  * <http://www.gnu.org/licenses/>.
18  *
19  * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20  */
21 
22 #ifndef NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
23 #define NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
24 
25 #include "pending-interest.hpp"
26 
27 namespace ndn {
28 
32 class InterestFilterRecord : noncopyable
33 {
34 public:
42  const InterestCallback& interestCallback)
43  : m_filter(filter)
44  , m_interestCallback(interestCallback)
45  {
46  }
47 
51  const InterestFilter&
52  getFilter() const
53  {
54  return m_filter;
55  }
56 
61  bool
62  doesMatch(const PendingInterest& entry) const
63  {
64  return (entry.getOrigin() == PendingInterestOrigin::FORWARDER || m_filter.allowsLoopback()) &&
65  m_filter.doesMatch(entry.getInterest()->getName());
66  }
67 
72  void
73  invokeInterestCallback(const Interest& interest) const
74  {
75  if (m_interestCallback != nullptr) {
76  m_interestCallback(m_filter, interest);
77  }
78  }
79 
80 private:
81  InterestFilter m_filter;
82  InterestCallback m_interestCallback;
83 };
84 
88 class InterestFilterId;
89 
94 {
95 public:
96  explicit
97  MatchInterestFilterId(const InterestFilterId* interestFilterId)
98  : m_id(interestFilterId)
99  {
100  }
101 
102  bool
103  operator()(const shared_ptr<InterestFilterRecord>& interestFilterId) const
104  {
105  return reinterpret_cast<const InterestFilterId*>(interestFilterId.get()) == m_id;
106  }
107 
108 private:
109  const InterestFilterId* m_id;
110 };
111 
112 } // namespace ndn
113 
114 #endif // NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
void invokeInterestCallback(const Interest &interest) const
invokes the InterestCallback
Copyright (c) 2011-2015 Regents of the University of California.
InterestFilterRecord(const InterestFilter &filter, const InterestCallback &interestCallback)
Construct an Interest filter record.
shared_ptr< const Interest > getInterest() const
Get the Interest.
declares the set of Interests a producer can serve, which starts with a name prefix, plus an optional regular expression
const InterestFilter & getFilter() const
associates an InterestFilter with Interest callback
bool doesMatch(const PendingInterest &entry) const
Check if Interest name matches the filter.
Represents an Interest packet.
Definition: interest.hpp:42
MatchInterestFilterId(const InterestFilterId *interestFilterId)
bool doesMatch(const Name &name) const
Check if specified Interest name matches the filter.
Functor to match InterestFilterId.
function< void(const InterestFilter &, const Interest &)> InterestCallback
Callback invoked when incoming Interest matches the specified InterestFilter.
Definition: face.hpp:65
bool operator()(const shared_ptr< InterestFilterRecord > &interestFilterId) const
Interest was received from the forwarder via Transport.
bool allowsLoopback() const
Get whether Interest loopback is allowed.
PendingInterestOrigin getOrigin() const
Stores a pending Interest and associated callbacks.