Yanbiao Li | 4ee73d4 | 2015-08-19 16:30:16 -0700 | [diff] [blame^] | 1 | /* -*- 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 | |
| 28 | namespace nfd { |
| 29 | |
| 30 | InternalFace::InternalFace() |
| 31 | : Face(FaceUri("internal://"), FaceUri("internal://"), true) |
| 32 | { |
| 33 | } |
| 34 | |
| 35 | void |
| 36 | InternalFace::sendInterest(const Interest& interest) |
| 37 | { |
| 38 | this->emitSignal(onSendInterest, interest); |
| 39 | } |
| 40 | |
| 41 | void |
| 42 | InternalFace::sendData(const Data& data) |
| 43 | { |
| 44 | this->emitSignal(onSendData, data); |
| 45 | } |
| 46 | |
| 47 | void |
| 48 | InternalFace::close() |
| 49 | { |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | InternalFace::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 | |
| 64 | void |
| 65 | InternalFace::receiveInterest(const Interest& interest) |
| 66 | { |
| 67 | this->emitSignal(onReceiveInterest, interest); |
| 68 | } |
| 69 | |
| 70 | void |
| 71 | InternalFace::receiveData(const Data& data) |
| 72 | { |
| 73 | this->emitSignal(onReceiveData, data); |
| 74 | } |
| 75 | |
| 76 | template<typename Packet> |
| 77 | shared_ptr<Packet> |
| 78 | InternalFace::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 | |
| 87 | template shared_ptr<Interest> |
| 88 | InternalFace::extractPacketFromBlock<Interest>(const Block& blockFromClient, const Block& payLoad); |
| 89 | |
| 90 | template shared_ptr<Data> |
| 91 | InternalFace::extractPacketFromBlock<Data>(const Block& blockFromClient, const Block& payLoad); |
| 92 | |
| 93 | } // namespace nfd |