Jeff Thompson | bf50a1a | 2013-08-20 18:01:01 -0700 | [diff] [blame^] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include "encoding/binary-xml-decoder.hpp" |
| 7 | #include "c/encoding/binary-xml.h" |
| 8 | #include "data.hpp" |
| 9 | #include "Node.hpp" |
| 10 | |
| 11 | using namespace std; |
| 12 | using namespace ndn::ptr_lib; |
| 13 | |
| 14 | namespace ndn { |
| 15 | |
| 16 | void Node::expressInterest(const Name &name, Closure *closure, const Interest *interestTemplate) |
| 17 | { |
| 18 | Interest interest(name); |
| 19 | shared_ptr<vector<unsigned char> > encoding = interest.wireEncode(); |
| 20 | |
| 21 | // TODO: This should go in the PIT. |
| 22 | tempClosure_ = closure; |
| 23 | |
| 24 | transport_->connect(*this); |
| 25 | transport_->send(*encoding); |
| 26 | } |
| 27 | |
| 28 | void Node::processEvents() |
| 29 | { |
| 30 | transport_->processEvents(); |
| 31 | } |
| 32 | |
| 33 | void Node::onReceivedElement(unsigned char *element, unsigned int elementLength) |
| 34 | { |
| 35 | BinaryXmlDecoder decoder(element, elementLength); |
| 36 | |
| 37 | if (decoder.peekDTag(ndn_BinaryXml_DTag_ContentObject)) { |
| 38 | shared_ptr<Data> data(new Data()); |
| 39 | data->wireDecode(element, elementLength); |
| 40 | |
| 41 | shared_ptr<Interest> dummyInterest; |
| 42 | UpcallInfo upcallInfo(this, dummyInterest, 0, data); |
| 43 | tempClosure_->upcall(UPCALL_DATA, upcallInfo); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void Node::shutdown() |
| 48 | { |
| 49 | transport_->close(); |
| 50 | } |
| 51 | |
| 52 | } |