blob: fe700ef8e9b57aedf4792c1dbf8f4692c00f4aa3 [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
7#define NDN_FACE_HPP
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -07008
Jeff Thompson53412192013-08-06 13:35:50 -07009#include "closure.hpp"
10#include "interest.hpp"
11#include "transport/udp-transport.hpp"
12#include "encoding/binary-xml-element-reader.hpp"
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070013
Jeff Thompsonbeb8b7d2013-07-16 15:49:21 -070014using namespace std;
15
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070016namespace ndn {
17
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070018class Face : public ElementListener {
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070019public:
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070020 Face(const char *host, unsigned short port, const ptr_lib::shared_ptr<Transport> &transport)
Jeff Thompsonb7d059d2013-07-31 10:59:51 -070021 : host_(host), port_(port), transport_(transport)
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070022 {
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070023 }
24
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070025 Face(const char *host, unsigned short port)
Jeff Thompsonb7d059d2013-07-31 10:59:51 -070026 : host_(host), port_(port), transport_(new UdpTransport())
27 {
28 }
Jeff Thompson1242b1f2013-07-31 11:02:00 -070029
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070030 Face(const char *host)
Jeff Thompson1242b1f2013-07-31 11:02:00 -070031 : host_(host), port_(9695), transport_(new UdpTransport())
32 {
33 }
Jeff Thompsonb7d059d2013-07-31 10:59:51 -070034
Jeff Thompsonc172be32013-07-16 15:08:05 -070035 /**
36 * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
37 * Send the interest through the transport, read the entire response and call
Jeff Thompson56ec9e22013-08-02 11:34:07 -070038 * closure->upcall(UPCALL_DATA (or UPCALL_DATA_UNVERIFIED),
39 * UpcallInfo(this, interest, 0, data)).
Jeff Thompsonc172be32013-07-16 15:08:05 -070040 * @param name reference to a Name for the interest. This does not keep a pointer to the Name object.
41 * @param closure a shared_ptr for the Closure. This uses shared_ptr to take another reference to the object.
42 * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
43 */
44 void expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure, const Interest *interestTemplate);
45
Jeff Thompsoncdf7e252013-07-31 12:41:47 -070046 void expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure)
47 {
48 expressInterest(name, closure, 0);
49 }
50
Jeff Thompson517ffa82013-08-05 16:04:34 -070051 void shutdown();
52
Jeff Thompson0cb7aee2013-07-16 16:18:06 -070053 const char *getHost() const { return host_.c_str(); }
54
55 unsigned short getPort() const { return port_; }
Jeff Thompsonc172be32013-07-16 15:08:05 -070056
Jeff Thompsonab13ac72013-08-01 10:37:21 -070057 ptr_lib::shared_ptr<Transport> &getTransport() { return transport_; }
58
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070059 virtual void onReceivedElement(unsigned char *element, unsigned int elementLength);
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070060
61private:
Jeff Thompsonc172be32013-07-16 15:08:05 -070062 ptr_lib::shared_ptr<Transport> transport_;
Jeff Thompsonbeb8b7d2013-07-16 15:49:21 -070063 string host_;
64 unsigned short port_;
Jeff Thompsonc172be32013-07-16 15:08:05 -070065 ptr_lib::shared_ptr<Closure> tempClosure_;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070066};
67
68}
69
70#endif