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 | 73e3004 | 2015-09-17 17:09:51 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013-2015 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: |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 34 | typedef function<void (const InterestFilter&, const Interest&)> InterestCallback; |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 35 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 36 | InterestFilterRecord(const InterestFilter& filter, const InterestCallback& afterInterest) |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 37 | : m_filter(filter) |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 38 | , m_afterInterest(afterInterest) |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 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 | |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 52 | /** |
| 53 | * @brief invokes the InterestCallback |
| 54 | * @note If the DataCallback is an empty function, this method does nothing. |
| 55 | */ |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 56 | void |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 57 | invokeInterestCallback(const Interest& interest) const |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 58 | { |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 59 | m_afterInterest(m_filter, interest); |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | const InterestFilter& |
| 63 | getFilter() const |
| 64 | { |
| 65 | return m_filter; |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | InterestFilter m_filter; |
Alexander Afanasyev | 9d158f0 | 2015-02-17 21:30:19 -0800 | [diff] [blame] | 70 | InterestCallback m_afterInterest; |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * @brief Opaque class representing ID of the Interest filter |
| 76 | */ |
| 77 | class InterestFilterId; |
| 78 | |
| 79 | /** |
| 80 | * @brief Functor to match InterestFilterId |
| 81 | */ |
| 82 | class MatchInterestFilterId |
| 83 | { |
| 84 | public: |
| 85 | explicit |
| 86 | MatchInterestFilterId(const InterestFilterId* interestFilterId) |
| 87 | : m_id(interestFilterId) |
| 88 | { |
| 89 | } |
| 90 | |
| 91 | bool |
Alexander Afanasyev | 984ad19 | 2014-05-02 19:11:15 -0700 | [diff] [blame] | 92 | operator()(const shared_ptr<InterestFilterRecord>& interestFilterId) const |
Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame] | 93 | { |
| 94 | return (reinterpret_cast<const InterestFilterId*>(interestFilterId.get()) == m_id); |
| 95 | } |
| 96 | private: |
| 97 | const InterestFilterId* m_id; |
| 98 | }; |
| 99 | |
| 100 | } // namespace ndn |
| 101 | |
| 102 | #endif // NDN_DETAIL_INTEREST_FILTER_RECORD_HPP |