Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (C) 2013 Regents of the University of California. |
| 4 | * @author: Alexander Afanasyev <alexander.afanasyev@ucla.edu> |
| 5 | * See COPYING for copyright and distribution information. |
| 6 | */ |
| 7 | |
Alexander Afanasyev | 09c613f | 2014-01-29 00:23:58 -0800 | [diff] [blame] | 8 | // correct way to include NDN-CPP headers |
| 9 | // #include <ndn-cpp-dev/face.hpp> |
| 10 | #include "face.hpp" |
| 11 | |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 12 | void |
| 13 | onData(ndn::Face &face, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 14 | const ndn::Interest& interest, ndn::Data& data) |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 15 | { |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 16 | std::cout << "I: " << interest.toUri() << std::endl; |
| 17 | std::cout << "D: " << data.getName().toUri() << std::endl; |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | void |
| 21 | onTimeout(ndn::Face &face, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 22 | const ndn::Interest& interest) |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 23 | { |
| 24 | std::cout << "Timeout" << std::endl; |
| 25 | } |
| 26 | |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 27 | int main() |
| 28 | { |
| 29 | try { |
| 30 | ndn::Interest i(ndn::Name("/localhost/testApp/randomData")); |
| 31 | i.setScope(1); |
Alexander Afanasyev | aa0e7da | 2014-03-17 14:37:33 -0700 | [diff] [blame] | 32 | i.setInterestLifetime(ndn::time::milliseconds(1000)); |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 33 | i.setMustBeFresh(true); |
| 34 | |
| 35 | ndn::Face face; |
| 36 | face.expressInterest(i, |
Alexander Afanasyev | 0222fba | 2014-02-09 23:16:02 -0800 | [diff] [blame] | 37 | ndn::bind(onData, boost::ref(face), _1, _2), |
| 38 | ndn::bind(onTimeout, boost::ref(face), _1)); |
Alexander Afanasyev | c4b7598 | 2014-01-09 14:51:45 -0800 | [diff] [blame] | 39 | |
| 40 | // processEvents will block until the requested data received or timeout occurs |
| 41 | face.processEvents(); |
| 42 | } |
| 43 | catch(std::exception &e) { |
| 44 | std::cerr << "ERROR: " << e.what() << std::endl; |
| 45 | } |
| 46 | return 0; |
| 47 | } |