blob: 2f710969fea3d9731af28767f744f3589dc349db [file] [log] [blame]
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07001/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07002 * Copyright (C) 2013 Regents of the University of California.
3 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07004 * See COPYING for copyright and distribution information.
5 */
6
7#ifndef NDN_TRANSPORT_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07008#define NDN_TRANSPORT_HPP
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07009
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070010#include <vector>
11
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070012namespace ndn {
Jeff Thompson0cb7aee2013-07-16 16:18:06 -070013
Jeff Thompson10e34382013-08-22 13:34:46 -070014class ElementListener;
15
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070016class Transport {
17public:
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070018 /**
Jeff Thompson10e34382013-08-22 13:34:46 -070019 * A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transport.
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070020 */
Jeff Thompson10e34382013-08-22 13:34:46 -070021 class ConnectionInfo {
22 public:
23 virtual ~ConnectionInfo();
24 };
25
26 /**
27 * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
28 * @param connectionInfo A reference to an object of a subclass of ConnectionInfo.
29 * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
30 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070031 virtual void
32 connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070033
Jeff Thompson432c8be2013-08-09 16:16:08 -070034 /**
35 * Set data to the host
36 * @param data A pointer to the buffer of data to send.
37 * @param dataLength The number of bytes in data.
38 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070039 virtual void
40 send(const unsigned char *data, unsigned int dataLength);
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070041
Jeff Thompson0050abe2013-09-17 12:50:25 -070042 void
43 send(const std::vector<unsigned char>& data)
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070044 {
45 send(&data[0], data.size());
46 }
Jeff Thompson57963882013-08-05 16:01:25 -070047
48 /**
Jeff Thompson10e34382013-08-22 13:34:46 -070049 * Process any data to receive. For each element received, call elementListener.onReceivedElement.
Jeff Thompson432c8be2013-08-09 16:16:08 -070050 * This is non-blocking and will silently time out after a brief period if there is no data to receive.
51 * You should repeatedly call this from an event loop.
52 * @throw This may throw an exception for reading data or in the callback for processing the data. If you
53 * call this from an main event loop, you may want to catch and log/disregard all exceptions.
Jeff Thompson7098dd62013-08-06 14:42:02 -070054 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070055 virtual void
56 processEvents() = 0;
Jeff Thompson7098dd62013-08-06 14:42:02 -070057
Jeff Thompson0050abe2013-09-17 12:50:25 -070058 virtual bool
59 getIsConnected();
Jeff Thompsona4056972013-08-22 11:52:21 -070060
Jeff Thompson7098dd62013-08-06 14:42:02 -070061 /**
Jeff Thompson57963882013-08-05 16:01:25 -070062 * Close the connection. This base class implementation does nothing, but your derived class can override.
63 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070064 virtual void
65 close();
Jeff Thompson43d6c0a2013-08-12 12:35:48 -070066
67 virtual ~Transport();
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070068};
69
70}
71
72#endif