blob: c25fff3c5c7b0f6e0529541c29acc923155fc18a [file] [log] [blame]
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -07001/**
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 Thompsonb982b6d2013-07-15 18:15:45 -070011using namespace std;
Jeff Thompson707d7062013-07-16 16:32:40 -070012using namespace ndn::ptr_lib;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070013
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070014namespace ndn {
15
Jeff Thompson707d7062013-07-16 16:32:40 -070016void NDN::expressInterest(const Name &name, const shared_ptr<Closure> &closure, const Interest *interestTemplate)
Jeff Thompsonc172be32013-07-16 15:08:05 -070017{
18 Interest interest(name);
19 vector<unsigned char> encoding;
20 interest.encode(encoding);
21
Jeff Thompson9657bda2013-07-16 16:23:41 -070022 // TODO: This should go in the PIT.
23 tempClosure_ = closure;
24
Jeff Thompson0cb7aee2013-07-16 16:18:06 -070025 transport_->connect(*this);
Jeff Thompsonc172be32013-07-16 15:08:05 -070026 transport_->send(&encoding[0], encoding.size());
27}
28
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070029void NDN::onReceivedElement(unsigned char *element, unsigned int elementLength)
30{
31 BinaryXMLDecoder decoder(element, elementLength);
32
33 if (decoder.peekDTag(ndn_BinaryXML_DTag_ContentObject)) {
Jeff Thompson707d7062013-07-16 16:32:40 -070034 shared_ptr<ContentObject> contentObject(new ContentObject());
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070035 contentObject->decode(element, elementLength);
36
Jeff Thompson707d7062013-07-16 16:32:40 -070037 shared_ptr<Interest> dummyInterest;
Jeff Thompson85ff99f2013-07-15 18:23:58 -070038 UpcallInfo upcallInfo(this, dummyInterest, 0, contentObject);
Jeff Thompsonc172be32013-07-16 15:08:05 -070039 tempClosure_->upcall(UPCALL_CONTENT, upcallInfo);
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070040 }
41}
42
43}