From 32bfeb3401e625d2e5c1ebad87ddb4923e0463ff Mon Sep 17 00:00:00 2001 From: Junxiao Shi Date: Sat, 25 Jan 2014 18:22:02 -0700 Subject: [PATCH] abstract Face class refs #1153 Change-Id: I0b0dd71300d9b2d747a48c72fa8850c9afb75448 --- daemon/face/face.cpp | 52 ++++++++++++++++++++++++++++++++++++++++ daemon/face/face.hpp | 57 ++++++++++++++++++++++++++++++++++++++++++++ tests/face/face.cpp | 26 +++++++++++++++++++- 3 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 daemon/face/face.cpp diff --git a/daemon/face/face.cpp b/daemon/face/face.cpp new file mode 100644 index 00000000..1aa51842 --- /dev/null +++ b/daemon/face/face.cpp @@ -0,0 +1,52 @@ +/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ +/** + * Copyright (C) 2014 Named Data Networking Project + * See COPYING for copyright and distribution information. + */ + +#include "face.hpp" + +namespace ndn { + +Face::Face(FaceId id) + : m_id(id) +{ +} + +Face::~Face() +{ +} + +bool +Face::isUp() const +{ + return true; +} + +void +Face::setDescription(const std::string& description) +{ + m_description = description; +} + +const std::string& +Face::getDescription() const +{ + return m_description; +} + +bool +Face::isMultiAccess() const +{ + return false; +} + +bool +Face::isLocalControlHeaderEnabled() const +{ + // TODO add local control header functionality + return false; +} + + +} //namespace ndn diff --git a/daemon/face/face.hpp b/daemon/face/face.hpp index 0a758b3a..abcb3ab7 100644 --- a/daemon/face/face.hpp +++ b/daemon/face/face.hpp @@ -8,6 +8,7 @@ #define NFD_FACE_FACE_H #include "common.hpp" +#include "util/event-emitter.hpp" namespace ndn { @@ -21,6 +22,62 @@ typedef int FaceId; */ class Face : noncopyable { +public: + Face(FaceId id); + + virtual + ~Face(); + + /// fires when an Interest is received + EventEmitter onReceiveInterest; + + /// fires when a Data is received + EventEmitter onReceiveData; + + /// send an Interest + virtual void + sendInterest(const Interest &interest) =0; + + /// send a Data + virtual void + sendData(const Data &data) =0; + + /** \brief Get whether underlying communicate is up + * In this base class this property is always true. + */ + virtual bool + isUp() const; + + /** \brief Set the description + * This is typically invoked by mgmt on set description command + */ + virtual void + setDescription(const std::string& description); + + /// Get the description + virtual const std::string& + getDescription() const; + + /** \brief Get whether packets sent this Face may reach multiple peers + * In this base class this property is always false. + */ + virtual bool + isMultiAccess() const; + + /// Get whether the face has opted in for local control header + virtual bool + isLocalControlHeaderEnabled() const; + +protected: + // void + // receiveInterest(); + + // void + // receiveData(); + +private: + FaceId m_id; + std::string m_description; }; } // namespace ndn diff --git a/tests/face/face.cpp b/tests/face/face.cpp index 93a78ecf..b453110e 100644 --- a/tests/face/face.cpp +++ b/tests/face/face.cpp @@ -12,7 +12,31 @@ namespace ndn { BOOST_AUTO_TEST_SUITE(FaceFace) -// no unit test here: this ensures face.hpp can compile on its own +class FaceTestFace : public Face +{ +public: + FaceTestFace() + : Face(1) + { + } + + virtual void + sendInterest(const Interest &interest) + { + } + + virtual void + sendData(const Data &data) + { + } +}; + +BOOST_AUTO_TEST_CASE(Description) +{ + FaceTestFace face; + face.setDescription("3pFsKrvWr"); + BOOST_CHECK_EQUAL(face.getDescription(), "3pFsKrvWr"); +} BOOST_AUTO_TEST_SUITE_END()