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" |
| 11 | #include "../interest.hpp" |
| 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | class RegisteredPrefix { |
| 16 | public: |
| 17 | typedef function<void |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 18 | (const Name&, const Interest&)> OnInterest; |
Alexander Afanasyev | c8823bc | 2014-02-09 19:33:33 -0800 | [diff] [blame] | 19 | |
| 20 | /** |
| 21 | * Create a new PrefixEntry. |
| 22 | * @param prefix A shared_ptr for the prefix. |
| 23 | * @param onInterest A function object to call when a matching data packet is received. |
| 24 | */ |
| 25 | RegisteredPrefix(const Name& prefix, const OnInterest& onInterest) |
| 26 | : prefix_(new Name(prefix)) |
| 27 | , onInterest_(onInterest) |
| 28 | { |
| 29 | } |
| 30 | |
| 31 | const Name& |
| 32 | getPrefix() const |
| 33 | { |
| 34 | return *prefix_; |
| 35 | } |
| 36 | |
| 37 | const OnInterest& |
| 38 | getOnInterest() const |
| 39 | { |
| 40 | return onInterest_; |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | shared_ptr<Name> prefix_; |
| 45 | const OnInterest onInterest_; |
| 46 | }; |
| 47 | |
| 48 | |
| 49 | struct RegisteredPrefixId; |
| 50 | |
| 51 | /** |
| 52 | * @brief Functor to match pending interests against PendingInterestId |
| 53 | */ |
| 54 | struct MatchRegisteredPrefixId |
| 55 | { |
| 56 | MatchRegisteredPrefixId(const RegisteredPrefixId *registeredPrefixId) |
| 57 | : id_(registeredPrefixId) |
| 58 | { |
| 59 | } |
| 60 | |
| 61 | bool |
| 62 | operator()(const shared_ptr<RegisteredPrefix> ®isteredPrefix) const |
| 63 | { |
| 64 | return (reinterpret_cast<const RegisteredPrefixId *>(registeredPrefix.get()) == id_); |
| 65 | } |
| 66 | private: |
| 67 | const RegisteredPrefixId *id_; |
| 68 | }; |
| 69 | |
| 70 | } // namespace ndn |
| 71 | |
| 72 | #endif // NDN_DETAIL_REGISTERED_PREFIX_HPP |