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 | #include "encoding/BinaryXMLDecoder.hpp" |
| 7 | #include "c/encoding/BinaryXML.h" |
| 8 | #include "ContentObject.hpp" |
| 9 | #include "NDN.hpp" |
| 10 | |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 11 | using namespace std; |
| 12 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 13 | namespace ndn { |
| 14 | |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 15 | void NDN::expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure, const Interest *interestTemplate) |
| 16 | { |
| 17 | Interest interest(name); |
| 18 | vector<unsigned char> encoding; |
| 19 | interest.encode(encoding); |
| 20 | |
Jeff Thompson | beb8b7d | 2013-07-16 15:49:21 -0700 | [diff] [blame] | 21 | transport_->connect(host_.c_str(), port_); |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 22 | transport_->send(&encoding[0], encoding.size()); |
| 23 | } |
| 24 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 25 | void NDN::onReceivedElement(unsigned char *element, unsigned int elementLength) |
| 26 | { |
| 27 | BinaryXMLDecoder decoder(element, elementLength); |
| 28 | |
| 29 | if (decoder.peekDTag(ndn_BinaryXML_DTag_ContentObject)) { |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 30 | ptr_lib::shared_ptr<ContentObject> contentObject(new ContentObject()); |
| 31 | contentObject->decode(element, elementLength); |
| 32 | |
Jeff Thompson | 85ff99f | 2013-07-15 18:23:58 -0700 | [diff] [blame] | 33 | ptr_lib::shared_ptr<Interest> dummyInterest; |
| 34 | UpcallInfo upcallInfo(this, dummyInterest, 0, contentObject); |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 35 | tempClosure_->upcall(UPCALL_CONTENT, upcallInfo); |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
| 39 | } |