blob: 6e06438c267cd9607ad01dd7fd4fddc1d19484a3 [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
20void
21FaceTable::add(shared_ptr<Face> face)
22{
23 FaceId faceId = ++m_lastFaceId;
24 face->setId(faceId);
25 m_faces[faceId] = face;
26 NFD_LOG_INFO("addFace id=" << faceId);
27
28 face->onReceiveInterest += bind(&Forwarder::onInterest,
29 &m_forwarder, boost::ref(*face), _1);
30 face->onReceiveData += bind(&Forwarder::onData,
31 &m_forwarder, boost::ref(*face), _1);
32}
33
34void
35FaceTable::remove(shared_ptr<Face> face)
36{
37 FaceId faceId = face->getId();
38 m_faces.erase(faceId);
39 face->setId(INVALID_FACEID);
40 NFD_LOG_INFO("removeFace id=" << faceId);
41
42 // XXX This clears all subscriptions, because EventEmitter
43 // does not support only removing Forwarder's subscription
44 face->onReceiveInterest.clear();
45 face->onReceiveData .clear();
46
47 m_forwarder.getFib().removeNextHopFromAllEntries(face);
48}
49
50} // namespace nfd