All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Pages
udp-transport.hpp
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
22 #ifndef NDN_UDPTRANSPORT_HPP
23 #define NDN_UDPTRANSPORT_HPP
24 
25 #include <string>
26 #include "../common.hpp"
27 #include "transport.hpp"
28 
29 struct ndn_UdpTransport;
30 
31 namespace ndn {
32 
33 class DynamicUInt8Vector;
34 
39 class UdpTransport : public Transport {
40 public:
46  public:
52  ConnectionInfo(const char *host, unsigned short port = 6363)
53  : host_(host), port_(port)
54  {
55  }
56 
61  const std::string&
62  getHost() const { return host_; }
63 
68  unsigned short
69  getPort() const { return port_; }
70 
71  virtual
72  ~ConnectionInfo();
73 
74  private:
75  std::string host_;
76  unsigned short port_;
77  };
78 
79  UdpTransport();
80 
87  virtual bool
88  isLocal(const Transport::ConnectionInfo& connectionInfo);
89 
95  virtual bool
96  isAsync();
97 
107  virtual void
108  connect(const Transport::ConnectionInfo& connectionInfo,
109  ElementListener& elementListener, const OnConnected& onConnected);
110 
116  virtual void
117  send(const uint8_t *data, size_t dataLength);
118 
128  virtual void
129  processEvents();
130 
131  virtual bool
132  getIsConnected();
133 
137  virtual void
138  close();
139 
140 private:
141  ptr_lib::shared_ptr<struct ndn_UdpTransport> transport_;
142  ptr_lib::shared_ptr<DynamicUInt8Vector> elementBuffer_;
143  bool isConnected_;
144 };
145 
146 }
147 
148 #endif
A Transport object is used by Face to send packets and to listen for incoming packets.
Definition: transport.hpp:36
const std::string & getHost() const
Get the host given to the constructor.
Definition: udp-transport.hpp:62
A UdpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for t...
Definition: udp-transport.hpp:45
An ElementListener extends an ndn_ElementListener struct to proved an abstract virtual onReceivedElem...
Definition: element-listener.hpp:33
ConnectionInfo(const char *host, unsigned short port=6363)
Create a ConnectionInfo with the given host and port.
Definition: udp-transport.hpp:52
UdpTransport extends the Transport interface to implement communication over UDP. ...
Definition: udp-transport.hpp:39
virtual void close()
Close the connection to the host.
virtual void send(const uint8_t *data, size_t dataLength)
Send data to the host.
virtual bool isLocal(const Transport::ConnectionInfo &connectionInfo)
Determine whether this transport connecting according to connectionInfo is to a node on the current m...
virtual void connect(const Transport::ConnectionInfo &connectionInfo, ElementListener &elementListener, const OnConnected &onConnected)
Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
unsigned short getPort() const
Get the port given to the constructor.
Definition: udp-transport.hpp:69
virtual void processEvents()
Process any data to receive.
A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transpor...
Definition: transport.hpp:42
Definition: transport-types.h:39
virtual bool isAsync()
Override to return false since connect does not need to use the onConnected callback.