blob: 920997a6c14c55a9430a45e31db1102b6fa050ba [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#include "lp-face-wrapper.hpp"
27
28namespace nfd {
29namespace face {
30
31LpFaceWrapper::LpFaceWrapper(unique_ptr<LpFace> face)
32 : Face(face->getRemoteUri(), face->getLocalUri(),
33 face->getScope() == ndn::nfd::FACE_SCOPE_LOCAL,
34 face->getLinkType() == ndn::nfd::LINK_TYPE_MULTI_ACCESS)
35 , m_face(std::move(face))
36{
37 this->Face::setPersistency(m_face->getPersistency());
38 m_face->afterReceiveInterest.connect(bind(&LpFaceWrapper::dispatchInterest, this, _1));
39 m_face->afterReceiveData.connect(bind(&LpFaceWrapper::dispatchData, this, _1));
40 m_face->afterReceiveNack.connect(bind(&LpFaceWrapper::dispatchNack, this, _1));
41 m_face->afterStateChange.connect(bind(&LpFaceWrapper::handleStateChange, this, _1, _2));
42}
43
44void
45LpFaceWrapper::setPersistency(ndn::nfd::FacePersistency persistency)
46{
47 this->Face::setPersistency(persistency);
48 m_face->setPersistency(persistency);
49}
50
51void
52LpFaceWrapper::setId(nfd::FaceId faceId)
53{
54 this->Face::setId(faceId);
55
56 FaceId lpId = static_cast<FaceId>(faceId);
57 if (faceId == nfd::INVALID_FACEID) {
58 lpId = INVALID_FACEID;
59 }
60 m_face->setId(lpId);
61}
62
63void
64LpFaceWrapper::dispatchInterest(const Interest& interest)
65{
66 this->emitSignal(onReceiveInterest, interest);
67}
68
69void
70LpFaceWrapper::dispatchData(const Data& data)
71{
72 this->emitSignal(onReceiveData, data);
73}
74
75void
76LpFaceWrapper::dispatchNack(const ndn::lp::Nack& nack)
77{
78 this->emitSignal(onReceiveNack, nack);
79}
80
81void
82LpFaceWrapper::handleStateChange(FaceState oldState, FaceState newState)
83{
84 if (newState != FaceState::CLOSED) {
85 return;
86 }
87
88 switch (oldState) {
89 case FaceState::CLOSING:
90 this->fail("LpFace closed");
91 break;
92 case FaceState::FAILED:
93 this->fail("LpFace failed");
94 break;
95 default:
96 BOOST_ASSERT(false);
97 break;
98 }
99}
100
101} // namespace face
102} // namespace nfd