Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 2 | /** |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 3 | * Copyright (c) 2013-2014 Regents of the University of California. |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 4 | * |
| 5 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 6 | * |
Alexander Afanasyev | c169a81 | 2014-05-20 20:37:29 -0400 | [diff] [blame] | 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. |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 20 | */ |
| 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 | |
| 29 | namespace ndn { |
| 30 | |
| 31 | class InterestFilterRecord : noncopyable |
| 32 | { |
| 33 | public: |
| 34 | typedef function<void (const InterestFilter&, const Interest&)> OnInterest; |
| 35 | |
| 36 | InterestFilterRecord(const InterestFilter& filter, const OnInterest& onInterest) |
| 37 | : m_filter(filter) |
| 38 | , m_onInterest(onInterest) |
| 39 | { |
| 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 | |
| 52 | void |
| 53 | operator()(const Interest& interest) const |
| 54 | { |
| 55 | m_onInterest(m_filter, interest); |
| 56 | } |
| 57 | |
| 58 | const InterestFilter& |
| 59 | getFilter() const |
| 60 | { |
| 61 | return m_filter; |
| 62 | } |
| 63 | |
| 64 | private: |
| 65 | InterestFilter m_filter; |
| 66 | OnInterest m_onInterest; |
| 67 | }; |
| 68 | |
| 69 | |
| 70 | /** |
| 71 | * @brief Opaque class representing ID of the Interest filter |
| 72 | */ |
| 73 | class InterestFilterId; |
| 74 | |
| 75 | /** |
| 76 | * @brief Functor to match InterestFilterId |
| 77 | */ |
| 78 | class MatchInterestFilterId |
| 79 | { |
| 80 | public: |
| 81 | explicit |
| 82 | MatchInterestFilterId(const InterestFilterId* interestFilterId) |
| 83 | : m_id(interestFilterId) |
| 84 | { |
| 85 | } |
| 86 | |
| 87 | bool |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 88 | operator()(const shared_ptr<InterestFilterRecord>& interestFilterId) const |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 89 | { |
| 90 | return (reinterpret_cast<const InterestFilterId*>(interestFilterId.get()) == m_id); |
| 91 | } |
| 92 | private: |
| 93 | const InterestFilterId* m_id; |
| 94 | }; |
| 95 | |
| 96 | } // namespace ndn |
| 97 | |
| 98 | #endif // NDN_DETAIL_INTEREST_FILTER_RECORD_HPP |