face.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_HPP
27 #define NFD_DAEMON_FACE_HPP
28 
29 #include "transport.hpp"
30 #include "link-service.hpp"
31 #include "face-counters.hpp"
32 #include "face-log.hpp"
33 
34 namespace nfd {
35 namespace face {
36 
39 typedef uint64_t FaceId;
40 
42 const FaceId INVALID_FACEID = 0;
44 const FaceId FACEID_INTERNAL_FACE = 1;
46 const FaceId FACEID_CONTENT_STORE = 254;
48 const FaceId FACEID_NULL = 255;
50 const FaceId FACEID_RESERVED_MAX = 255;
51 
55 
67 class Face
68 #ifndef WITH_TESTS
69 final
70 #endif
71  : public enable_shared_from_this<Face>, noncopyable
72 {
73 public:
74  Face(unique_ptr<LinkService> service, unique_ptr<Transport> transport);
75 
77  getLinkService() const;
78 
79  Transport*
80  getTransport() const;
81 
82 public: // upper interface connected to forwarding
85  void
86  sendInterest(const Interest& interest);
87 
90  void
91  sendData(const Data& data);
92 
95  void
96  sendNack(const lp::Nack& nack);
97 
100  signal::Signal<LinkService, Interest>& afterReceiveInterest;
101 
104  signal::Signal<LinkService, Data>& afterReceiveData;
105 
108  signal::Signal<LinkService, lp::Nack>& afterReceiveNack;
109 
110 public: // static properties
113  FaceId
114  getId() const;
115 
119  void
120  setId(FaceId id);
121 
124  FaceUri
125  getLocalUri() const;
126 
129  FaceUri
130  getRemoteUri() const;
131 
134  ndn::nfd::FaceScope
135  getScope() const;
136 
139  ndn::nfd::FacePersistency
140  getPersistency() const;
141 
144  void
145  setPersistency(ndn::nfd::FacePersistency persistency);
146 
149  ndn::nfd::LinkType
150  getLinkType() const;
151 
152 public: // dynamic properties
155  FaceState
156  getState() const;
157 
160  signal::Signal<Transport, FaceState/*old*/, FaceState/*new*/>& afterStateChange;
161 
165  time::steady_clock::TimePoint
166  getExpirationTime() const;
167 
178  void
179  close();
180 
181  const FaceCounters&
182  getCounters() const;
183 
184 private:
185  FaceId m_id;
186  unique_ptr<LinkService> m_service;
187  unique_ptr<Transport> m_transport;
188  FaceCounters m_counters;
189 };
190 
191 inline LinkService*
193 {
194  return m_service.get();
195 }
196 
197 inline Transport*
199 {
200  return m_transport.get();
201 }
202 
203 inline void
204 Face::sendInterest(const Interest& interest)
205 {
206  m_service->sendInterest(interest);
207 }
208 
209 inline void
210 Face::sendData(const Data& data)
211 {
212  m_service->sendData(data);
213 }
214 
215 inline void
216 Face::sendNack(const lp::Nack& nack)
217 {
218  m_service->sendNack(nack);
219 }
220 
221 inline FaceId
222 Face::getId() const
223 {
224  return m_id;
225 }
226 
227 inline void
228 Face::setId(FaceId id)
229 {
230  m_id = id;
231 }
232 
233 inline FaceUri
235 {
236  return m_transport->getLocalUri();
237 }
238 
239 inline FaceUri
241 {
242  return m_transport->getRemoteUri();
243 }
244 
245 inline ndn::nfd::FaceScope
247 {
248  return m_transport->getScope();
249 }
250 
251 inline ndn::nfd::FacePersistency
253 {
254  return m_transport->getPersistency();
255 }
256 
257 inline void
258 Face::setPersistency(ndn::nfd::FacePersistency persistency)
259 {
260  return m_transport->setPersistency(persistency);
261 }
262 
263 inline ndn::nfd::LinkType
265 {
266  return m_transport->getLinkType();
267 }
268 
269 inline FaceState
271 {
272  return m_transport->getState();
273 }
274 
275 inline time::steady_clock::TimePoint
277 {
278  return m_transport->getExpirationTime();
279 }
280 
281 inline void
283 {
284  m_transport->close();
285 }
286 
287 inline const FaceCounters&
289 {
290  return m_counters;
291 }
292 
293 std::ostream&
294 operator<<(std::ostream& os, const FaceLogHelper<Face>& flh);
295 
296 template<typename T>
297 typename std::enable_if<std::is_base_of<Face, T>::value, std::ostream&>::type
298 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
299 {
300  return os << FaceLogHelper<Face>(flh.obj);
301 }
302 
303 } // namespace face
304 
305 using face::FaceId;
306 using face::Face;
307 
308 } // namespace nfd
309 
310 #endif // NFD_DAEMON_FACE_HPP
LinkService * getLinkService() const
Definition: face.hpp:192
TransportState
indicates the state of a transport
Definition: transport.hpp:41
void setPersistency(ndn::nfd::FacePersistency persistency)
changes face persistency setting
Definition: face.hpp:258
Transport * getTransport() const
Definition: face.hpp:198
signal::Signal< LinkService, lp::Nack > & afterReceiveNack
signals on Nack received
Definition: face.hpp:108
signal::Signal< LinkService, Interest > & afterReceiveInterest
signals on Interest received
Definition: face.hpp:100
const FaceId FACEID_INTERNAL_FACE
identifies the InternalFace used in management
Definition: face.hpp:44
const FaceCounters & getCounters() const
Definition: face.hpp:288
FaceUri getRemoteUri() const
Definition: face.hpp:240
FaceState getState() const
Definition: face.hpp:270
the lower part of a Face
Definition: transport.hpp:104
void setId(FaceId id)
sets face ID
Definition: face.hpp:228
void close()
request the face to be closed
Definition: face.hpp:282
signal::Signal< LinkService, Data > & afterReceiveData
signals on Data received
Definition: face.hpp:104
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
TransportState FaceState
indicates the state of a face
Definition: face.hpp:54
const FaceId FACEID_RESERVED_MAX
upper bound of reserved FaceIds
Definition: face.hpp:50
time::steady_clock::TimePoint getExpirationTime() const
Definition: face.hpp:276
generalization of a network interface
Definition: face.hpp:67
FaceId getId() const
Definition: face.hpp:222
void sendData(const Data &data)
sends Data on Face
Definition: face.hpp:210
gives access to counters provided by Face
FaceUri getLocalUri() const
Definition: face.hpp:234
Face(unique_ptr< LinkService > service, unique_ptr< Transport > transport)
Definition: face.cpp:31
ndn::nfd::LinkType getLinkType() const
Definition: face.hpp:264
void sendNack(const lp::Nack &nack)
sends Nack on Face
Definition: face.hpp:216
signal::Signal< Transport, FaceState, FaceState > & afterStateChange
signals after face state changed
Definition: face.hpp:160
const FaceId FACEID_NULL
identifies the NullFace that drops every packet
Definition: face.hpp:48
void sendInterest(const Interest &interest)
sends Interest on Face
Definition: face.hpp:204
uint64_t FaceId
identifies a face
Definition: face.hpp:39
const FaceId FACEID_CONTENT_STORE
identifies a packet comes from the ContentStore
Definition: face.hpp:46
ndn::nfd::FacePersistency getPersistency() const
Definition: face.hpp:252
ndn::nfd::FaceScope getScope() const
Definition: face.hpp:246
const FaceId INVALID_FACEID
indicates an invalid FaceId
Definition: face.hpp:42