blob: 80d41b2b38b567519ccf681ee5948dbf4942c406 [file] [log] [blame]
Jeff Thompson25b4e612013-10-10 16:03:24 -07001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07002/**
Jeff Thompson7687dc02013-09-13 11:54:07 -07003 * Copyright (C) 2013 Regents of the University of California.
4 * @author: Jeff Thompson <jefft0@remap.ucla.edu>
Jeff Thompsonfcf347d2013-07-15 11:30:44 -07005 * See COPYING for copyright and distribution information.
6 */
7
8#ifndef NDN_TRANSPORT_HPP
Jeff Thompson2d27e2f2013-08-09 12:55:00 -07009#define NDN_TRANSPORT_HPP
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070010
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070011#include <vector>
12
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070013namespace ndn {
Jeff Thompson0cb7aee2013-07-16 16:18:06 -070014
Jeff Thompson10e34382013-08-22 13:34:46 -070015class ElementListener;
16
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070017class Transport {
18public:
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070019 /**
Jeff Thompson10e34382013-08-22 13:34:46 -070020 * 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 Thompson0050abe2013-09-17 12:50:25 -070024 virtual void
Alexander Afanasyev0b688dc2013-12-18 16:43:37 -080025 connect(ElementListener& elementListener) = 0;
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070026
Jeff Thompson432c8be2013-08-09 16:16:08 -070027 /**
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 Thompson0050abe2013-09-17 12:50:25 -070032 virtual void
Alexander Afanasyev0b688dc2013-12-18 16:43:37 -080033 send(const uint8_t *data, size_t dataLength) = 0;
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070034
Alexander Afanasyev0b688dc2013-12-18 16:43:37 -080035 inline void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070036 send(const std::vector<uint8_t>& data)
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070037 {
38 send(&data[0], data.size());
39 }
Jeff Thompson57963882013-08-05 16:01:25 -070040
41 /**
Jeff Thompson10e34382013-08-22 13:34:46 -070042 * Process any data to receive. For each element received, call elementListener.onReceivedElement.
Jeff Thompson17cb30c2013-11-15 16:18:09 -080043 * 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 Thompson432c8be2013-08-09 16:16:08 -070045 * @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 Thompson7098dd62013-08-06 14:42:02 -070047 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070048 virtual void
49 processEvents() = 0;
Jeff Thompson7098dd62013-08-06 14:42:02 -070050
Jeff Thompson0050abe2013-09-17 12:50:25 -070051 virtual bool
Alexander Afanasyev0b688dc2013-12-18 16:43:37 -080052 getIsConnected() = 0;
Jeff Thompsona4056972013-08-22 11:52:21 -070053
Jeff Thompson7098dd62013-08-06 14:42:02 -070054 /**
Jeff Thompson57963882013-08-05 16:01:25 -070055 * Close the connection. This base class implementation does nothing, but your derived class can override.
56 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070057 virtual void
58 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