blob: c5ab2ca783b58dec62ea652052163989db3a2fd2 [file] [log] [blame]
Yanbiao Li4ee73d42015-08-19 16:30:16 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2014-2015, Regents of the University of California,
4 * Arizona Board of Regents,
5 * Colorado State University,
6 * University Pierre & Marie Curie, Sorbonne University,
7 * Washington University in St. Louis,
8 * Beijing Institute of Technology,
9 * The University of Memphis.
10 *
11 * This file is part of NFD (Named Data Networking Forwarding Daemon).
12 * See AUTHORS.md for complete list of NFD authors and contributors.
13 *
14 * NFD is free software: you can redistribute it and/or modify it under the terms
15 * of the GNU General Public License as published by the Free Software Foundation,
16 * either version 3 of the License, or (at your option) any later version.
17 *
18 * NFD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
20 * PURPOSE. See the GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along with
23 * NFD, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
24 */
25
26#include "internal-face.hpp"
27
28namespace nfd {
29
30InternalFace::InternalFace()
31 : Face(FaceUri("internal://"), FaceUri("internal://"), true)
32{
33}
34
35void
36InternalFace::sendInterest(const Interest& interest)
37{
38 this->emitSignal(onSendInterest, interest);
39}
40
41void
42InternalFace::sendData(const Data& data)
43{
44 this->emitSignal(onSendData, data);
45}
46
47void
48InternalFace::close()
49{
50}
51
52void
53InternalFace::receive(const Block& blockFromClient)
54{
55 const Block& payLoad = ndn::nfd::LocalControlHeader::getPayload(blockFromClient);
56 if (payLoad.type() == ndn::tlv::Interest) {
57 receiveInterest(*extractPacketFromBlock<Interest>(blockFromClient, payLoad));
58 }
59 else if (payLoad.type() == ndn::tlv::Data) {
60 receiveData(*extractPacketFromBlock<Data>(blockFromClient, payLoad));
61 }
62}
63
64void
65InternalFace::receiveInterest(const Interest& interest)
66{
67 this->emitSignal(onReceiveInterest, interest);
68}
69
70void
71InternalFace::receiveData(const Data& data)
72{
73 this->emitSignal(onReceiveData, data);
74}
75
76template<typename Packet>
77shared_ptr<Packet>
78InternalFace::extractPacketFromBlock(const Block& blockFromClient, const Block& payLoad)
79{
80 auto packet = make_shared<Packet>(payLoad);
81 if (&payLoad != &blockFromClient) {
82 packet->getLocalControlHeader().wireDecode(blockFromClient);
83 }
84 return packet;
85}
86
87template shared_ptr<Interest>
88InternalFace::extractPacketFromBlock<Interest>(const Block& blockFromClient, const Block& payLoad);
89
90template shared_ptr<Data>
91InternalFace::extractPacketFromBlock<Data>(const Block& blockFromClient, const Block& payLoad);
92
93} // namespace nfd