blob: e2aa62d54a7937e1e8cd1507df97976a1221f5b6 [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
72 /** \brief Get whether underlying communicate is up
73 * In this base class this property is always true.
74 */
75 virtual bool
76 isUp() const;
77
78 /** \brief Set the description
79 * This is typically invoked by mgmt on set description command
80 */
81 virtual void
82 setDescription(const std::string& description);
83
84 /// Get the description
85 virtual const std::string&
86 getDescription() const;
87
88 /** \brief Get whether packets sent this Face may reach multiple peers
89 * In this base class this property is always false.
90 */
91 virtual bool
92 isMultiAccess() const;
93
94 /// Get whether the face has opted in for local control header
95 virtual bool
96 isLocalControlHeaderEnabled() const;
97
98protected:
99 // void
100 // receiveInterest();
101
102 // void
103 // receiveData();
104
105private:
Alexander Afanasyev46f66472014-01-31 16:50:58 -0800106 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700107 setId(FaceId faceId);
108
109private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -0700110 FaceId m_id;
111 std::string m_description;
Junxiao Shi8c8d2182014-01-30 22:33:00 -0700112
113 // allow setting FaceId
114 friend class Forwarder;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700115};
116
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800117} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700118
119#endif // NFD_FACE_FACE_H