Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 6 | #include "encoding/binary-xml-decoder.hpp" |
| 7 | #include "c/encoding/binary-xml.h" |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 8 | #include "data.hpp" |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 9 | #include "face.hpp" |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 10 | |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 11 | using namespace std; |
Jeff Thompson | 707d706 | 2013-07-16 16:32:40 -0700 | [diff] [blame] | 12 | using namespace ndn::ptr_lib; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 13 | |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 14 | namespace ndn { |
| 15 | |
Jeff Thompson | 2a4724b | 2013-08-07 17:13:34 -0700 | [diff] [blame^] | 16 | void Face::expressInterest(const Name &name, Closure *closure, const Interest *interestTemplate) |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 17 | { |
| 18 | Interest interest(name); |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 19 | shared_ptr<vector<unsigned char> > encoding = interest.wireEncode(); |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 20 | |
Jeff Thompson | 9657bda | 2013-07-16 16:23:41 -0700 | [diff] [blame] | 21 | // TODO: This should go in the PIT. |
| 22 | tempClosure_ = closure; |
| 23 | |
Jeff Thompson | 0cb7aee | 2013-07-16 16:18:06 -0700 | [diff] [blame] | 24 | transport_->connect(*this); |
Jeff Thompson | b0979fd | 2013-07-30 15:48:21 -0700 | [diff] [blame] | 25 | transport_->send(*encoding); |
Jeff Thompson | c172be3 | 2013-07-16 15:08:05 -0700 | [diff] [blame] | 26 | } |
| 27 | |
Jeff Thompson | 517ffa8 | 2013-08-05 16:04:34 -0700 | [diff] [blame] | 28 | void Face::shutdown() |
| 29 | { |
| 30 | transport_->close(); |
| 31 | } |
| 32 | |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 33 | void Face::onReceivedElement(unsigned char *element, unsigned int elementLength) |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 34 | { |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 35 | BinaryXmlDecoder decoder(element, elementLength); |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 36 | |
Jeff Thompson | f0fea00 | 2013-07-30 17:22:42 -0700 | [diff] [blame] | 37 | if (decoder.peekDTag(ndn_BinaryXml_DTag_ContentObject)) { |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 38 | shared_ptr<Data> data(new Data()); |
Jeff Thompson | 67e9e0a | 2013-08-02 19:16:19 -0700 | [diff] [blame] | 39 | data->wireDecode(element, elementLength); |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 40 | |
Jeff Thompson | 707d706 | 2013-07-16 16:32:40 -0700 | [diff] [blame] | 41 | shared_ptr<Interest> dummyInterest; |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 42 | UpcallInfo upcallInfo(this, dummyInterest, 0, data); |
| 43 | tempClosure_->upcall(UPCALL_DATA, upcallInfo); |
Jeff Thompson | aa4e6db | 2013-07-15 17:25:23 -0700 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | } |