blob: 9159b99e790cd036f453c0f71daf0cb3a014812b [file] [log] [blame]
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#ifndef NDN_TRANSPORT_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07007#define NDN_TRANSPORT_HPP
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07008
Jeff Thompsonb605b5d2013-07-30 15:12:56 -07009#include <vector>
10
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070011namespace ndn {
Jeff Thompson0cb7aee2013-07-16 16:18:06 -070012
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070013class Node;
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070014class Transport {
15public:
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070016 /**
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070017 * Connect to the host specified in node.
18 * @param node Not a shared_ptr because we assume that it will remain valid during the life of this Transport object.
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070019 */
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070020 virtual void connect(Node &node);
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070021
Jeff Thompson432c8be2013-08-09 16:16:08 -070022 /**
23 * Set data to the host
24 * @param data A pointer to the buffer of data to send.
25 * @param dataLength The number of bytes in data.
26 */
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070027 virtual void send(const unsigned char *data, unsigned int dataLength);
28
29 void send(const std::vector<unsigned char> &data)
30 {
31 send(&data[0], data.size());
32 }
Jeff Thompson57963882013-08-05 16:01:25 -070033
34 /**
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070035 * Process any data to receive. For each element received, call node.onReceivedElement.
Jeff Thompson432c8be2013-08-09 16:16:08 -070036 * This is non-blocking and will silently time out after a brief period if there is no data to receive.
37 * You should repeatedly call this from an event loop.
38 * @throw This may throw an exception for reading data or in the callback for processing the data. If you
39 * call this from an main event loop, you may want to catch and log/disregard all exceptions.
Jeff Thompson7098dd62013-08-06 14:42:02 -070040 */
Jeff Thompson432c8be2013-08-09 16:16:08 -070041 virtual void processEvents() = 0;
Jeff Thompson7098dd62013-08-06 14:42:02 -070042
43 /**
Jeff Thompson57963882013-08-05 16:01:25 -070044 * Close the connection. This base class implementation does nothing, but your derived class can override.
45 */
46 virtual void close();
Jeff Thompson43d6c0a2013-08-12 12:35:48 -070047
48 virtual ~Transport();
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070049};
50
51}
52
53#endif