Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
Jeff Thompson | 95a71b1 | 2013-07-31 10:49:50 -0700 | [diff] [blame] | 6 | #ifndef NDN_UDPTRANSPORT_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 7 | #define NDN_UDPTRANSPORT_HPP |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 9 | #include "../c/transport/udp-transport.h" |
| 10 | #include "../c/encoding/binary-xml-element-reader.h" |
| 11 | #include "transport.hpp" |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 12 | |
| 13 | namespace ndn { |
| 14 | |
| 15 | class UdpTransport : public Transport { |
| 16 | public: |
| 17 | UdpTransport() |
| 18 | { |
| 19 | ndn_UdpTransport_init(&transport_); |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 20 | face_ = 0; |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | /** |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame^] | 24 | * Connect to the host specified in face. |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 25 | * @param face Not a shared_ptr because we assume that it will remain valid during the life of this Transport object. |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 26 | */ |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 27 | virtual void connect(Face &face); |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 28 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame^] | 29 | /** |
| 30 | * Set data to the host |
| 31 | * @param data A pointer to the buffer of data to send. |
| 32 | * @param dataLength The number of bytes in data. |
| 33 | */ |
Jeff Thompson | 60eaae3 | 2013-07-30 15:46:19 -0700 | [diff] [blame] | 34 | virtual void send(const unsigned char *data, unsigned int dataLength); |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 35 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame^] | 36 | /** |
| 37 | * Process any data to receive. For each element received, call face.onReceivedElement. |
| 38 | * This is non-blocking and will silently time out after a brief period if there is no data to receive. |
| 39 | * You should repeatedly call this from an event loop. |
| 40 | * @throw This may throw an exception for reading data or in the callback for processing the data. If you |
| 41 | * call this from an main event loop, you may want to catch and log/disregard all exceptions. |
| 42 | */ |
| 43 | virtual void processEvents(); |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 44 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame^] | 45 | /** |
| 46 | * Close the connection to the host. |
| 47 | */ |
Jeff Thompson | 5796388 | 2013-08-05 16:01:25 -0700 | [diff] [blame] | 48 | virtual void close(); |
| 49 | |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 50 | private: |
| 51 | struct ndn_UdpTransport transport_; |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 52 | Face *face_; |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 53 | // TODO: This belongs in the socket listener. |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 54 | ndn_BinaryXmlElementReader elementReader_; |
Jeff Thompson | bc53c52 | 2013-07-17 17:11:48 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } |
| 58 | |
| 59 | #endif |