blob: 36a55faf4d0f33349bc24527e7c0e575d70f78e1 [file] [log] [blame]
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08001/* -*- 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 Afanasyevc348f832014-02-17 16:35:17 -080011#include "../name.hpp"
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080012#include "../interest.hpp"
13
14namespace ndn {
15
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070016class RegisteredPrefix
17{
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080018public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070019 typedef function<void (const Name&, const Interest&)> OnInterest;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080020
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 Afanasyevfdbfc6d2014-04-14 15:12:11 -070027 : m_prefix(new Name(prefix))
28 , m_onInterest(onInterest)
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080029 {
30 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070031
32 const Name&
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080033 getPrefix() const
34 {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070035 return* m_prefix;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080036 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070037
38 const OnInterest&
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080039 getOnInterest() const
40 {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070041 return m_onInterest;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080042 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070043
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080044private:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070045 shared_ptr<Name> m_prefix;
46 const OnInterest m_onInterest;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080047};
48
49
50struct RegisteredPrefixId;
51
52/**
53 * @brief Functor to match pending interests against PendingInterestId
54 */
55struct MatchRegisteredPrefixId
56{
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070057 MatchRegisteredPrefixId(const RegisteredPrefixId* registeredPrefixId)
58 : m_id(registeredPrefixId)
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080059 {
60 }
61
62 bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070063 operator()(const shared_ptr<RegisteredPrefix>& registeredPrefix) const
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080064 {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070065 return (reinterpret_cast<const RegisteredPrefixId*>(registeredPrefix.get()) == m_id);
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080066 }
67private:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070068 const RegisteredPrefixId* m_id;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080069};
70
71} // namespace ndn
72
73#endif // NDN_DETAIL_REGISTERED_PREFIX_HPP