blob: 1f1a6cbc23466a3f83d9e7dce9642962cb39acf3 [file] [log] [blame]
Steve DiBenedetto5b433982014-01-29 17:14:27 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "internal-face.hpp"
8
9namespace nfd {
10
Steve DiBenedetto3970c892014-01-31 23:31:13 -070011NFD_LOG_INIT("InternalFace");
12
13InternalFace::InternalFace()
Steve DiBenedetto5b433982014-01-29 17:14:27 -070014{
15
16}
17
18void
19InternalFace::sendInterest(const Interest& interest)
20{
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070021 if (m_interestFilters.size() == 0)
22 {
23 NFD_LOG_DEBUG("no Interest filters to match against");
24 return;
25 }
26
Steve DiBenedetto3970c892014-01-31 23:31:13 -070027 const Name& interestName(interest.getName());
28 NFD_LOG_DEBUG("received Interest: " << interestName);
Steve DiBenedetto5b433982014-01-29 17:14:27 -070029
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070030 std::map<Name, OnInterest>::const_iterator filter =
31 m_interestFilters.lower_bound(interestName);
Steve DiBenedetto3970c892014-01-31 23:31:13 -070032
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070033 // lower_bound gives us the first Name that is
34 // an exact match OR ordered after interestName.
35 //
36 // If we reach the end of the map, then we need
37 // only check if the before-end element is a match.
38 //
39 // If we match an element, then the current
40 // position or the previous element are potential
41 // matches.
42 //
43 // If we hit begin, the element is either an exact
44 // match or there is no matching prefix in the map.
45
46
Steve DiBenedettobdedce92014-02-02 22:49:39 -070047 if (filter == m_interestFilters.end() && filter != m_interestFilters.begin())
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070048 {
49 // We hit the end, check if the previous element
50 // is a match
51 --filter;
52 if (filter->first.isPrefixOf(interestName))
Steve DiBenedetto3970c892014-01-31 23:31:13 -070053 {
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070054 NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (before end match)");
Steve DiBenedetto3970c892014-01-31 23:31:13 -070055 filter->second(interestName, interest);
56 }
57 else
58 {
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070059 NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (before end)");
Steve DiBenedetto3970c892014-01-31 23:31:13 -070060 }
Steve DiBenedetto5b433982014-01-29 17:14:27 -070061 }
Steve DiBenedettobdedce92014-02-02 22:49:39 -070062 else if (filter->first == interestName)
Steve DiBenedetto43cd0372014-02-01 17:05:07 -070063 {
64 NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (exact match)");
65 filter->second(interestName, interest);
66 }
67 else if (filter != m_interestFilters.begin())
68 {
69 // the element we found is canonically
70 // ordered after interestName.
71 // Check the previous element.
72 --filter;
73 if (filter->first.isPrefixOf(interestName))
74 {
75 NFD_LOG_DEBUG("found Interest filter for " << filter->first << " (previous match)");
76 filter->second(interestName, interest);
77 }
78 else
79 {
80 NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (previous)");
81 }
82 }
83 else
84 {
85 NFD_LOG_DEBUG("no Interest filter found for " << interestName << " (begin)");
86 }
Steve DiBenedetto5b433982014-01-29 17:14:27 -070087 //Drop Interest
88}
89
90void
91InternalFace::sendData(const Data& data)
92{
Steve DiBenedetto5b433982014-01-29 17:14:27 -070093}
94
95void
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080096InternalFace::close()
97{
98 throw Error("Internal face cannot be closed");
99}
100
Alexander Afanasyev93ce75e2014-02-18 19:45:34 -0800101bool
102InternalFace::isLocal() const
103{
104 return true;
105}
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -0800106
107void
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700108InternalFace::setInterestFilter(const Name& filter,
109 OnInterest onInterest)
110{
Steve DiBenedetto3970c892014-01-31 23:31:13 -0700111 NFD_LOG_INFO("registering callback for " << filter);
112 m_interestFilters[filter] = onInterest;
Steve DiBenedetto5b433982014-01-29 17:14:27 -0700113}
114
115void
116InternalFace::put(const Data& data)
117{
118 onReceiveData(data);
119}
120
121InternalFace::~InternalFace()
122{
123
124}
125
126} // namespace nfd