link-service.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
26 #ifndef NFD_DAEMON_FACE_LINK_SERVICE_HPP
27 #define NFD_DAEMON_FACE_LINK_SERVICE_HPP
28 
29 #include "core/counter.hpp"
30 #include "transport.hpp"
31 #include "face-log.hpp"
32 
33 namespace nfd {
34 namespace face {
35 
36 class Face;
37 
43 {
44 public:
48 
52 
56 
60 
64 
68 };
69 
73 class LinkService : protected virtual LinkServiceCounters, noncopyable
74 {
75 public:
79 
80 public:
81  LinkService();
82 
83  virtual
84  ~LinkService();
85 
89  void
90  setFaceAndTransport(Face& face, Transport& transport);
91 
94  const Face*
95  getFace() const;
96 
99  const Transport*
100  getTransport() const;
101 
104  Transport*
105  getTransport();
106 
107  virtual const Counters&
108  getCounters() const;
109 
110 public: // upper interface to be used by forwarding
114  void
115  sendInterest(const Interest& interest);
116 
120  void
121  sendData(const Data& data);
122 
126  void
127  sendNack(const ndn::lp::Nack& nack);
128 
131  signal::Signal<LinkService, Interest> afterReceiveInterest;
132 
135  signal::Signal<LinkService, Data> afterReceiveData;
136 
139  signal::Signal<LinkService, lp::Nack> afterReceiveNack;
140 
141 public: // lower interface to be invoked by Transport
144  void
146 
147 protected: // upper interface to be invoked in subclass (receive path termination)
150  void
151  receiveInterest(const Interest& interest);
152 
155  void
156  receiveData(const Data& data);
157 
160  void
161  receiveNack(const lp::Nack& nack);
162 
163 protected: // lower interface to be invoked in subclass (send path termination)
166  void
167  sendPacket(Transport::Packet&& packet);
168 
169 private: // upper interface to be overridden in subclass (send path entrypoint)
172  virtual void
173  doSendInterest(const Interest& interest) = 0;
174 
177  virtual void
178  doSendData(const Data& data) = 0;
179 
182  virtual void
183  doSendNack(const lp::Nack& nack) = 0;
184 
185 private: // lower interface to be overridden in subclass
186  virtual void
187  doReceivePacket(Transport::Packet&& packet) = 0;
188 
189 private:
190  Face* m_face;
191  Transport* m_transport;
192 };
193 
194 inline const Face*
196 {
197  return m_face;
198 }
199 
200 inline const Transport*
202 {
203  return m_transport;
204 }
205 
206 inline Transport*
208 {
209  return m_transport;
210 }
211 
212 inline const LinkService::Counters&
214 {
215  return *this;
216 }
217 
218 inline void
220 {
221  doReceivePacket(std::move(packet));
222 }
223 
224 inline void
226 {
227  m_transport->send(std::move(packet));
228 }
229 
230 std::ostream&
231 operator<<(std::ostream& os, const FaceLogHelper<LinkService>& flh);
232 
233 template<typename T>
234 typename std::enable_if<std::is_base_of<LinkService, T>::value &&
235  !std::is_same<LinkService, T>::value, std::ostream&>::type
236 operator<<(std::ostream& os, const FaceLogHelper<T>& flh)
237 {
238  return os << FaceLogHelper<LinkService>(flh.obj);
239 }
240 
241 } // namespace face
242 } // namespace nfd
243 
244 #endif // NFD_DAEMON_FACE_LINK_SERVICE_HPP
the lower part of a Face
Definition: transport.hpp:104
stores a packet along with the remote endpoint
Definition: transport.hpp:113
represents a counter of number of packets
Definition: counter.hpp:77
Copyright (c) 2014-2015, Regents of the University of California, Arizona Board of Regents...
Definition: algorithm.hpp:32
generalization of a network interface
Definition: face.hpp:67
void send(Packet &&packet)
send a link-layer packet
Definition: transport.cpp:99