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