Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -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 | #ifndef NFD_FACE_FACE_H |
| 8 | #define NFD_FACE_FACE_H |
| 9 | |
| 10 | #include "common.hpp" |
Junxiao Shi | 7f02c1e | 2014-01-29 22:57:01 -0700 | [diff] [blame] | 11 | #include "core/event-emitter.hpp" |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 12 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 13 | namespace nfd { |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 14 | |
| 15 | /** \class FaceId |
| 16 | * \brief identifies a face |
| 17 | */ |
| 18 | typedef int FaceId; |
| 19 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 20 | const FaceId INVALID_FACEID = -1; |
| 21 | |
Alexander Afanasyev | d32cb96 | 2014-01-28 12:43:47 -0800 | [diff] [blame] | 22 | const std::size_t MAX_NDN_PACKET_SIZE = 8800; |
| 23 | |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 24 | /** \class Face |
| 25 | * \brief represents a face |
| 26 | */ |
Alexander Afanasyev | d32cb96 | 2014-01-28 12:43:47 -0800 | [diff] [blame] | 27 | class Face : noncopyable, public enable_shared_from_this<Face> |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 28 | { |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 29 | public: |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 30 | Face(); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 31 | |
| 32 | virtual |
| 33 | ~Face(); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 34 | |
| 35 | FaceId |
| 36 | getId() const; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 37 | |
| 38 | /// fires when an Interest is received |
| 39 | EventEmitter<const Interest&> onReceiveInterest; |
| 40 | |
| 41 | /// fires when a Data is received |
| 42 | EventEmitter<const Data&> onReceiveData; |
Alexander Afanasyev | d32cb96 | 2014-01-28 12:43:47 -0800 | [diff] [blame] | 43 | |
| 44 | /// fires when face disconnects or fails to perform properly |
| 45 | EventEmitter<const std::string& /*reason*/> onFail; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 46 | |
| 47 | /// send an Interest |
| 48 | virtual void |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 49 | sendInterest(const Interest& interest) = 0; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 50 | |
| 51 | /// send a Data |
| 52 | virtual void |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 53 | sendData(const Data& data) = 0; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 54 | |
| 55 | /** \brief Get whether underlying communicate is up |
| 56 | * In this base class this property is always true. |
| 57 | */ |
| 58 | virtual bool |
| 59 | isUp() const; |
| 60 | |
| 61 | /** \brief Set the description |
| 62 | * This is typically invoked by mgmt on set description command |
| 63 | */ |
| 64 | virtual void |
| 65 | setDescription(const std::string& description); |
| 66 | |
| 67 | /// Get the description |
| 68 | virtual const std::string& |
| 69 | getDescription() const; |
| 70 | |
| 71 | /** \brief Get whether packets sent this Face may reach multiple peers |
| 72 | * In this base class this property is always false. |
| 73 | */ |
| 74 | virtual bool |
| 75 | isMultiAccess() const; |
| 76 | |
| 77 | /// Get whether the face has opted in for local control header |
| 78 | virtual bool |
| 79 | isLocalControlHeaderEnabled() const; |
| 80 | |
| 81 | protected: |
| 82 | // void |
| 83 | // receiveInterest(); |
| 84 | |
| 85 | // void |
| 86 | // receiveData(); |
| 87 | |
| 88 | private: |
Alexander Afanasyev | 46f6647 | 2014-01-31 16:50:58 -0800 | [diff] [blame^] | 89 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 90 | setId(FaceId faceId); |
| 91 | |
| 92 | private: |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 93 | FaceId m_id; |
| 94 | std::string m_description; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 95 | |
| 96 | // allow setting FaceId |
| 97 | friend class Forwarder; |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 100 | } // namespace nfd |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 101 | |
| 102 | #endif // NFD_FACE_FACE_H |