Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_DETAIL_REGISTERED_PREFIX_HPP |
| 8 | #define NDN_DETAIL_REGISTERED_PREFIX_HPP |
| 9 | |
| 10 | #include "../common.hpp" |
Alexander Afanasyev | c348f83 | 2014-02-17 16:35:17 -0800 | [diff] [blame] | 11 | #include "../name.hpp" |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 12 | #include "../interest.hpp" |
| 13 | |
| 14 | namespace ndn { |
| 15 | |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 16 | class RegisteredPrefix |
| 17 | { |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 18 | public: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 19 | typedef function<void (const Name&, const Interest&)> OnInterest; |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Create a new PrefixEntry. |
| 23 | * @param prefix A shared_ptr for the prefix. |
| 24 | * @param onInterest A function object to call when a matching data packet is received. |
| 25 | */ |
| 26 | RegisteredPrefix(const Name& prefix, const OnInterest& onInterest) |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 27 | : m_prefix(new Name(prefix)) |
| 28 | , m_onInterest(onInterest) |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 29 | { |
| 30 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 31 | |
| 32 | const Name& |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 33 | getPrefix() const |
| 34 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 35 | return* m_prefix; |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 36 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 37 | |
| 38 | const OnInterest& |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 39 | getOnInterest() const |
| 40 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 41 | return m_onInterest; |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 42 | } |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 43 | |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 44 | private: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 45 | shared_ptr<Name> m_prefix; |
| 46 | const OnInterest m_onInterest; |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | |
| 50 | struct RegisteredPrefixId; |
| 51 | |
| 52 | /** |
| 53 | * @brief Functor to match pending interests against PendingInterestId |
| 54 | */ |
| 55 | struct MatchRegisteredPrefixId |
| 56 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 57 | MatchRegisteredPrefixId(const RegisteredPrefixId* registeredPrefixId) |
| 58 | : m_id(registeredPrefixId) |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 59 | { |
| 60 | } |
| 61 | |
| 62 | bool |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 63 | operator()(const shared_ptr<RegisteredPrefix>& registeredPrefix) const |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 64 | { |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 65 | return (reinterpret_cast<const RegisteredPrefixId*>(registeredPrefix.get()) == m_id); |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 66 | } |
| 67 | private: |
Alexander Afanasyev | fdbfc6d | 2014-04-14 15:12:11 -0700 | [diff] [blame^] | 68 | const RegisteredPrefixId* m_id; |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | } // namespace ndn |
| 72 | |
| 73 | #endif // NDN_DETAIL_REGISTERED_PREFIX_HPP |