blob: 543fc81209e6555e716de2de76b9ec8436fdf23c [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:
Junxiao Shi8c8d2182014-01-30 22:33:00 -070030 Face();
Junxiao Shi32bfeb32014-01-25 18:22:02 -070031
32 virtual
33 ~Face();
Junxiao Shi8c8d2182014-01-30 22:33:00 -070034
35 FaceId
36 getId() const;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070037
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 Afanasyevd32cb962014-01-28 12:43:47 -080043
44 /// fires when face disconnects or fails to perform properly
45 EventEmitter<const std::string& /*reason*/> onFail;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070046
47 /// send an Interest
48 virtual void
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080049 sendInterest(const Interest& interest) = 0;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070050
51 /// send a Data
52 virtual void
Alexander Afanasyeva9034b02014-01-26 18:32:02 -080053 sendData(const Data& data) = 0;
Junxiao Shi32bfeb32014-01-25 18:22:02 -070054
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
81protected:
82 // void
83 // receiveInterest();
84
85 // void
86 // receiveData();
87
88private:
Alexander Afanasyev46f66472014-01-31 16:50:58 -080089 void
Junxiao Shi8c8d2182014-01-30 22:33:00 -070090 setId(FaceId faceId);
91
92private:
Junxiao Shi32bfeb32014-01-25 18:22:02 -070093 FaceId m_id;
94 std::string m_description;
Junxiao Shi8c8d2182014-01-30 22:33:00 -070095
96 // allow setting FaceId
97 friend class Forwarder;
Junxiao Shi2c29f3a2014-01-24 19:59:00 -070098};
99
Alexander Afanasyev18bbf812014-01-29 01:40:23 -0800100} // namespace nfd
Junxiao Shi2c29f3a2014-01-24 19:59:00 -0700101
102#endif // NFD_FACE_FACE_H