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 | 9b0d3e9 | 2014-02-15 12:27:12 -0700 | [diff] [blame] | 24 | /** \brief represents a face |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 25 | */ |
Alexander Afanasyev | d32cb96 | 2014-01-28 12:43:47 -0800 | [diff] [blame] | 26 | class Face : noncopyable, public enable_shared_from_this<Face> |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 27 | { |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 28 | public: |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 29 | /** |
| 30 | * \brief Face-related error |
| 31 | */ |
| 32 | struct Error : public std::runtime_error |
| 33 | { |
| 34 | Error(const std::string& what) : std::runtime_error(what) {} |
| 35 | }; |
| 36 | |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 37 | Face(); |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 38 | |
| 39 | virtual |
| 40 | ~Face(); |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 41 | |
| 42 | FaceId |
| 43 | getId() const; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 44 | |
| 45 | /// fires when an Interest is received |
Alexander Afanasyev | d6cf455 | 2014-02-11 17:15:22 -0800 | [diff] [blame] | 46 | EventEmitter<Interest> onReceiveInterest; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 47 | |
| 48 | /// fires when a Data is received |
Alexander Afanasyev | d6cf455 | 2014-02-11 17:15:22 -0800 | [diff] [blame] | 49 | EventEmitter<Data> onReceiveData; |
Alexander Afanasyev | d32cb96 | 2014-01-28 12:43:47 -0800 | [diff] [blame] | 50 | |
| 51 | /// fires when face disconnects or fails to perform properly |
Alexander Afanasyev | d6cf455 | 2014-02-11 17:15:22 -0800 | [diff] [blame] | 52 | EventEmitter<std::string/*reason*/> onFail; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 53 | |
| 54 | /// send an Interest |
| 55 | virtual void |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 56 | sendInterest(const Interest& interest) = 0; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 57 | |
| 58 | /// send a Data |
| 59 | virtual void |
Alexander Afanasyev | a9034b0 | 2014-01-26 18:32:02 -0800 | [diff] [blame] | 60 | sendData(const Data& data) = 0; |
Alexander Afanasyev | a0a10fb | 2014-02-13 19:56:15 -0800 | [diff] [blame] | 61 | |
| 62 | /** |
| 63 | * \brief Close the face |
| 64 | * |
| 65 | * This terminates all communication on the face and cause |
| 66 | * onFail() method event to be invoked |
| 67 | */ |
| 68 | virtual void |
| 69 | close() = 0; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 70 | |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 71 | /** \brief Get whether underlying communication is up |
| 72 | * |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 73 | * In this base class this property is always true. |
| 74 | */ |
| 75 | virtual bool |
| 76 | isUp() const; |
| 77 | |
| 78 | /** \brief Set the description |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 79 | * |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 80 | * This is typically invoked by mgmt on set description command |
| 81 | */ |
| 82 | virtual void |
| 83 | setDescription(const std::string& description); |
| 84 | |
| 85 | /// Get the description |
| 86 | virtual const std::string& |
| 87 | getDescription() const; |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 88 | |
| 89 | /** \brief Get whether face is connected to a local app |
| 90 | * |
| 91 | * In this base class this property is always false. |
| 92 | */ |
| 93 | virtual bool |
| 94 | isLocal() const; |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 95 | |
| 96 | /** \brief Get whether packets sent this Face may reach multiple peers |
Junxiao Shi | 8888449 | 2014-02-15 15:57:43 -0700 | [diff] [blame] | 97 | * |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 98 | * In this base class this property is always false. |
| 99 | */ |
| 100 | virtual bool |
| 101 | isMultiAccess() const; |
| 102 | |
| 103 | /// Get whether the face has opted in for local control header |
| 104 | virtual bool |
| 105 | isLocalControlHeaderEnabled() const; |
| 106 | |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 107 | private: |
Alexander Afanasyev | 46f6647 | 2014-01-31 16:50:58 -0800 | [diff] [blame] | 108 | void |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 109 | setId(FaceId faceId); |
| 110 | |
| 111 | private: |
Junxiao Shi | 32bfeb3 | 2014-01-25 18:22:02 -0700 | [diff] [blame] | 112 | FaceId m_id; |
| 113 | std::string m_description; |
Junxiao Shi | 8c8d218 | 2014-01-30 22:33:00 -0700 | [diff] [blame] | 114 | |
| 115 | // allow setting FaceId |
| 116 | friend class Forwarder; |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Alexander Afanasyev | 18bbf81 | 2014-01-29 01:40:23 -0800 | [diff] [blame] | 119 | } // namespace nfd |
Junxiao Shi | 2c29f3a | 2014-01-24 19:59:00 -0700 | [diff] [blame] | 120 | |
| 121 | #endif // NFD_FACE_FACE_H |