| /** |
| * @author: Jeff Thompson |
| * See COPYING for copyright and distribution information. |
| */ |
| |
| #ifndef NDN_NDN_HPP |
| #define NDN_NDN_HPP |
| |
| #include "Closure.hpp" |
| #include "Interest.hpp" |
| #include "transport/UdpTransport.hpp" |
| #include "encoding/BinaryXMLElementReader.hpp" |
| |
| using namespace std; |
| |
| namespace ndn { |
| |
| class NDN : public ElementListener { |
| public: |
| NDN(const char *host, unsigned short port, const ptr_lib::shared_ptr<Transport> &transport) |
| : host_(host), port_(port), transport_(transport) |
| { |
| } |
| |
| NDN(const char *host, unsigned short port) |
| : host_(host), port_(port), transport_(new UdpTransport()) |
| { |
| } |
| |
| NDN(const char *host) |
| : host_(host), port_(9695), transport_(new UdpTransport()) |
| { |
| } |
| |
| /** |
| * Encode name as an Interest. If interestTemplate is not 0, use its interest selectors. |
| * Send the interest through the transport, read the entire response and call |
| * closure->upcall(UPCALL_CONTENT (or UPCALL_CONTENT_UNVERIFIED), |
| * UpcallInfo(this, interest, 0, contentObject)). |
| * @param name reference to a Name for the interest. This does not keep a pointer to the Name object. |
| * @param closure a shared_ptr for the Closure. This uses shared_ptr to take another reference to the object. |
| * @param interestTemplate if not 0, copy interest selectors from the template. This does not keep a pointer to the Interest object. |
| */ |
| void expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure, const Interest *interestTemplate); |
| |
| void expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure) |
| { |
| expressInterest(name, closure, 0); |
| } |
| |
| const char *getHost() const { return host_.c_str(); } |
| |
| unsigned short getPort() const { return port_; } |
| |
| virtual void onReceivedElement(unsigned char *element, unsigned int elementLength); |
| |
| private: |
| ptr_lib::shared_ptr<Transport> transport_; |
| string host_; |
| unsigned short port_; |
| ptr_lib::shared_ptr<Closure> tempClosure_; |
| }; |
| |
| } |
| |
| #endif |