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 | |
| 20 | void |
| 21 | FaceTable::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 | |
| 34 | void |
| 35 | FaceTable::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 |