Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #ifndef NDN_TRANSPORT_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 7 | #define NDN_TRANSPORT_HPP |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 8 | |
Jeff Thompson | b605b5d | 2013-07-30 15:12:56 -0700 | [diff] [blame] | 9 | #include <vector> |
| 10 | |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 11 | namespace ndn { |
Jeff Thompson | 0cb7aee | 2013-07-16 16:18:06 -0700 | [diff] [blame] | 12 | |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 13 | class Face; |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 14 | class Transport { |
| 15 | public: |
Jeff Thompson | 2ed62fb | 2013-07-16 18:10:30 -0700 | [diff] [blame] | 16 | /** |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 17 | * Connect to the host specified in face. |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 18 | * @param face Not a shared_ptr because we assume that it will remain valid during the life of this Transport object. |
Jeff Thompson | 2ed62fb | 2013-07-16 18:10:30 -0700 | [diff] [blame] | 19 | */ |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 20 | virtual void connect(Face &face); |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 21 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 22 | /** |
| 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 Thompson | b605b5d | 2013-07-30 15:12:56 -0700 | [diff] [blame] | 27 | 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 Thompson | 5796388 | 2013-08-05 16:01:25 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 35 | * Process any data to receive. For each element received, call face.onReceivedElement. |
| 36 | * 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 Thompson | 7098dd6 | 2013-08-06 14:42:02 -0700 | [diff] [blame] | 40 | */ |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 41 | virtual void processEvents() = 0; |
Jeff Thompson | 7098dd6 | 2013-08-06 14:42:02 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Jeff Thompson | 5796388 | 2013-08-05 16:01:25 -0700 | [diff] [blame] | 44 | * Close the connection. This base class implementation does nothing, but your derived class can override. |
| 45 | */ |
| 46 | virtual void close(); |
Jeff Thompson | 43d6c0a | 2013-08-12 12:35:48 -0700 | [diff] [blame^] | 47 | |
| 48 | virtual ~Transport(); |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | } |
| 52 | |
| 53 | #endif |