blob: c98932c1a0adf59fccc12ef2703fa48d7ccb403e [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 /**
19 * Create a new Face for communication with an NDN hub at host:port with the given Transport object.
20 * @param host The host of the NDN hub.
21 * @param port The port of the NDN hub.
22 * @param transport A pointer to a Transport object used for communication.
23 */
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070024 Face(const char *host, unsigned short port, const ptr_lib::shared_ptr<Transport> &transport)
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070025 : node_(host, port, transport)
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070026 {
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070027 }
28
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070029 /**
30 * Create a new Face for communication with an NDN hub at host:port using the default UdpTransport.
31 * @param host The host of the NDN hub.
32 * @param port The port of the NDN hub.
33 */
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070034 Face(const char *host, unsigned short port)
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070035 : node_(host, port)
Jeff Thompsonb7d059d2013-07-31 10:59:51 -070036 {
37 }
Jeff Thompson1242b1f2013-07-31 11:02:00 -070038
Jeff Thompsonfe08e5a2013-08-13 11:15:59 -070039 /**
40 * Create a new Face for communication with an NDN hub at host with the default port 9695 and using the default UdpTransport.
41 * @param host The host of the NDN hub.
42 */
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070043 Face(const char *host)
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070044 : node_(host)
Jeff Thompson1242b1f2013-07-31 11:02:00 -070045 {
46 }
Jeff Thompsonb7d059d2013-07-31 10:59:51 -070047
Jeff Thompsonc172be32013-07-16 15:08:05 -070048 /**
49 * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
50 * Send the interest through the transport, read the entire response and call
Jeff Thompson56ec9e22013-08-02 11:34:07 -070051 * closure->upcall(UPCALL_DATA (or UPCALL_DATA_UNVERIFIED),
52 * UpcallInfo(this, interest, 0, data)).
Jeff Thompsonc172be32013-07-16 15:08:05 -070053 * @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 -070054 * @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 -070055 * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
56 */
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070057 void expressInterest(const Name &name, Closure *closure, const Interest *interestTemplate)
58 {
59 node_.expressInterest(name, closure, interestTemplate);
60 }
Jeff Thompsonc172be32013-07-16 15:08:05 -070061
Jeff Thompson2a4724b2013-08-07 17:13:34 -070062 void expressInterest(const Name &name, Closure *closure)
Jeff Thompsoncdf7e252013-07-31 12:41:47 -070063 {
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070064 node_.expressInterest(name, closure);
Jeff Thompsoncdf7e252013-07-31 12:41:47 -070065 }
66
Jeff Thompson432c8be2013-08-09 16:16:08 -070067 /**
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070068 * Process any data to receive or call timeout callbacks.
Jeff Thompsonc7e07442013-08-19 15:25:43 -070069 * This is non-blocking and will return immediately if there is no data to receive.
70 * 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 -070071 * @throw This may throw an exception for reading data or in the callback for processing the data. If you
72 * call this from an main event loop, you may want to catch and log/disregard all exceptions.
73 */
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070074 void processEvents()
75 {
76 // Just call Node's processEvents.
77 node_.processEvents();
78 }
Jeff Thompson432c8be2013-08-09 16:16:08 -070079
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070080 /**
81 * Shut down and disconnect this Face.
82 */
Jeff Thompson517ffa82013-08-05 16:04:34 -070083 void shutdown();
84
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070085private:
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -070086 Node node_;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070087};
88
89}
90
91#endif