blob: 20609fe065b789b40d7a865fe00e9841e228d6ce [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;
12
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070013namespace ndn {
14
Jeff Thompsonc172be32013-07-16 15:08:05 -070015void NDN::expressInterest(const Name &name, const ptr_lib::shared_ptr<Closure> &closure, const Interest *interestTemplate)
16{
17 Interest interest(name);
18 vector<unsigned char> encoding;
19 interest.encode(encoding);
20
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 Thompsonc172be32013-07-16 15:08:05 -070025 transport_->send(&encoding[0], encoding.size());
26}
27
Jeff Thompsonaa4e6db2013-07-15 17:25:23 -070028void NDN::onReceivedElement(unsigned char *element, unsigned int elementLength)
29{
30 BinaryXMLDecoder decoder(element, elementLength);
31
32 if (decoder.peekDTag(ndn_BinaryXML_DTag_ContentObject)) {
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070033 ptr_lib::shared_ptr<ContentObject> contentObject(new ContentObject());
34 contentObject->decode(element, elementLength);
35
Jeff Thompson85ff99f2013-07-15 18:23:58 -070036 ptr_lib::shared_ptr<Interest> dummyInterest;
37 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}