blob: 3be3dd3afb41cc3bd9acfeced05957ada6fcf390 [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 * A Transport::ConnectionInfo is a base class for connection information used by subclasses of Transport.
Jeff Thompson2ed62fb2013-07-16 18:10:30 -070021 */
Jeff Thompson10e34382013-08-22 13:34:46 -070022 class ConnectionInfo {
23 public:
24 virtual ~ConnectionInfo();
25 };
26
27 /**
28 * Connect according to the info in ConnectionInfo, and processEvents() will use elementListener.
29 * @param connectionInfo A reference to an object of a subclass of ConnectionInfo.
30 * @param elementListener Not a shared_ptr because we assume that it will remain valid during the life of this object.
31 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070032 virtual void
33 connect(const Transport::ConnectionInfo& connectionInfo, ElementListener& elementListener);
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070034
Jeff Thompson432c8be2013-08-09 16:16:08 -070035 /**
36 * Set data to the host
37 * @param data A pointer to the buffer of data to send.
38 * @param dataLength The number of bytes in data.
39 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070040 virtual void
Jeff Thompson97223af2013-09-24 17:01:27 -070041 send(const uint8_t *data, size_t dataLength);
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070042
Jeff Thompson0050abe2013-09-17 12:50:25 -070043 void
Jeff Thompson10ad12a2013-09-24 16:19:11 -070044 send(const std::vector<uint8_t>& data)
Jeff Thompsonb605b5d2013-07-30 15:12:56 -070045 {
46 send(&data[0], data.size());
47 }
Jeff Thompson57963882013-08-05 16:01:25 -070048
49 /**
Jeff Thompson10e34382013-08-22 13:34:46 -070050 * Process any data to receive. For each element received, call elementListener.onReceivedElement.
Jeff Thompson432c8be2013-08-09 16:16:08 -070051 * This is non-blocking and will silently time out after a brief period if there is no data to receive.
52 * You should repeatedly call this from an event loop.
53 * @throw This may throw an exception for reading data or in the callback for processing the data. If you
54 * call this from an main event loop, you may want to catch and log/disregard all exceptions.
Jeff Thompson7098dd62013-08-06 14:42:02 -070055 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070056 virtual void
57 processEvents() = 0;
Jeff Thompson7098dd62013-08-06 14:42:02 -070058
Jeff Thompson0050abe2013-09-17 12:50:25 -070059 virtual bool
60 getIsConnected();
Jeff Thompsona4056972013-08-22 11:52:21 -070061
Jeff Thompson7098dd62013-08-06 14:42:02 -070062 /**
Jeff Thompson57963882013-08-05 16:01:25 -070063 * Close the connection. This base class implementation does nothing, but your derived class can override.
64 */
Jeff Thompson0050abe2013-09-17 12:50:25 -070065 virtual void
66 close();
Jeff Thompson43d6c0a2013-08-12 12:35:48 -070067
68 virtual ~Transport();
Jeff Thompsonfcf347d2013-07-15 11:30:44 -070069};
70
71}
72
73#endif