Jeff Thompson | 25b4e61 | 2013-10-10 16:03:24 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 2 | /** |
Jeff Thompson | 7687dc0 | 2013-09-13 11:54:07 -0700 | [diff] [blame] | 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Jeff Thompson <jefft0@remap.ucla.edu> |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
| 8 | #ifndef NDN_TRANSPORT_HPP |
Jeff Thompson | 2d27e2f | 2013-08-09 12:55:00 -0700 | [diff] [blame] | 9 | #define NDN_TRANSPORT_HPP |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 10 | |
Jeff Thompson | b605b5d | 2013-07-30 15:12:56 -0700 | [diff] [blame] | 11 | #include <vector> |
| 12 | |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 13 | namespace ndn { |
Jeff Thompson | 0cb7aee | 2013-07-16 16:18:06 -0700 | [diff] [blame] | 14 | |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 15 | class ElementListener; |
| 16 | |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 17 | class Transport { |
| 18 | public: |
Jeff Thompson | 2ed62fb | 2013-07-16 18:10:30 -0700 | [diff] [blame] | 19 | /** |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 20 | * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener. |
| 21 | * @param connectionInfo A reference to an object of a subclass of ConnectionInfo. |
| 22 | * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object. |
| 23 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 24 | virtual void |
Alexander Afanasyev | 0b688dc | 2013-12-18 16:43:37 -0800 | [diff] [blame] | 25 | connect(ElementListener& elementListener) = 0; |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 26 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 27 | /** |
| 28 | * Set data to the host |
| 29 | * @param data A pointer to the buffer of data to send. |
| 30 | * @param dataLength The number of bytes in data. |
| 31 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 32 | virtual void |
Alexander Afanasyev | 0b688dc | 2013-12-18 16:43:37 -0800 | [diff] [blame] | 33 | send(const uint8_t *data, size_t dataLength) = 0; |
Jeff Thompson | b605b5d | 2013-07-30 15:12:56 -0700 | [diff] [blame] | 34 | |
Alexander Afanasyev | 0b688dc | 2013-12-18 16:43:37 -0800 | [diff] [blame] | 35 | inline void |
Jeff Thompson | 10ad12a | 2013-09-24 16:19:11 -0700 | [diff] [blame] | 36 | send(const std::vector<uint8_t>& data) |
Jeff Thompson | b605b5d | 2013-07-30 15:12:56 -0700 | [diff] [blame] | 37 | { |
| 38 | send(&data[0], data.size()); |
| 39 | } |
Jeff Thompson | 5796388 | 2013-08-05 16:01:25 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
Jeff Thompson | 10e3438 | 2013-08-22 13:34:46 -0700 | [diff] [blame] | 42 | * Process any data to receive. For each element received, call elementListener.onReceivedElement. |
Jeff Thompson | 17cb30c | 2013-11-15 16:18:09 -0800 | [diff] [blame] | 43 | * This is non-blocking and will return immediately if there is no data to receive. |
| 44 | * You should normally not call this directly since it is called by Face.processEvents. |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 45 | * @throw This may throw an exception for reading data or in the callback for processing the data. If you |
| 46 | * 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] | 47 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 48 | virtual void |
| 49 | processEvents() = 0; |
Jeff Thompson | 7098dd6 | 2013-08-06 14:42:02 -0700 | [diff] [blame] | 50 | |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 51 | virtual bool |
Alexander Afanasyev | 0b688dc | 2013-12-18 16:43:37 -0800 | [diff] [blame] | 52 | getIsConnected() = 0; |
Jeff Thompson | a405697 | 2013-08-22 11:52:21 -0700 | [diff] [blame] | 53 | |
Jeff Thompson | 7098dd6 | 2013-08-06 14:42:02 -0700 | [diff] [blame] | 54 | /** |
Jeff Thompson | 5796388 | 2013-08-05 16:01:25 -0700 | [diff] [blame] | 55 | * Close the connection. This base class implementation does nothing, but your derived class can override. |
| 56 | */ |
Jeff Thompson | 0050abe | 2013-09-17 12:50:25 -0700 | [diff] [blame] | 57 | virtual void |
| 58 | close(); |
Jeff Thompson | 43d6c0a | 2013-08-12 12:35:48 -0700 | [diff] [blame] | 59 | |
| 60 | virtual ~Transport(); |
Jeff Thompson | fcf347d | 2013-07-15 11:30:44 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | } |
| 64 | |
| 65 | #endif |