Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -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 | #ifndef NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP |
| 27 | #define NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP |
| 28 | |
| 29 | #include "common.hpp" |
| 30 | #include "face.hpp" |
| 31 | #include "lp-face.hpp" |
| 32 | |
| 33 | namespace nfd { |
| 34 | namespace face { |
| 35 | |
| 36 | /** \brief an adaptor to provide old Face APIs from an LpFace |
| 37 | * \sa LpFace |
Eric Newberry | a98bf93 | 2015-09-21 00:58:47 -0700 | [diff] [blame] | 38 | */ |
| 39 | class LpFaceWrapper : public Face |
| 40 | { |
| 41 | public: |
| 42 | explicit |
| 43 | LpFaceWrapper(unique_ptr<LpFace> face); |
| 44 | |
| 45 | LpFace* |
| 46 | getLpFace(); |
| 47 | |
| 48 | virtual void |
| 49 | sendInterest(const Interest& interest) DECL_OVERRIDE; |
| 50 | |
| 51 | virtual void |
| 52 | sendData(const Data& data) DECL_OVERRIDE; |
| 53 | |
| 54 | virtual void |
| 55 | sendNack(const lp::Nack& nack) DECL_OVERRIDE; |
| 56 | |
| 57 | virtual void |
| 58 | close() DECL_OVERRIDE; |
| 59 | |
| 60 | virtual bool |
| 61 | isUp() const DECL_OVERRIDE; |
| 62 | |
| 63 | virtual void |
| 64 | setPersistency(ndn::nfd::FacePersistency persistency) DECL_OVERRIDE; |
| 65 | |
| 66 | virtual const FaceCounters& |
| 67 | getCounters() const DECL_OVERRIDE; |
| 68 | |
| 69 | protected: |
| 70 | virtual void |
| 71 | setId(nfd::FaceId faceId) DECL_OVERRIDE; |
| 72 | |
| 73 | private: |
| 74 | void |
| 75 | dispatchInterest(const Interest& interest); |
| 76 | |
| 77 | void |
| 78 | dispatchData(const Data& data); |
| 79 | |
| 80 | void |
| 81 | dispatchNack(const lp::Nack& nack); |
| 82 | |
| 83 | void |
| 84 | handleStateChange(FaceState oldState, FaceState newState); |
| 85 | |
| 86 | private: |
| 87 | unique_ptr<LpFace> m_face; |
| 88 | }; |
| 89 | |
| 90 | inline LpFace* |
| 91 | LpFaceWrapper::getLpFace() |
| 92 | { |
| 93 | return m_face.get(); |
| 94 | } |
| 95 | |
| 96 | inline void |
| 97 | LpFaceWrapper::sendInterest(const Interest& interest) |
| 98 | { |
| 99 | this->emitSignal(onSendInterest, interest); |
| 100 | m_face->sendInterest(interest); |
| 101 | } |
| 102 | |
| 103 | inline void |
| 104 | LpFaceWrapper::sendData(const Data& data) |
| 105 | { |
| 106 | this->emitSignal(onSendData, data); |
| 107 | m_face->sendData(data); |
| 108 | } |
| 109 | |
| 110 | inline void |
| 111 | LpFaceWrapper::sendNack(const lp::Nack& nack) |
| 112 | { |
| 113 | this->emitSignal(onSendNack, nack); |
| 114 | m_face->sendNack(nack); |
| 115 | } |
| 116 | |
| 117 | inline void |
| 118 | LpFaceWrapper::close() |
| 119 | { |
| 120 | m_face->close(); |
| 121 | } |
| 122 | |
| 123 | inline bool |
| 124 | LpFaceWrapper::isUp() const |
| 125 | { |
| 126 | return m_face->getState() == FaceState::UP; |
| 127 | } |
| 128 | |
| 129 | inline const FaceCounters& |
| 130 | LpFaceWrapper::getCounters() const |
| 131 | { |
| 132 | return m_face->getCounters(); |
| 133 | } |
| 134 | |
| 135 | } // namespace face |
| 136 | } // namespace nfd |
| 137 | |
| 138 | #endif // NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP |