blob: d5c174b76e156d08323822ac10753868302b97c1 [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 Thompson67e9e0a2013-08-02 19:16:19 -070019 shared_ptr<vector<unsigned char> > encoding = interest.wireEncode();
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 Thompson517ffa82013-08-05 16:04:34 -070028void Face::shutdown()
29{
30 transport_->close();
31}
32
Jeff Thompsonb9e3c8e2013-08-02 11:42:51 -070033void Face::onReceivedElement(unsigned char *element, unsigned int elementLength)
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070034{
Jeff Thompsonf0fea002013-07-30 17:22:42 -070035 BinaryXmlDecoder decoder(element, elementLength);
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070036
Jeff Thompsonf0fea002013-07-30 17:22:42 -070037 if (decoder.peekDTag(ndn_BinaryXml_DTag_ContentObject)) {
Jeff Thompson56ec9e22013-08-02 11:34:07 -070038 shared_ptr<Data> data(new Data());
Jeff Thompson67e9e0a2013-08-02 19:16:19 -070039 data->wireDecode(element, elementLength);
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070040
Jeff Thompson707d7062013-07-16 16:32:40 -070041 shared_ptr<Interest> dummyInterest;
Jeff Thompson56ec9e22013-08-02 11:34:07 -070042 UpcallInfo upcallInfo(this, dummyInterest, 0, data);
43 tempClosure_->upcall(UPCALL_DATA, upcallInfo);
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070044 }
45}
46
47}