blob: b317fa60df68f02b85331ccf139ee2fa868ae01a [file] [log] [blame]
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -07006#ifndef NDN_FACE_HPP
Jeff Thompsona0d18c92013-08-06 13:55:32 -07007#define NDN_FACE_HPP
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -07008
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -07009#include "node.hpp"
Jeff Thompsonbeb8b7d2013-07-16 15:49:21 -070010
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070011namespace ndn {
12
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070013/**
14 * The Face class provides the main methods for NDN communication.
15 */
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070016class Face {
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070017public:
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070018 /**
Jeff Thompson10e34382013-08-22 13:34:46 -070019 * Create a new Face for communication with an NDN hub with the given Transport object and connectionInfo.
20 * @param transport A shared_ptr to a Transport object used for communication.
21 * @param transport A shared_ptr to a Transport::ConnectionInfo to be used to connect to the transport.
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070022 */
Jeff Thompson10e34382013-08-22 13:34:46 -070023 Face(const ptr_lib::shared_ptr<Transport> &transport, const ptr_lib::shared_ptr<const Transport::ConnectionInfo> &connectionInfo)
24 : node_(transport, connectionInfo)
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070025 {
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070026 }
27
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070028 /**
29 * Create a new Face for communication with an NDN hub at host:port using the default UdpTransport.
30 * @param host The host of the NDN hub.
31 * @param port The port of the NDN hub.
32 */
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070033 Face(const char *host, unsigned short port)
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070034 : node_(host, port)
Jeff Thompsonb7d059d2013-07-31 10:59:51 -070035 {
36 }
Jeff Thompson1242b1f2013-07-31 11:02:00 -070037
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070038 /**
39 * Create a new Face for communication with an NDN hub at host with the default port 9695 and using the default UdpTransport.
40 * @param host The host of the NDN hub.
41 */
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070042 Face(const char *host)
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070043 : node_(host)
Jeff Thompson1242b1f2013-07-31 11:02:00 -070044 {
45 }
Jeff Thompsonb7d059d2013-07-31 10:59:51 -070046
Jeff Thompsonc172be32013-07-16 15:08:05 -070047 /**
48 * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
49 * Send the interest through the transport, read the entire response and call
Jeff Thompson56ec9e22013-08-02 11:34:07 -070050 * closure->upcall(UPCALL_DATA (or UPCALL_DATA_UNVERIFIED),
51 * UpcallInfo(this, interest, 0, data)).
Jeff Thompsonc172be32013-07-16 15:08:05 -070052 * @param name reference to a Name for the interest. This does not keep a pointer to the Name object.
Jeff Thompson2a4724b2013-08-07 17:13:34 -070053 * @param closure a pointer for the Closure. The caller must manage the memory for the Closure. This will not try to delete it.
Jeff Thompsonc172be32013-07-16 15:08:05 -070054 * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
55 */
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070056 void expressInterest(const Name &name, Closure *closure, const Interest *interestTemplate)
57 {
58 node_.expressInterest(name, closure, interestTemplate);
59 }
Jeff Thompsonc172be32013-07-16 15:08:05 -070060
Jeff Thompson2a4724b2013-08-07 17:13:34 -070061 void expressInterest(const Name &name, Closure *closure)
Jeff Thompsoncdf7e252013-07-31 12:41:47 -070062 {
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070063 node_.expressInterest(name, closure);
Jeff Thompsoncdf7e252013-07-31 12:41:47 -070064 }
65
Jeff Thompson432c8be2013-08-09 16:16:08 -070066 /**
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070067 * Process any data to receive or call timeout callbacks.
Jeff Thompsonc7e07442013-08-19 15:25:43 -070068 * This is non-blocking and will return immediately if there is no data to receive.
69 * You should repeatedly call this from an event loop, with calls to sleep as needed so that the loop doesn't use 100% of the CPU.
Jeff Thompson432c8be2013-08-09 16:16:08 -070070 * @throw This may throw an exception for reading data or in the callback for processing the data. If you
71 * call this from an main event loop, you may want to catch and log/disregard all exceptions.
72 */
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070073 void processEvents()
74 {
75 // Just call Node's processEvents.
76 node_.processEvents();
77 }
Jeff Thompson432c8be2013-08-09 16:16:08 -070078
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070079 /**
80 * Shut down and disconnect this Face.
81 */
Jeff Thompson517ffa82013-08-05 16:04:34 -070082 void shutdown();
83
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070084private:
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070085 Node node_;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070086};
87
88}
89
90#endif