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