blob: f3a224c21e479db3ca91304ea083ef98726a81dd [file] [log] [blame]
Alexander Afanasyevc169a812014-05-20 20:37:29 -04001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -07002/**
Alexander Afanasyevc169a812014-05-20 20:37:29 -04003 * Copyright (c) 2013-2014 Regents of the University of California.
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -07004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -07006 *
Alexander Afanasyevc169a812014-05-20 20:37:29 -04007 * 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.
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070020 */
21
22#ifndef NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
23#define NDN_DETAIL_INTEREST_FILTER_RECORD_HPP
24
25#include "../common.hpp"
26#include "../name.hpp"
27#include "../interest.hpp"
28
29namespace ndn {
30
31class InterestFilterRecord : noncopyable
32{
33public:
Alexander Afanasyev9d158f02015-02-17 21:30:19 -080034 typedef function<void (const InterestFilter&, const Interest&)> InterestCallback;
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070035
Alexander Afanasyev9d158f02015-02-17 21:30:19 -080036 InterestFilterRecord(const InterestFilter& filter, const InterestCallback& afterInterest)
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070037 : m_filter(filter)
Alexander Afanasyev9d158f02015-02-17 21:30:19 -080038 , m_afterInterest(afterInterest)
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070039 {
40 }
41
42 /**
43 * @brief Check if Interest name matches the filter
44 * @param name Interest Name
45 */
46 bool
47 doesMatch(const Name& name) const
48 {
49 return m_filter.doesMatch(name);
50 }
51
Alexander Afanasyev9d158f02015-02-17 21:30:19 -080052 /**
53 * @brief invokes the InterestCallback
54 * @note If the DataCallback is an empty function, this method does nothing.
55 */
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070056 void
Alexander Afanasyev9d158f02015-02-17 21:30:19 -080057 invokeInterestCallback(const Interest& interest) const
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070058 {
Alexander Afanasyev9d158f02015-02-17 21:30:19 -080059 m_afterInterest(m_filter, interest);
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070060 }
61
62 const InterestFilter&
63 getFilter() const
64 {
65 return m_filter;
66 }
67
68private:
69 InterestFilter m_filter;
Alexander Afanasyev9d158f02015-02-17 21:30:19 -080070 InterestCallback m_afterInterest;
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070071};
72
73
74/**
75 * @brief Opaque class representing ID of the Interest filter
76 */
77class InterestFilterId;
78
79/**
80 * @brief Functor to match InterestFilterId
81 */
82class MatchInterestFilterId
83{
84public:
85 explicit
86 MatchInterestFilterId(const InterestFilterId* interestFilterId)
87 : m_id(interestFilterId)
88 {
89 }
90
91 bool
Alexander Afanasyev984ad192014-05-02 19:11:15 -070092 operator()(const shared_ptr<InterestFilterRecord>& interestFilterId) const
Alexander Afanasyevee8bb1e2014-05-02 17:39:54 -070093 {
94 return (reinterpret_cast<const InterestFilterId*>(interestFilterId.get()) == m_id);
95 }
96private:
97 const InterestFilterId* m_id;
98};
99
100} // namespace ndn
101
102#endif // NDN_DETAIL_INTEREST_FILTER_RECORD_HPP