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 
35 class UdpTransport : public Transport {
36 public:
42  public:
48  ConnectionInfo(const char *host, unsigned short port = 6363)
49  : host_(host), port_(port)
50  {
51  }
52 
57  const std::string&
58  getHost() const { return host_; }
59 
64  unsigned short
65  getPort() const { return port_; }
66 
67  virtual
68  ~ConnectionInfo();
69 
70  private:
71  std::string host_;
72  unsigned short port_;
73  };
74 
75  UdpTransport();
76 
83  virtual bool
84  isLocal(const Transport::ConnectionInfo& connectionInfo);
85 
93  virtual void
94  connect(const Transport::ConnectionInfo& connectionInfo,
95  ElementListener& elementListener);
96 
102  virtual void
103  send(const uint8_t *data, size_t dataLength);
104 
114  virtual void
115  processEvents();
116 
117  virtual bool
118  getIsConnected();
119 
123  virtual void
124  close();
125 
126 private:
127  ptr_lib::shared_ptr<struct ndn_UdpTransport> transport_;
128  ptr_lib::shared_ptr<DynamicUInt8Vector> elementBuffer_;
129  bool isConnected_;
130 };
131 
132 }
133 
134 #endif
Definition: transport.hpp:32
virtual void connect(const Transport::ConnectionInfo &connectionInfo, ElementListener &elementListener)
Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
Definition: udp-transport.cpp:53
Copyright (C) 2013-2015 Regents of the University of California.
Definition: common.hpp:35
const std::string & getHost() const
Get the host given to the constructor.
Definition: udp-transport.hpp:58
A UdpTransport::ConnectionInfo extends Transport::ConnectionInfo to hold the host and port info for t...
Definition: udp-transport.hpp:41
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:48
Definition: udp-transport.hpp:35
virtual void processEvents()
Process any data to receive.
Definition: udp-transport.cpp:77
virtual bool isLocal(const Transport::ConnectionInfo &connectionInfo)
Determine whether this transport connecting according to connectionInfo is to a node on the current m...
Definition: udp-transport.cpp:46
virtual void send(const uint8_t *data, size_t dataLength)
Set data to the host.
Definition: udp-transport.cpp:69
unsigned short getPort() const
Get the port given to the constructor.
Definition: udp-transport.hpp:65
A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transpor...
Definition: transport.hpp:38
virtual void close()
Close the connection to the host.
Definition: udp-transport.cpp:93
Definition: transport-types.h:39