Jeff Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 1 | /** |
| 2 | * @author: Jeff Thompson |
| 3 | * See COPYING for copyright and distribution information. |
| 4 | */ |
| 5 | |
| 6 | #include <cstdlib> |
| 7 | #include <sstream> |
| 8 | #include <iostream> |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 9 | #include <ndn-cpp/interest.hpp> |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 10 | #include <ndn-cpp/data.hpp> |
Jeff Thompson | 5341219 | 2013-08-06 13:35:50 -0700 | [diff] [blame] | 11 | #include <ndn-cpp/transport/udp-transport.hpp> |
Jeff Thompson | b9e3c8e | 2013-08-02 11:42:51 -0700 | [diff] [blame] | 12 | #include <ndn-cpp/face.hpp> |
Jeff Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 13 | |
| 14 | using namespace std; |
| 15 | using namespace ndn; |
Jeff Thompson | 1bbc4e7 | 2013-07-16 16:30:55 -0700 | [diff] [blame] | 16 | using namespace ptr_lib; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 17 | |
| 18 | class MyClosure : public Closure { |
| 19 | public: |
Jeff Thompson | b002f90 | 2013-07-16 18:07:18 -0700 | [diff] [blame] | 20 | MyClosure() |
| 21 | : gotContent_(false) |
| 22 | { |
| 23 | } |
| 24 | |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 25 | virtual UpcallResult upcall(UpcallKind kind, UpcallInfo &upcallInfo) |
| 26 | { |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 27 | if (kind == UPCALL_DATA || kind == UPCALL_DATA_UNVERIFIED) { |
Jeff Thompson | b002f90 | 2013-07-16 18:07:18 -0700 | [diff] [blame] | 28 | gotContent_ = true; |
Jeff Thompson | 56ec9e2 | 2013-08-02 11:34:07 -0700 | [diff] [blame] | 29 | cout << "Got data packet with name " << upcallInfo.getData()->getName().to_uri() << endl; |
| 30 | for (unsigned int i = 0; i < upcallInfo.getData()->getContent().size(); ++i) |
| 31 | cout << upcallInfo.getData()->getContent()[i]; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 32 | cout << endl; |
| 33 | |
| 34 | return CLOSURE_RESULT_OK; |
| 35 | } |
| 36 | else |
| 37 | return CLOSURE_RESULT_OK; |
| 38 | } |
Jeff Thompson | b002f90 | 2013-07-16 18:07:18 -0700 | [diff] [blame] | 39 | |
| 40 | bool gotContent_; |
Jeff Thompson | b982b6d | 2013-07-15 18:15:45 -0700 | [diff] [blame] | 41 | }; |
| 42 | |
Jeff Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 43 | int main(int argc, char** argv) |
| 44 | { |
| 45 | try { |
Jeff Thompson | 2a4724b | 2013-08-07 17:13:34 -0700 | [diff] [blame] | 46 | MyClosure closure; |
Jeff Thompson | 7098dd6 | 2013-08-06 14:42:02 -0700 | [diff] [blame] | 47 | Face face("E.hub.ndn.ucla.edu", 9695, shared_ptr<UdpTransport>(new UdpTransport())); |
Jeff Thompson | 2a4724b | 2013-08-07 17:13:34 -0700 | [diff] [blame] | 48 | face.expressInterest(Name("/ndn/ucla.edu/apps/ndn-js-test/hello.txt/level2/%FD%05%0B%16%7D%95%0E"), &closure); |
Jeff Thompson | 3a21706 | 2013-07-14 23:37:42 -0700 | [diff] [blame] | 49 | |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 50 | // The main event loop. |
Jeff Thompson | 2a4724b | 2013-08-07 17:13:34 -0700 | [diff] [blame] | 51 | while (!closure.gotContent_) |
Jeff Thompson | 432c8be | 2013-08-09 16:16:08 -0700 | [diff] [blame] | 52 | face.processEvents(); |
Jeff Thompson | 1bbc4e7 | 2013-07-16 16:30:55 -0700 | [diff] [blame] | 53 | } catch (std::exception &e) { |
Jeff Thompson | c98be1a | 2013-07-14 22:44:43 -0700 | [diff] [blame] | 54 | cout << "exception: " << e.what() << endl; |
| 55 | } |
| 56 | return 0; |
| 57 | } |