blob: aeb6c66dc61706362fc2387e1848689d5cb01257 [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"
11#include "../interest.hpp"
12
13namespace ndn {
14
15class RegisteredPrefix {
16public:
17 typedef function<void
Alexander Afanasyev0222fba2014-02-09 23:16:02 -080018 (const Name&, const Interest&)> OnInterest;
Alexander Afanasyevc8823bc2014-02-09 19:33:33 -080019
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
43private:
44 shared_ptr<Name> prefix_;
45 const OnInterest onInterest_;
46};
47
48
49struct RegisteredPrefixId;
50
51/**
52 * @brief Functor to match pending interests against PendingInterestId
53 */
54struct MatchRegisteredPrefixId
55{
56 MatchRegisteredPrefixId(const RegisteredPrefixId *registeredPrefixId)
57 : id_(registeredPrefixId)
58 {
59 }
60
61 bool
62 operator()(const shared_ptr<RegisteredPrefix> &registeredPrefix) const
63 {
64 return (reinterpret_cast<const RegisteredPrefixId *>(registeredPrefix.get()) == id_);
65 }
66private:
67 const RegisteredPrefixId *id_;
68};
69
70} // namespace ndn
71
72#endif // NDN_DETAIL_REGISTERED_PREFIX_HPP