blob: f2212ea09f560ffb62a0e6c9593646e62136e187 [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 Thompsonb9e3c8e2013-08-02 11:42:51 -07009#include "face.hpp"
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070010
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 Thompsonb9e3c8e2013-08-02 11:42:51 -070016void Face::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 Thompsonb9e3c8e2013-08-02 11:42:51 -070028void Face::onReceivedElement(unsigned char *element, unsigned int elementLength)
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070029{
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}