NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: 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/asio.hpp>
29 
30 namespace ndn {
31 
32 class Transport : noncopyable
33 {
34 public:
35  class Error : public std::runtime_error
36  {
37  public:
38  inline Error(const boost::system::error_code& code, const std::string& msg);
39  inline Error(const std::string& msg);
40  };
41 
42  typedef function<void (const Block& wire)> ReceiveCallback;
43  typedef function<void ()> ErrorCallback;
44 
45  inline
46  Transport();
47 
48  inline virtual
49  ~Transport();
50 
56  inline virtual void
57  connect(boost::asio::io_service& io_service,
58  const ReceiveCallback& receiveCallback);
59 
63  virtual void
64  close() = 0;
65 
71  virtual void
72  send(const Block& wire) = 0;
73 
80  virtual void
81  send(const Block& header, const Block& payload) = 0;
82 
83  virtual void
84  pause() = 0;
85 
86  virtual void
87  resume() = 0;
88 
89  inline bool
90  isConnected();
91 
92  inline bool
94 
95 protected:
96  inline void
97  receive(const Block& wire);
98 
99 protected:
100  boost::asio::io_service* m_ioService;
104 };
105 
106 inline
108  : m_ioService(0)
109  , m_isConnected(false)
110  , m_isExpectingData(false)
111 {
112 }
113 
114 inline
115 Transport::Error::Error(const boost::system::error_code& code, const std::string& msg)
116  : std::runtime_error(msg + (code.value() ? " (" + code.category().message(code.value()) + ")" : ""))
117 {
118 }
119 
120 inline
121 Transport::Error::Error(const std::string& msg)
122  : std::runtime_error(msg)
123 {
124 }
125 
126 inline
128 {
129 }
130 
131 inline void
132 Transport::connect(boost::asio::io_service& ioService,
133  const ReceiveCallback& receiveCallback)
134 {
135  m_ioService = &ioService;
136  m_receiveCallback = receiveCallback;
137 }
138 
139 inline bool
141 {
142  return m_isConnected;
143 }
144 
145 inline bool
147 {
148  return m_isExpectingData;
149 }
150 
151 inline void
153 {
154  m_receiveCallback(wire);
155 }
156 
157 } // namespace ndn
158 
159 #endif // NDN_TRANSPORT_TRANSPORT_HPP
virtual void connect(boost::asio::io_service &io_service, const ReceiveCallback &receiveCallback)
Connect transport.
Definition: transport.hpp:132
Copyright (c) 2011-2015 Regents of the University of California.
Error(const boost::system::error_code &code, const std::string &msg)
Definition: transport.hpp:115
virtual void close()=0
Close the connection.
STL namespace.
function< void()> ErrorCallback
Definition: transport.hpp:43
Class representing a wire element of NDN-TLV packet format.
Definition: block.hpp:43
virtual void send(const Block &wire)=0
Send block of data from.
ReceiveCallback m_receiveCallback
Definition: transport.hpp:103
bool m_isExpectingData
Definition: transport.hpp:102
function< void(const Block &wire)> ReceiveCallback
Definition: transport.hpp:42
virtual void resume()=0
boost::asio::io_service * m_ioService
Definition: transport.hpp:100
void receive(const Block &wire)
Definition: transport.hpp:152
virtual void pause()=0
bool isConnected()
Definition: transport.hpp:140
virtual ~Transport()
Definition: transport.hpp:127
bool isExpectingData()
Definition: transport.hpp:146