Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -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.hpp" |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 8 | #include "core/logger.hpp" |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 9 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 10 | namespace nfd { |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 11 | |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 12 | NFD_LOG_INIT("Face") |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 13 | |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 14 | template<class Packet> |
| 15 | static inline void |
| 16 | increaseCounter(const Packet& packet, FaceCounter& counter) |
| 17 | { |
| 18 | ++counter; |
| 19 | } |
| 20 | |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 21 | Face::Face(const FaceUri& uri, bool isLocal) |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 22 | : m_id(INVALID_FACEID) |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 23 | , m_isLocal(isLocal) |
Alexander Afanasyev | a39b90b | 2014-03-05 15:31:00 +0000 | [diff] [blame] | 24 | , m_uri(uri) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 25 | { |
Alexander Afanasyev | 7e698e6 | 2014-03-07 16:48:35 +0000 | [diff] [blame] | 26 | onReceiveInterest += bind(&increaseCounter<Interest>, _1, boost::ref(m_counters.getInInterest())); |
| 27 | onReceiveData += bind(&increaseCounter<Data>, _1, boost::ref(m_counters.getInData())); |
| 28 | onSendInterest += bind(&increaseCounter<Interest>, _1, boost::ref(m_counters.getOutInterest())); |
| 29 | onSendData += bind(&increaseCounter<Data>, _1, boost::ref(m_counters.getOutData())); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | Face::~Face() |
| 33 | { |
| 34 | } |
| 35 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 36 | FaceId |
| 37 | Face::getId() const |
| 38 | { |
| 39 | return m_id; |
| 40 | } |
| 41 | |
Alexander Afanasyev | 46f6647 | 2014-01-31 16:50:58 -0800 | [diff] [blame] | 42 | // this method is private and should be used only by the Forwarder |
| 43 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 44 | Face::setId(FaceId faceId) |
| 45 | { |
| 46 | m_id = faceId; |
| 47 | } |
| 48 | |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 49 | void |
| 50 | Face::setDescription(const std::string& description) |
| 51 | { |
| 52 | m_description = description; |
| 53 | } |
| 54 | |
| 55 | const std::string& |
| 56 | Face::getDescription() const |
| 57 | { |
| 58 | return m_description; |
| 59 | } |
| 60 | |
| 61 | bool |
| 62 | Face::isMultiAccess() const |
| 63 | { |
| 64 | return false; |
| 65 | } |
| 66 | |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 67 | bool |
Davide Pesavento | 0ff10db | 2014-02-28 03:12:27 +0100 | [diff] [blame] | 68 | Face::isUp() const |
| 69 | { |
| 70 | return true; |
| 71 | } |
| 72 | |
| 73 | bool |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 74 | Face::decodeAndDispatchInput(const Block& element) |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 75 | { |
Alexander Afanasyev | bd220a0 | 2014-02-20 00:29:56 -0800 | [diff] [blame] | 76 | /// \todo Ensure lazy field decoding process |
| 77 | |
| 78 | if (element.type() == tlv::Interest) |
| 79 | { |
| 80 | shared_ptr<Interest> i = make_shared<Interest>(); |
| 81 | i->wireDecode(element); |
| 82 | this->onReceiveInterest(*i); |
| 83 | } |
| 84 | else if (element.type() == tlv::Data) |
| 85 | { |
| 86 | shared_ptr<Data> d = make_shared<Data>(); |
| 87 | d->wireDecode(element); |
| 88 | this->onReceiveData(*d); |
| 89 | } |
| 90 | else |
| 91 | return false; |
| 92 | |
| 93 | return true; |
Junxiao Shi | 16b8bc9 | 2014-02-17 22:24:55 -0700 | [diff] [blame] | 94 | } |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 95 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 96 | } //namespace nfd |