blob: 2e78b6e0ba023f85bc8d17a8e4b070c51dcf7467 [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 Thompson10e34382013-08-22 13:34:46 -070013class ElementListener;
14
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070015class Transport {
16public:
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070017 /**
Jeff Thompson10e34382013-08-22 13:34:46 -070018 * A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transport.
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070019 */
Jeff Thompson10e34382013-08-22 13:34:46 -070020 class ConnectionInfo {
21 public:
22 virtual ~ConnectionInfo();
23 };
24
25 /**
26 * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
27 * @param connectionInfo A reference to an object of a subclass of ConnectionInfo.
28 * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
29 */
Jeff Thompson1656e6a2013-08-29 18:01:48 -070030 virtual void connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070031
Jeff Thompson432c8be2013-08-09 16:16:08 -070032 /**
33 * Set data to the host
34 * @param data A pointer to the buffer of data to send.
35 * @param dataLength The number of bytes in data.
36 */
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070037 virtual void send(const unsigned char *data, unsigned int dataLength);
38
Jeff Thompson1656e6a2013-08-29 18:01:48 -070039 void send(const std::vector<unsigned char>& data)
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070040 {
41 send(&data[0], data.size());
42 }
Jeff Thompson57963882013-08-05 16:01:25 -070043
44 /**
Jeff Thompson10e34382013-08-22 13:34:46 -070045 * Process any data to receive. For each element received, call elementListener.onReceivedElement.
Jeff Thompson432c8be2013-08-09 16:16:08 -070046 * This is non-blocking and will silently time out after a brief period if there is no data to receive.
47 * You should repeatedly call this from an event loop.
48 * @throw This may throw an exception for reading data or in the callback for processing the data. If you
49 * call this from an main event loop, you may want to catch and log/disregard all exceptions.
Jeff Thompson7098dd62013-08-06 14:42:02 -070050 */
Jeff Thompson432c8be2013-08-09 16:16:08 -070051 virtual void processEvents() = 0;
Jeff Thompson7098dd62013-08-06 14:42:02 -070052
Jeff Thompsona4056972013-08-22 11:52:21 -070053 virtual bool getIsConnected();
54
Jeff Thompson7098dd62013-08-06 14:42:02 -070055 /**
Jeff Thompson57963882013-08-05 16:01:25 -070056 * Close the connection. This base class implementation does nothing, but your derived class can override.
57 */
58 virtual void close();
Jeff Thompson43d6c0a2013-08-12 12:35:48 -070059
60 virtual ~Transport();
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070061};
62
63}
64
65#endif