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