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 |
| 38 | * \note When LpFace is adapted by LpFaceWrapper, |
| 39 | * FaceId and counters will come from old Face rather than LpFace. |
| 40 | */ |
| 41 | class LpFaceWrapper : public Face |
| 42 | { |
| 43 | public: |
| 44 | explicit |
| 45 | LpFaceWrapper(unique_ptr<LpFace> face); |
| 46 | |
| 47 | LpFace* |
| 48 | getLpFace(); |
| 49 | |
| 50 | virtual void |
| 51 | sendInterest(const Interest& interest) DECL_OVERRIDE; |
| 52 | |
| 53 | virtual void |
| 54 | sendData(const Data& data) DECL_OVERRIDE; |
| 55 | |
| 56 | virtual void |
| 57 | sendNack(const lp::Nack& nack) DECL_OVERRIDE; |
| 58 | |
| 59 | virtual void |
| 60 | close() DECL_OVERRIDE; |
| 61 | |
| 62 | virtual bool |
| 63 | isUp() const DECL_OVERRIDE; |
| 64 | |
| 65 | virtual void |
| 66 | setPersistency(ndn::nfd::FacePersistency persistency) DECL_OVERRIDE; |
| 67 | |
| 68 | virtual const FaceCounters& |
| 69 | getCounters() const DECL_OVERRIDE; |
| 70 | |
| 71 | protected: |
| 72 | virtual void |
| 73 | setId(nfd::FaceId faceId) DECL_OVERRIDE; |
| 74 | |
| 75 | private: |
| 76 | void |
| 77 | dispatchInterest(const Interest& interest); |
| 78 | |
| 79 | void |
| 80 | dispatchData(const Data& data); |
| 81 | |
| 82 | void |
| 83 | dispatchNack(const lp::Nack& nack); |
| 84 | |
| 85 | void |
| 86 | handleStateChange(FaceState oldState, FaceState newState); |
| 87 | |
| 88 | private: |
| 89 | unique_ptr<LpFace> m_face; |
| 90 | }; |
| 91 | |
| 92 | inline LpFace* |
| 93 | LpFaceWrapper::getLpFace() |
| 94 | { |
| 95 | return m_face.get(); |
| 96 | } |
| 97 | |
| 98 | inline void |
| 99 | LpFaceWrapper::sendInterest(const Interest& interest) |
| 100 | { |
| 101 | this->emitSignal(onSendInterest, interest); |
| 102 | m_face->sendInterest(interest); |
| 103 | } |
| 104 | |
| 105 | inline void |
| 106 | LpFaceWrapper::sendData(const Data& data) |
| 107 | { |
| 108 | this->emitSignal(onSendData, data); |
| 109 | m_face->sendData(data); |
| 110 | } |
| 111 | |
| 112 | inline void |
| 113 | LpFaceWrapper::sendNack(const lp::Nack& nack) |
| 114 | { |
| 115 | this->emitSignal(onSendNack, nack); |
| 116 | m_face->sendNack(nack); |
| 117 | } |
| 118 | |
| 119 | inline void |
| 120 | LpFaceWrapper::close() |
| 121 | { |
| 122 | m_face->close(); |
| 123 | } |
| 124 | |
| 125 | inline bool |
| 126 | LpFaceWrapper::isUp() const |
| 127 | { |
| 128 | return m_face->getState() == FaceState::UP; |
| 129 | } |
| 130 | |
| 131 | inline const FaceCounters& |
| 132 | LpFaceWrapper::getCounters() const |
| 133 | { |
| 134 | return m_face->getCounters(); |
| 135 | } |
| 136 | |
| 137 | } // namespace face |
| 138 | } // namespace nfd |
| 139 | |
| 140 | #endif // NFD_DAEMON_FACE_LP_FACE_WRAPPER_HPP |