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); |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 19 | shared_ptr<vector<unsigned char> > encoding = interest.encode(); |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 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 | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 25 | transport_->send(*encoding); |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 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 | { |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 30 | BinaryXmlDecoder decoder(element, elementLength); |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 31 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame^] | 32 | if (decoder.peekDTag(ndn_BinaryXml_DTag_ContentObject)) { |
Jeff Thompson | 707d706 | 2013-07-16 16:32:40 -0700 | [diff] [blame] | 33 | shared_ptr<ContentObject> contentObject(new ContentObject()); |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 34 | contentObject->decode(element, elementLength); |
| 35 | |
Jeff Thompson | 707d706 | 2013-07-16 16:32:40 -0700 | [diff] [blame] | 36 | shared_ptr<Interest> dummyInterest; |
Jeff Thompson | 85ff99f | 2013-07-15 18:23:58 -0700 | [diff] [blame] | 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 | } |