blob: fed4c8e3d9ab6aea689b7652595008d74ebc483d [file] [log] [blame]
Jeff Thompsonbf50a1a2013-08-20 18:01:01 -07001/**
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
11using namespace std;
12using namespace ndn::ptr_lib;
13
14namespace ndn {
15
16void 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
28void Node::processEvents()
29{
30 transport_->processEvents();
31}
32
33void 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
47void Node::shutdown()
48{
49 transport_->close();
50}
51
52}