blob: 17f6e25eda365c8d4138deff465932faac8cb6af [file] [log] [blame]
Jeff Thompsonbc53c522013-07-17 17:11:48 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
Jeff Thompson95a71b12013-07-31 10:49:50 -07006#ifndef NDN_UDPTRANSPORT_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_UDPTRANSPORT_HPP
Jeff Thompsonbc53c522013-07-17 17:11:48 -07008
Jeff Thompson53412192013-08-06 13:35:50 -07009#include "../c/transport/udp-transport.h"
10#include "../c/encoding/binary-xml-element-reader.h"
11#include "transport.hpp"
Jeff Thompsonbc53c522013-07-17 17:11:48 -070012
13namespace ndn {
14
15class UdpTransport : public Transport {
16public:
17 UdpTransport()
18 {
19 ndn_UdpTransport_init(&transport_);
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070020 face_ = 0;
Jeff Thompsona00f4eb2013-08-12 12:36:48 -070021 elementReader_.partialData.array = 0;
Jeff Thompsonbc53c522013-07-17 17:11:48 -070022 }
23
24 /**
Jeff Thompson432c8be2013-08-09 16:16:08 -070025 * Connect to the host specified in face.
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070026 * @param face Not a shared_ptr because we assume that it will remain valid during the life of this Transport object.
Jeff Thompsonbc53c522013-07-17 17:11:48 -070027 */
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070028 virtual void connect(Face &face);
Jeff Thompsonbc53c522013-07-17 17:11:48 -070029
Jeff Thompson432c8be2013-08-09 16:16:08 -070030 /**
31 * Set data to the host
32 * @param data A pointer to the buffer of data to send.
33 * @param dataLength The number of bytes in data.
34 */
Jeff Thompson60eaae32013-07-30 15:46:19 -070035 virtual void send(const unsigned char *data, unsigned int dataLength);
Jeff Thompsonbc53c522013-07-17 17:11:48 -070036
Jeff Thompson432c8be2013-08-09 16:16:08 -070037 /**
38 * Process any data to receive. For each element received, call face.onReceivedElement.
39 * This is non-blocking and will silently time out after a brief period if there is no data to receive.
40 * You should repeatedly call this from an event loop.
41 * @throw This may throw an exception for reading data or in the callback for processing the data. If you
42 * call this from an main event loop, you may want to catch and log/disregard all exceptions.
43 */
44 virtual void processEvents();
Jeff Thompsonbc53c522013-07-17 17:11:48 -070045
Jeff Thompson432c8be2013-08-09 16:16:08 -070046 /**
47 * Close the connection to the host.
48 */
Jeff Thompson57963882013-08-05 16:01:25 -070049 virtual void close();
50
Jeff Thompsona00f4eb2013-08-12 12:36:48 -070051 ~UdpTransport();
52
Jeff Thompsonbc53c522013-07-17 17:11:48 -070053private:
54 struct ndn_UdpTransport transport_;
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070055 Face *face_;
Jeff Thompsonbc53c522013-07-17 17:11:48 -070056 // TODO: This belongs in the socket listener.
Jeff Thompsonf0fea002013-07-30 17:22:42 -070057 ndn_BinaryXmlElementReader elementReader_;
Jeff Thompsonbc53c522013-07-17 17:11:48 -070058};
59
60}
61
62#endif