blob: 6524331562f3565367520f439df01bedda80edf7 [file] [log] [blame]
Jeff Thompsonc98be1a2013-07-14 22:44:43 -07001/**
2 * @author: Jeff Thompson
3 * See COPYING for copyright and distribution information.
4 */
5
6#include <cstdlib>
7#include <sstream>
8#include <iostream>
9#include <ndn-cpp/Interest.hpp>
10#include <ndn-cpp/ContentObject.hpp>
Jeff Thompsonbc53c522013-07-17 17:11:48 -070011#include <ndn-cpp/transport/UdpTransport.hpp>
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070012#include <ndn-cpp/NDN.hpp>
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070013
14using namespace std;
15using namespace ndn;
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070016using namespace ptr_lib;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070017
18class MyClosure : public Closure {
19public:
Jeff Thompsonb002f902013-07-16 18:07:18 -070020 MyClosure()
21 : gotContent_(false)
22 {
23 }
24
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070025 virtual UpcallResult upcall(UpcallKind kind, UpcallInfo &upcallInfo)
26 {
27 if (kind == UPCALL_CONTENT || kind == UPCALL_CONTENT_UNVERIFIED) {
Jeff Thompsonb002f902013-07-16 18:07:18 -070028 gotContent_ = true;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070029 cout << "Got content with name " << upcallInfo.getContentObject()->getName().to_uri() << endl;
30 for (unsigned int i = 0; i < upcallInfo.getContentObject()->getContent().size(); ++i)
31 cout << upcallInfo.getContentObject()->getContent()[i];
32 cout << endl;
33
34 return CLOSURE_RESULT_OK;
35 }
36 else
37 return CLOSURE_RESULT_OK;
38 }
Jeff Thompsonb002f902013-07-16 18:07:18 -070039
40 bool gotContent_;
Jeff Thompsonb982b6d2013-07-15 18:15:45 -070041};
42
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070043int main(int argc, char** argv)
44{
45 try {
Jeff Thompsonbc53c522013-07-17 17:11:48 -070046 shared_ptr<UdpTransport> transport(new UdpTransport());
Jeff Thompsonb002f902013-07-16 18:07:18 -070047 shared_ptr<MyClosure> closure(new MyClosure());
Jeff Thompson4a48e672013-07-31 10:41:07 -070048 NDN ndn("E.hub.ndn.ucla.edu", 9695, transport);
Jeff Thompsoncdf7e252013-07-31 12:41:47 -070049 ndn.expressInterest(Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E"), closure);
Jeff Thompson3a217062013-07-14 23:37:42 -070050
Jeff Thompsonb002f902013-07-16 18:07:18 -070051 // Pump the receive process. This should really be done by a socket listener.
52 while (!closure->gotContent_)
53 transport->tempReceive();
Jeff Thompson1bbc4e72013-07-16 16:30:55 -070054 } catch (std::exception &e) {
Jeff Thompsonc98be1a2013-07-14 22:44:43 -070055 cout << "exception: " << e.what() << endl;
56 }
57 return 0;
58}