blob: 35bf3774a51474d4708ae39d87a33bad0a887512 [file] [log] [blame]
Junxiao Shia4f2be82014-03-02 22:56:41 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (C) 2014 Named Data Networking Project
4 * See COPYING for copyright and distribution information.
5 */
6
7#include "face-table.hpp"
8#include "forwarder.hpp"
9
10namespace nfd {
11
12NFD_LOG_INIT("FaceTable");
13
14FaceTable::FaceTable(Forwarder& forwarder)
15 : m_forwarder(forwarder)
16 , m_lastFaceId(0)
17{
18}
19
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070020FaceTable::~FaceTable()
21{
22
23}
24
Junxiao Shia4f2be82014-03-02 22:56:41 -070025void
26FaceTable::add(shared_ptr<Face> face)
27{
28 FaceId faceId = ++m_lastFaceId;
29 face->setId(faceId);
30 m_faces[faceId] = face;
31 NFD_LOG_INFO("addFace id=" << faceId);
32
33 face->onReceiveInterest += bind(&Forwarder::onInterest,
Junxiao Shic542b2b2014-03-16 21:45:52 -070034 &m_forwarder, boost::ref(*face), _1);
Junxiao Shia4f2be82014-03-02 22:56:41 -070035 face->onReceiveData += bind(&Forwarder::onData,
Junxiao Shic542b2b2014-03-16 21:45:52 -070036 &m_forwarder, boost::ref(*face), _1);
37 face->onFail += bind(&FaceTable::remove,
38 this, face);
Junxiao Shibd392bf2014-03-17 15:54:11 -070039
40 this->onAdd(face);
Junxiao Shia4f2be82014-03-02 22:56:41 -070041}
42
43void
44FaceTable::remove(shared_ptr<Face> face)
45{
Junxiao Shibd392bf2014-03-17 15:54:11 -070046 this->onRemove(face);
47
Junxiao Shia4f2be82014-03-02 22:56:41 -070048 FaceId faceId = face->getId();
49 m_faces.erase(faceId);
50 face->setId(INVALID_FACEID);
51 NFD_LOG_INFO("removeFace id=" << faceId);
52
53 // XXX This clears all subscriptions, because EventEmitter
54 // does not support only removing Forwarder's subscription
55 face->onReceiveInterest.clear();
56 face->onReceiveData .clear();
Junxiao Shic542b2b2014-03-16 21:45:52 -070057 // don't clear onFail because other functions may need to execute
Junxiao Shia4f2be82014-03-02 22:56:41 -070058
59 m_forwarder.getFib().removeNextHopFromAllEntries(face);
60}
61
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070062
63
Junxiao Shia4f2be82014-03-02 22:56:41 -070064} // namespace nfd