blob: c631340e299fd8c19480ef12eb7ea7fe36f832fc [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
6#ifndef NDN_NDN_HPP
7#define NDN_NDN_HPP
8
Jeff Thompsonb982b6d2013-07-15 18:15:45 -07009#include "Closure.hpp"
Jeff Thompsonc172be32013-07-16 15:08:05 -070010#include "Interest.hpp"
Jeff Thompsonb7d059d2013-07-31 10:59:51 -070011#include "transport/UdpTransport.hpp"
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070012#include "encoding/BinaryXMLElementReader.hpp"
13
Jeff Thompsonbeb8b7d2013-07-16 15:49:21 -070014using namespace std;
15
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070016namespace ndn {
17
18class NDN : public ElementListener {
19public:
Jeff Thompson4a48e672013-07-31 10:41:07 -070020 NDN(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 Thompsonb7d059d2013-07-31 10:59:51 -070025 NDN(const char *host, unsigned short port)
26 : host_(host), port_(port), transport_(new UdpTransport())
27 {
28 }
29
Jeff Thompsonc172be32013-07-16 15:08:05 -070030 /**
31 * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors.
32 * Send the interest through the transport, read the entire response and call
33 * closure->upcall(UPCALL_CONTENT (or UPCALL_CONTENT_UNVERIFIED),
34 * UpcallInfo(this, interest, 0, contentObject)).
35 * @param name reference to a Name for the interest. This does not keep a pointer to the Name object.
36 * @param closure a shared_ptr for the Closure. This uses shared_ptr to take another reference to the object.
37 * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object.
38 */
39 void expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure, const Interest *interestTemplate);
40
Jeff Thompson0cb7aee2013-07-16 16:18:06 -070041 const char *getHost() const { return host_.c_str(); }
42
43 unsigned short getPort() const { return port_; }
Jeff Thompsonc172be32013-07-16 15:08:05 -070044
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070045 virtual void onReceivedElement(unsigned char *element, unsigned int elementLength);
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070046
47private:
Jeff Thompsonc172be32013-07-16 15:08:05 -070048 ptr_lib::shared_ptr<Transport> transport_;
Jeff Thompsonbeb8b7d2013-07-16 15:49:21 -070049 string host_;
50 unsigned short port_;
Jeff Thompsonc172be32013-07-16 15:08:05 -070051 ptr_lib::shared_ptr<Closure> tempClosure_;
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070052};
53
54}
55
56#endif