Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 1 | /* -*- 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 | |
| 10 | namespace nfd { |
| 11 | |
| 12 | NFD_LOG_INIT("FaceTable"); |
| 13 | |
| 14 | FaceTable::FaceTable(Forwarder& forwarder) |
| 15 | : m_forwarder(forwarder) |
| 16 | , m_lastFaceId(0) |
| 17 | { |
| 18 | } |
| 19 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame^] | 20 | FaceTable::~FaceTable() |
| 21 | { |
| 22 | |
| 23 | } |
| 24 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 25 | void |
| 26 | FaceTable::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 | |
| 39 | void |
| 40 | FaceTable::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 DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame^] | 55 | |
| 56 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 57 | } // namespace nfd |