Alexander Afanasyev | ee8bb1e | 2014-05-02 17:39:54 -0700 | [diff] [blame^] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2013-2014, Regents of the University of California. |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions). |
| 7 | * See AUTHORS.md for complete list of ndn-cxx authors and contributors. |
| 8 | * |
| 9 | * This file licensed under New BSD License. See COPYING for detailed information about |
| 10 | * ndn-cxx library copyright, permissions, and redistribution restrictions. |
| 11 | */ |
| 12 | |
| 13 | #ifndef NDN_DETAIL_INTEREST_FILTER_RECORD_HPP |
| 14 | #define NDN_DETAIL_INTEREST_FILTER_RECORD_HPP |
| 15 | |
| 16 | #include "../common.hpp" |
| 17 | #include "../name.hpp" |
| 18 | #include "../interest.hpp" |
| 19 | |
| 20 | namespace ndn { |
| 21 | |
| 22 | class InterestFilterRecord : noncopyable |
| 23 | { |
| 24 | public: |
| 25 | typedef function<void (const InterestFilter&, const Interest&)> OnInterest; |
| 26 | |
| 27 | InterestFilterRecord(const InterestFilter& filter, const OnInterest& onInterest) |
| 28 | : m_filter(filter) |
| 29 | , m_onInterest(onInterest) |
| 30 | { |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @brief Check if Interest name matches the filter |
| 35 | * @param name Interest Name |
| 36 | */ |
| 37 | bool |
| 38 | doesMatch(const Name& name) const |
| 39 | { |
| 40 | return m_filter.doesMatch(name); |
| 41 | } |
| 42 | |
| 43 | void |
| 44 | operator()(const Interest& interest) const |
| 45 | { |
| 46 | m_onInterest(m_filter, interest); |
| 47 | } |
| 48 | |
| 49 | const InterestFilter& |
| 50 | getFilter() const |
| 51 | { |
| 52 | return m_filter; |
| 53 | } |
| 54 | |
| 55 | private: |
| 56 | InterestFilter m_filter; |
| 57 | OnInterest m_onInterest; |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | /** |
| 62 | * @brief Opaque class representing ID of the Interest filter |
| 63 | */ |
| 64 | class InterestFilterId; |
| 65 | |
| 66 | /** |
| 67 | * @brief Functor to match InterestFilterId |
| 68 | */ |
| 69 | class MatchInterestFilterId |
| 70 | { |
| 71 | public: |
| 72 | explicit |
| 73 | MatchInterestFilterId(const InterestFilterId* interestFilterId) |
| 74 | : m_id(interestFilterId) |
| 75 | { |
| 76 | } |
| 77 | |
| 78 | bool |
| 79 | operator()(const shared_ptr<InterestFilter>& interestFilterId) const |
| 80 | { |
| 81 | return (reinterpret_cast<const InterestFilterId*>(interestFilterId.get()) == m_id); |
| 82 | } |
| 83 | private: |
| 84 | const InterestFilterId* m_id; |
| 85 | }; |
| 86 | |
| 87 | } // namespace ndn |
| 88 | |
| 89 | #endif // NDN_DETAIL_INTEREST_FILTER_RECORD_HPP |