blob: 084094fcd93e494843bf0970189717eb5fed7049 [file] [log] [blame]
Eric Newberrya98bf932015-09-21 00:58:47 -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#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
33namespace nfd {
34namespace 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 */
41class LpFaceWrapper : public Face
42{
43public:
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
71protected:
72 virtual void
73 setId(nfd::FaceId faceId) DECL_OVERRIDE;
74
75private:
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
88private:
89 unique_ptr<LpFace> m_face;
90};
91
92inline LpFace*
93LpFaceWrapper::getLpFace()
94{
95 return m_face.get();
96}
97
98inline void
99LpFaceWrapper::sendInterest(const Interest& interest)
100{
101 this->emitSignal(onSendInterest, interest);
102 m_face->sendInterest(interest);
103}
104
105inline void
106LpFaceWrapper::sendData(const Data& data)
107{
108 this->emitSignal(onSendData, data);
109 m_face->sendData(data);
110}
111
112inline void
113LpFaceWrapper::sendNack(const lp::Nack& nack)
114{
115 this->emitSignal(onSendNack, nack);
116 m_face->sendNack(nack);
117}
118
119inline void
120LpFaceWrapper::close()
121{
122 m_face->close();
123}
124
125inline bool
126LpFaceWrapper::isUp() const
127{
128 return m_face->getState() == FaceState::UP;
129}
130
131inline const FaceCounters&
132LpFaceWrapper::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