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 | |
| 16 | class RegisteredPrefix { |
| 17 | public: |
| 18 | typedef function<void |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 19 | (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) |
| 27 | : prefix_(new Name(prefix)) |
| 28 | , onInterest_(onInterest) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | const Name& |
| 33 | getPrefix() const |
| 34 | { |
| 35 | return *prefix_; |
| 36 | } |
| 37 | |
| 38 | const OnInterest& |
| 39 | getOnInterest() const |
| 40 | { |
| 41 | return onInterest_; |
| 42 | } |
| 43 | |
| 44 | private: |
| 45 | shared_ptr<Name> prefix_; |
| 46 | const OnInterest onInterest_; |
| 47 | }; |
| 48 | |
| 49 | |
| 50 | struct RegisteredPrefixId; |
| 51 | |
| 52 | /** |
| 53 | * @brief Functor to match pending interests against PendingInterestId |
| 54 | */ |
| 55 | struct MatchRegisteredPrefixId |
| 56 | { |
| 57 | MatchRegisteredPrefixId(const RegisteredPrefixId *registeredPrefixId) |
| 58 | : id_(registeredPrefixId) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | bool |
| 63 | operator()(const shared_ptr<RegisteredPrefix> ®isteredPrefix) const |
| 64 | { |
| 65 | return (reinterpret_cast<const RegisteredPrefixId *>(registeredPrefix.get()) == id_); |
| 66 | } |
| 67 | private: |
| 68 | const RegisteredPrefixId *id_; |
| 69 | }; |
| 70 | |
| 71 | } // namespace ndn |
| 72 | |
| 73 | #endif // NDN_DETAIL_REGISTERED_PREFIX_HPP |