blob: 68b80730f96c8e9de63a529745842e13507d6e5f [file] [log] [blame]
Junxiao Shi2c29f3a2014-01-24 19:59:00 -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#ifndef NFD_FACE_FACE_H
8#define NFD_FACE_FACE_H
9
10#include "common.hpp"
Junxiao Shi7f02c1e2014-01-29 22:57:01 -070011#include "core/event-emitter.hpp"
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070012
Alexander Afanasyev18bbf812014-01-29 01:40:23 -080013namespace nfd {
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070014
15/** \class FaceId
16 * \brief identifies a face
17 */
18typedef int FaceId;
19
Junxiao Shi8c8d2182014-01-30 22:33:00 -070020const FaceId INVALID_FACEID = -1;
21
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080022const std::size_t MAX_NDN_PACKET_SIZE = 8800;
23
Junxiao Shi9b0d3e92014-02-15 12:27:12 -070024/** \brief represents a face
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070025 */
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080026class Face : noncopyable, public enable_shared_from_this<Face>
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070027{
Junxiao Shi32bfeb32014-01-25 18:22:02 -070028public:
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080029 /**
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 Shi8c8d2182014-01-30 22:33:00 -070037 Face();
Junxiao Shi32bfeb32014-01-25 18:22:02 -070038
39 virtual
40 ~Face();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070041
42 FaceId
43 getId() const;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070044
45 /// fires when an Interest is received
Alexander Afanasyevd6cf4552014-02-11 17:15:22 -080046 EventEmitter<Interest> onReceiveInterest;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070047
48 /// fires when a Data is received
Alexander Afanasyevd6cf4552014-02-11 17:15:22 -080049 EventEmitter<Data> onReceiveData;
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080050
51 /// fires when face disconnects or fails to perform properly
Alexander Afanasyevd6cf4552014-02-11 17:15:22 -080052 EventEmitter<std::string/*reason*/> onFail;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070053
54 /// send an Interest
55 virtual void
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080056 sendInterest(const Interest& interest) = 0;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070057
58 /// send a Data
59 virtual void
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080060 sendData(const Data& data) = 0;
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080061
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 Shi32bfeb32014-01-25 18:22:02 -070070
Junxiao Shi88884492014-02-15 15:57:43 -070071 /** \brief Get whether underlying communication is up
72 *
Junxiao Shi32bfeb32014-01-25 18:22:02 -070073 * In this base class this property is always true.
74 */
75 virtual bool
76 isUp() const;
77
78 /** \brief Set the description
Junxiao Shi88884492014-02-15 15:57:43 -070079 *
Junxiao Shi32bfeb32014-01-25 18:22:02 -070080 * 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 Shi88884492014-02-15 15:57:43 -070088
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 Shi32bfeb32014-01-25 18:22:02 -070095
96 /** \brief Get whether packets sent this Face may reach multiple peers
Junxiao Shi88884492014-02-15 15:57:43 -070097 *
Junxiao Shi32bfeb32014-01-25 18:22:02 -070098 * 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 Shi32bfeb32014-01-25 18:22:02 -0700107private:
Alexander Afanasyev46f66472014-01-31 16:50:58 -0800108 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700109 setId(FaceId faceId);
110
111private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700112 FaceId m_id;
113 std::string m_description;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700114
115 // allow setting FaceId
116 friend class Forwarder;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700117};
118
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800119} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700120
121#endif // NFD_FACE_FACE_H