blob: 58cccf6d89d213892de9e2a8adee3d27d163d594 [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 Shi2c29f3a2014-01-24 19:59:00 -070024/** \class Face
25 * \brief represents a face
26 */
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080027class Face : noncopyable, public enable_shared_from_this<Face>
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070028{
Junxiao Shi32bfeb32014-01-25 18:22:02 -070029public:
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080030 /**
31 * \brief Face-related error
32 */
33 struct Error : public std::runtime_error
34 {
35 Error(const std::string& what) : std::runtime_error(what) {}
36 };
37
Junxiao Shi8c8d2182014-01-30 22:33:00 -070038 Face();
Junxiao Shi32bfeb32014-01-25 18:22:02 -070039
40 virtual
41 ~Face();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070042
43 FaceId
44 getId() const;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070045
46 /// fires when an Interest is received
Alexander Afanasyevd6cf4552014-02-11 17:15:22 -080047 EventEmitter<Interest> onReceiveInterest;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070048
49 /// fires when a Data is received
Alexander Afanasyevd6cf4552014-02-11 17:15:22 -080050 EventEmitter<Data> onReceiveData;
Alexander Afanasyevd32cb962014-01-28 12:43:47 -080051
52 /// fires when face disconnects or fails to perform properly
Alexander Afanasyevd6cf4552014-02-11 17:15:22 -080053 EventEmitter<std::string/*reason*/> onFail;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070054
55 /// send an Interest
56 virtual void
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080057 sendInterest(const Interest& interest) = 0;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070058
59 /// send a Data
60 virtual void
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080061 sendData(const Data& data) = 0;
Alexander Afanasyeva0a10fb2014-02-13 19:56:15 -080062
63 /**
64 * \brief Close the face
65 *
66 * This terminates all communication on the face and cause
67 * onFail() method event to be invoked
68 */
69 virtual void
70 close() = 0;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070071
Junxiao Shi88884492014-02-15 15:57:43 -070072 /** \brief Get whether underlying communication is up
73 *
Junxiao Shi32bfeb32014-01-25 18:22:02 -070074 * In this base class this property is always true.
75 */
76 virtual bool
77 isUp() const;
78
79 /** \brief Set the description
Junxiao Shi88884492014-02-15 15:57:43 -070080 *
Junxiao Shi32bfeb32014-01-25 18:22:02 -070081 * This is typically invoked by mgmt on set description command
82 */
83 virtual void
84 setDescription(const std::string& description);
85
86 /// Get the description
87 virtual const std::string&
88 getDescription() const;
Junxiao Shi88884492014-02-15 15:57:43 -070089
90 /** \brief Get whether face is connected to a local app
91 *
92 * In this base class this property is always false.
93 */
94 virtual bool
95 isLocal() const;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070096
97 /** \brief Get whether packets sent this Face may reach multiple peers
Junxiao Shi88884492014-02-15 15:57:43 -070098 *
Junxiao Shi32bfeb32014-01-25 18:22:02 -070099 * In this base class this property is always false.
100 */
101 virtual bool
102 isMultiAccess() const;
103
104 /// Get whether the face has opted in for local control header
105 virtual bool
106 isLocalControlHeaderEnabled() const;
107
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700108private:
Alexander Afanasyev46f66472014-01-31 16:50:58 -0800109 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700110 setId(FaceId faceId);
111
112private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700113 FaceId m_id;
114 std::string m_description;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700115
116 // allow setting FaceId
117 friend class Forwarder;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700118};
119
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800120} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700121
122#endif // NFD_FACE_FACE_H