blob: a3013f6137c58e0f612aaf0a0d71694fae5a277f [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,
34 &m_forwarder, boost::ref(*face), _1);
35 face->onReceiveData += bind(&Forwarder::onData,
36 &m_forwarder, boost::ref(*face), _1);
37}
38
39void
40FaceTable::remove(shared_ptr<Face> face)
41{
42 FaceId faceId = face->getId();
43 m_faces.erase(faceId);
44 face->setId(INVALID_FACEID);
45 NFD_LOG_INFO("removeFace id=" << faceId);
46
47 // XXX This clears all subscriptions, because EventEmitter
48 // does not support only removing Forwarder's subscription
49 face->onReceiveInterest.clear();
50 face->onReceiveData .clear();
51
52 m_forwarder.getFib().removeNextHopFromAllEntries(face);
53}
54
Steve DiBenedettoabe9e972014-02-20 15:37:04 -070055
56
Junxiao Shia4f2be82014-03-02 22:56:41 -070057} // namespace nfd