Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 1 | /** |
| 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 Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 9 | #include "Closure.hpp" |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 10 | #include "Interest.hpp" |
Jeff Thompson | b7d059d | 2013-07-31 10:59:51 -0700 | [diff] [blame] | 11 | #include "transport/UdpTransport.hpp" |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 12 | #include "encoding/BinaryXMLElementReader.hpp" |
| 13 | |
Jeff Thompson | beb8b7d | 2013-07-16 15:49:21 -0700 | [diff] [blame] | 14 | using namespace std; |
| 15 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 16 | namespace ndn { |
| 17 | |
| 18 | class NDN : public ElementListener { |
| 19 | public: |
Jeff Thompson | 4a48e67 | 2013-07-31 10:41:07 -0700 | [diff] [blame] | 20 | NDN(const char *host, unsigned short port, const ptr_lib::shared_ptr<Transport> &transport) |
Jeff Thompson | b7d059d | 2013-07-31 10:59:51 -0700 | [diff] [blame] | 21 | : host_(host), port_(port), transport_(transport) |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 22 | { |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 23 | } |
| 24 | |
Jeff Thompson | b7d059d | 2013-07-31 10:59:51 -0700 | [diff] [blame] | 25 | NDN(const char *host, unsigned short port) |
| 26 | : host_(host), port_(port), transport_(new UdpTransport()) |
| 27 | { |
| 28 | } |
Jeff Thompson | 1242b1f | 2013-07-31 11:02:00 -0700 | [diff] [blame] | 29 | |
| 30 | NDN(const char *host) |
| 31 | : host_(host), port_(9695), transport_(new UdpTransport()) |
| 32 | { |
| 33 | } |
Jeff Thompson | b7d059d | 2013-07-31 10:59:51 -0700 | [diff] [blame] | 34 | |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 35 | /** |
| 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 |
| 38 | * closure->upcall(UPCALL_CONTENT (or UPCALL_CONTENT_UNVERIFIED), |
| 39 | * UpcallInfo(this, interest, 0, contentObject)). |
| 40 | * @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 Thompson | cdf7e25 | 2013-07-31 12:41:47 -0700 | [diff] [blame] | 46 | void expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure) |
| 47 | { |
| 48 | expressInterest(name, closure, 0); |
| 49 | } |
| 50 | |
Jeff Thompson | 0cb7aee | 2013-07-16 16:18:06 -0700 | [diff] [blame] | 51 | const char *getHost() const { return host_.c_str(); } |
| 52 | |
| 53 | unsigned short getPort() const { return port_; } |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 54 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 55 | virtual void onReceivedElement(unsigned char *element, unsigned int elementLength); |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 56 | |
| 57 | private: |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 58 | ptr_lib::shared_ptr<Transport> transport_; |
Jeff Thompson | beb8b7d | 2013-07-16 15:49:21 -0700 | [diff] [blame] | 59 | string host_; |
| 60 | unsigned short port_; |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 61 | ptr_lib::shared_ptr<Closure> tempClosure_; |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | } |
| 65 | |
| 66 | #endif |