blob: 08853aa974c7da12d66edc1fe9f9d095235094da [file] [log] [blame]
Junxiao Shi32bfeb32014-01-25 18:22:02 -07001/* -*- 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 Shi16b8bc92014-02-17 22:24:55 -07008#include "core/logger.hpp"
Junxiao Shi32bfeb32014-01-25 18:22:02 -07009
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080010namespace nfd {
Junxiao Shi32bfeb32014-01-25 18:22:02 -070011
Davide Pesavento0ff10db2014-02-28 03:12:27 +010012NFD_LOG_INIT("Face")
Junxiao Shi16b8bc92014-02-17 22:24:55 -070013
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000014template<class Packet>
15static inline void
16increaseCounter(const Packet& packet, FaceCounter& counter)
17{
18 ++counter;
19}
20
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000021Face::Face(const FaceUri& uri, bool isLocal)
Junxiao Shi8c8d2182014-01-30 22:33:00 -070022 : m_id(INVALID_FACEID)
Davide Pesavento0ff10db2014-02-28 03:12:27 +010023 , m_isLocal(isLocal)
Alexander Afanasyeva39b90b2014-03-05 15:31:00 +000024 , m_uri(uri)
Alexander Afanasyev355c0662014-03-20 18:08:17 -070025 , m_isOnDemand(false)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070026{
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000027 onReceiveInterest += bind(&increaseCounter<Interest>, _1, boost::ref(m_counters.getInInterest()));
28 onReceiveData += bind(&increaseCounter<Data>, _1, boost::ref(m_counters.getInData()));
29 onSendInterest += bind(&increaseCounter<Interest>, _1, boost::ref(m_counters.getOutInterest()));
30 onSendData += bind(&increaseCounter<Data>, _1, boost::ref(m_counters.getOutData()));
Junxiao Shi32bfeb32014-01-25 18:22:02 -070031}
32
33Face::~Face()
34{
35}
36
Junxiao Shi8c8d2182014-01-30 22:33:00 -070037FaceId
38Face::getId() const
39{
40 return m_id;
41}
42
Alexander Afanasyev46f66472014-01-31 16:50:58 -080043// this method is private and should be used only by the Forwarder
44void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070045Face::setId(FaceId faceId)
46{
47 m_id = faceId;
48}
49
Junxiao Shi32bfeb32014-01-25 18:22:02 -070050void
51Face::setDescription(const std::string& description)
52{
53 m_description = description;
54}
55
56const std::string&
57Face::getDescription() const
58{
59 return m_description;
60}
61
62bool
63Face::isMultiAccess() const
64{
65 return false;
66}
67
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080068bool
Davide Pesavento0ff10db2014-02-28 03:12:27 +010069Face::isUp() const
70{
71 return true;
72}
73
74bool
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080075Face::decodeAndDispatchInput(const Block& element)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070076{
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080077 /// \todo Ensure lazy field decoding process
Alexander Afanasyev355c0662014-03-20 18:08:17 -070078
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080079 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 Afanasyev355c0662014-03-20 18:08:17 -070093
Alexander Afanasyevbd220a02014-02-20 00:29:56 -080094 return true;
Junxiao Shi16b8bc92014-02-17 22:24:55 -070095}
Junxiao Shi32bfeb32014-01-25 18:22:02 -070096
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080097} //namespace nfd