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 | 9657bda | 2013-07-16 16:23:41 -0700 | [diff] [blame^] | 21 | // TODO: This should go in the PIT. |
| 22 | tempClosure_ = closure; |
| 23 | |
Jeff Thompson | 0cb7aee | 2013-07-16 16:18:06 -0700 | [diff] [blame] | 24 | transport_->connect(*this); |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 25 | transport_->send(&encoding[0], encoding.size()); |
| 26 | } |
| 27 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 28 | void NDN::onReceivedElement(unsigned char *element, unsigned int elementLength) |
| 29 | { |
| 30 | BinaryXMLDecoder decoder(element, elementLength); |
| 31 | |
| 32 | if (decoder.peekDTag(ndn_BinaryXML_DTag_ContentObject)) { |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 33 | ptr_lib::shared_ptr<ContentObject> contentObject(new ContentObject()); |
| 34 | contentObject->decode(element, elementLength); |
| 35 | |
Jeff Thompson | 85ff99f | 2013-07-15 18:23:58 -0700 | [diff] [blame] | 36 | ptr_lib::shared_ptr<Interest> dummyInterest; |
| 37 | UpcallInfo upcallInfo(this, dummyInterest, 0, contentObject); |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 38 | tempClosure_->upcall(UPCALL_CONTENT, upcallInfo); |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 39 | } |
| 40 | } |
| 41 | |
| 42 | } |