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, |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 34 | &m_forwarder, boost::ref(*face), _1); |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 35 | face->onReceiveData += bind(&Forwarder::onData, |
Junxiao Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 36 | &m_forwarder, boost::ref(*face), _1); |
| 37 | face->onFail += bind(&FaceTable::remove, |
| 38 | this, face); |
Junxiao Shi | bd392bf | 2014-03-17 15:54:11 -0700 | [diff] [blame^] | 39 | |
| 40 | this->onAdd(face); |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void |
| 44 | FaceTable::remove(shared_ptr<Face> face) |
| 45 | { |
Junxiao Shi | bd392bf | 2014-03-17 15:54:11 -0700 | [diff] [blame^] | 46 | this->onRemove(face); |
| 47 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 48 | 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 Shi | c542b2b | 2014-03-16 21:45:52 -0700 | [diff] [blame] | 57 | // don't clear onFail because other functions may need to execute |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 58 | |
| 59 | m_forwarder.getFib().removeNextHopFromAllEntries(face); |
| 60 | } |
| 61 | |
Steve DiBenedetto | abe9e97 | 2014-02-20 15:37:04 -0700 | [diff] [blame] | 62 | |
| 63 | |
Junxiao Shi | a4f2be8 | 2014-03-02 22:56:41 -0700 | [diff] [blame] | 64 | } // namespace nfd |