blob: 206af4327d22508c5fbdbada6f44ca7617ac8dd6 [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"
Jeff Thompson56ec9e22013-08-02 11:34:07 -07008#include "data.hpp"
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -07009#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);
Jeff Thompsonb0979fd2013-07-30 15:48:21 -070019 shared_ptr<vector<unsigned char> > encoding = interest.encode();
Jeff Thompsonc172be32013-07-16 15:08:05 -070020
Jeff Thompson9657bda2013-07-16 16:23:41 -070021 // TODO: This should go in the PIT.
22 tempClosure_ = closure;
23
Jeff Thompson0cb7aee2013-07-16 16:18:06 -070024 transport_->connect(*this);
Jeff Thompsonb0979fd2013-07-30 15:48:21 -070025 transport_->send(*encoding);
Jeff Thompsonc172be32013-07-16 15:08:05 -070026}
27
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070028void NDN::onReceivedElement(unsigned char *element, unsigned int elementLength)
29{
Jeff Thompsonf0fea002013-07-30 17:22:42 -070030 BinaryXmlDecoder decoder(element, elementLength);
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070031
Jeff Thompsonf0fea002013-07-30 17:22:42 -070032 if (decoder.peekDTag(ndn_BinaryXml_DTag_ContentObject)) {
Jeff Thompson56ec9e22013-08-02 11:34:07 -070033 shared_ptr<Data> data(new Data());
34 data->decode(element, elementLength);
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070035
Jeff Thompson707d7062013-07-16 16:32:40 -070036 shared_ptr<Interest> dummyInterest;
Jeff Thompson56ec9e22013-08-02 11:34:07 -070037 UpcallInfo upcallInfo(this, dummyInterest, 0, data);
38 tempClosure_->upcall(UPCALL_DATA, upcallInfo);
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070039 }
40}
41
42}