NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.3: NDN, CCN, CCNx, content centric networks
API Documentation
transport.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
22 #ifndef NDN_TRANSPORT_TRANSPORT_HPP
23 #define NDN_TRANSPORT_TRANSPORT_HPP
24 
25 #include "../common.hpp"
26 #include "../encoding/block.hpp"
27 
28 #include <boost/system/error_code.hpp>
29 
30 namespace boost {
31 namespace asio {
32 class io_service;
33 } // namespace asio
34 } // namespace boost
35 
36 namespace ndn {
37 
40 class Transport : noncopyable
41 {
42 public:
43  class Error : public std::runtime_error
44  {
45  public:
46  Error(const boost::system::error_code& code, const std::string& msg);
47 
48  explicit
49  Error(const std::string& msg);
50  };
51 
52  typedef function<void(const Block& wire)> ReceiveCallback;
53  typedef function<void()> ErrorCallback;
54 
55  Transport();
56 
57  virtual
58  ~Transport() = default;
59 
65  virtual void
66  connect(boost::asio::io_service& ioService, const ReceiveCallback& receiveCallback);
67 
70  virtual void
71  close() = 0;
72 
75  virtual void
76  send(const Block& wire) = 0;
77 
83  virtual void
84  send(const Block& header, const Block& payload) = 0;
85 
91  virtual void
92  pause() = 0;
93 
99  virtual void
100  resume() = 0;
101 
105  bool
106  isConnected() const;
107 
111  bool
112  isReceiving() const;
113 
114 protected:
117  void
118  receive(const Block& wire);
119 
120 protected:
121  boost::asio::io_service* m_ioService;
124  ReceiveCallback m_receiveCallback;
125 };
126 
127 inline bool
128 Transport::isConnected() const
129 {
130  return m_isConnected;
131 }
132 
133 inline bool
134 Transport::isReceiving() const
135 {
136  return m_isReceiving;
137 }
138 
139 inline void
140 Transport::receive(const Block& wire)
141 {
142  m_receiveCallback(wire);
143 }
144 
145 } // namespace ndn
146 
147 #endif // NDN_TRANSPORT_TRANSPORT_HPP
Copyright (c) 2011-2015 Regents of the University of California.
Copyright (c) 2013-2017 Regents of the University of California.
Represents a TLV element of NDN packet format.
Definition: block.hpp:42
ReceiveCallback m_receiveCallback
Definition: transport.hpp:124
function< void()> ErrorCallback
Definition: transport.hpp:53
boost::asio::io_service * m_ioService
Definition: transport.hpp:121
void close(T *e, websocketpp::connection_hdl hdl)
provides TLV-block delivery service
Definition: transport.hpp:40
function< void(const Block &wire)> ReceiveCallback
Definition: transport.hpp:52