blob: 3a1778563f892fbed65a00ef5b1498c479616150 [file] [log] [blame]
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
2/**
Alexander Afanasyevdfa52c42014-04-24 21:10:11 -07003 * 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.
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080011 */
12
13#ifndef NDN_DETAIL_REGISTERED_PREFIX_HPP
14#define NDN_DETAIL_REGISTERED_PREFIX_HPP
15
16#include "../common.hpp"
Alexander Afanasyevc348f832014-02-17 16:35:17 -080017#include "../name.hpp"
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080018#include "../interest.hpp"
19
20namespace ndn {
21
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070022class RegisteredPrefix
23{
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080024public:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070025 typedef function<void (const Name&, const Interest&)> OnInterest;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080026
27 /**
28 * Create a new PrefixEntry.
29 * @param prefix A shared_ptr for the prefix.
30 * @param onInterest A function object to call when a matching data packet is received.
31 */
32 RegisteredPrefix(const Name& prefix, const OnInterest& onInterest)
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070033 : m_prefix(new Name(prefix))
34 , m_onInterest(onInterest)
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080035 {
36 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070037
38 const Name&
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080039 getPrefix() const
40 {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070041 return* m_prefix;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080042 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070043
44 const OnInterest&
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080045 getOnInterest() const
46 {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070047 return m_onInterest;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080048 }
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070049
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080050private:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070051 shared_ptr<Name> m_prefix;
52 const OnInterest m_onInterest;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080053};
54
55
56struct RegisteredPrefixId;
57
58/**
59 * @brief Functor to match pending interests against PendingInterestId
60 */
61struct MatchRegisteredPrefixId
62{
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070063 MatchRegisteredPrefixId(const RegisteredPrefixId* registeredPrefixId)
64 : m_id(registeredPrefixId)
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080065 {
66 }
67
68 bool
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070069 operator()(const shared_ptr<RegisteredPrefix>& registeredPrefix) const
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080070 {
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070071 return (reinterpret_cast<const RegisteredPrefixId*>(registeredPrefix.get()) == m_id);
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080072 }
73private:
Alexander Afanasyevfdbfc6d2014-04-14 15:12:11 -070074 const RegisteredPrefixId* m_id;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080075};
76
77} // namespace ndn
78
79#endif // NDN_DETAIL_REGISTERED_PREFIX_HPP