Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 1 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 Regents of the University of California. |
| 3 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 4 | * See COPYING for copyright and distribution information. |
| 5 | */ |
| 6 | |
| 7 | #ifndef NDN_TRANSPORT_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 8 | #define NDN_TRANSPORT_HPP |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 9 | |
Jeff Thompson | b605b5d | 2013-07-30 15:12:56 -0700 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 12 | namespace ndn { |
Jeff Thompson | 0cb7aee | 2013-07-16 16:18:06 -0700 | [diff] [blame] | 13 | |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 14 | class ElementListener; |
| 15 | |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 16 | class Transport { |
| 17 | public: |
Jeff Thompson | 2ed62fb | 2013-07-16 18:10:30 -0700 | [diff] [blame] | 18 | /** |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 19 | * A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transport. |
Jeff Thompson | 2ed62fb | 2013-07-16 18:10:30 -0700 | [diff] [blame] | 20 | */ |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 21 | 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 Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 31 | virtual void connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener); |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 32 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 33 | /** |
| 34 | * Set data to the host |
| 35 | * @param data A pointer to the buffer of data to send. |
| 36 | * @param dataLength The number of bytes in data. |
| 37 | */ |
Jeff Thompson | b605b5d | 2013-07-30 15:12:56 -0700 | [diff] [blame] | 38 | virtual void send(const unsigned char *data, unsigned int dataLength); |
| 39 | |
Jeff Thompson | 1656e6a | 2013-08-29 18:01:48 -0700 | [diff] [blame] | 40 | void send(const std::vector<unsigned char>& data) |
Jeff Thompson | b605b5d | 2013-07-30 15:12:56 -0700 | [diff] [blame] | 41 | { |
| 42 | send(&data[0], data.size()); |
| 43 | } |
Jeff Thompson | 5796388 | 2013-08-05 16:01:25 -0700 | [diff] [blame] | 44 | |
| 45 | /** |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 46 | * Process any data to receive. For each element received, call elementListener.onReceivedElement. |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 47 | * This is non-blocking and will silently time out after a brief period if there is no data to receive. |
| 48 | * You should repeatedly call this from an event loop. |
| 49 | * @throw This may throw an exception for reading data or in the callback for processing the data. If you |
| 50 | * 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] | 51 | */ |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 52 | virtual void processEvents() = 0; |
Jeff Thompson | 7098dd6 | 2013-08-06 14:42:02 -0700 | [diff] [blame] | 53 | |
Jeff Thompson | a405697 | 2013-08-22 11:52:21 -0700 | [diff] [blame] | 54 | virtual bool getIsConnected(); |
| 55 | |
Jeff Thompson | 7098dd6 | 2013-08-06 14:42:02 -0700 | [diff] [blame] | 56 | /** |
Jeff Thompson | 5796388 | 2013-08-05 16:01:25 -0700 | [diff] [blame] | 57 | * Close the connection. This base class implementation does nothing, but your derived class can override. |
| 58 | */ |
| 59 | virtual void close(); |
Jeff Thompson | 43d6c0a | 2013-08-12 12:35:48 -0700 | [diff] [blame] | 60 | |
| 61 | virtual ~Transport(); |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | #endif |