blob: 1299e94ee0553c88b6c99352dcc33c17c987b763 [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);
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 Thompson707d7062013-07-16 16:32:40 -070033 shared_ptr<ContentObject> contentObject(new ContentObject());
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070034 contentObject->decode(element, elementLength);
35
Jeff Thompson707d7062013-07-16 16:32:40 -070036 shared_ptr<Interest> dummyInterest;
Jeff Thompson85ff99f2013-07-15 18:23:58 -070037 UpcallInfo upcallInfo(this, dummyInterest, 0, contentObject);
Jeff Thompsonc172be32013-07-16 15:08:05 -070038 tempClosure_->upcall(UPCALL_CONTENT, upcallInfo);
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070039 }
40}
41
42}