blob: 517b2302128ccd679a48c4fa25dd346853fac817 [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 +000014static inline void
Junxiao Shi79494162014-04-02 18:25:11 -070015increaseCounter(FaceCounter& counter)
Alexander Afanasyev7e698e62014-03-07 16:48:35 +000016{
17 ++counter;
18}
19
Junxiao Shi79494162014-04-02 18:25:11 -070020Face::Face(const FaceUri& remoteUri, const FaceUri& localUri, bool isLocal)
Junxiao Shi8c8d2182014-01-30 22:33:00 -070021 : m_id(INVALID_FACEID)
Davide Pesavento0ff10db2014-02-28 03:12:27 +010022 , m_isLocal(isLocal)
Junxiao Shi79494162014-04-02 18:25:11 -070023 , m_remoteUri(remoteUri)
24 , m_localUri(localUri)
Alexander Afanasyev355c0662014-03-20 18:08:17 -070025 , m_isOnDemand(false)
Junxiao Shi32bfeb32014-01-25 18:22:02 -070026{
Junxiao Shi6e694322014-04-03 10:27:13 -070027 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 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