Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */ |
| 2 | /** |
| 3 | * Copyright (c) 2014, Regents of the University of California. |
| 4 | * |
| 5 | * This file is part of NDN repo-ng (Next generation of NDN repository). |
| 6 | * See AUTHORS.md for complete list of repo-ng authors and contributors. |
| 7 | * |
| 8 | * repo-ng is free software: you can redistribute it and/or modify it under the terms |
| 9 | * of the GNU General Public License as published by the Free Software Foundation, |
| 10 | * either version 3 of the License, or (at your option) any later version. |
| 11 | * |
| 12 | * repo-ng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
| 13 | * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 14 | * PURPOSE. See the GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along with |
| 17 | * repo-ng, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>. |
| 18 | */ |
| 19 | |
| 20 | #ifndef REPO_NG_TOOLS_NDNGETFILE_HPP |
| 21 | #define REPO_NG_TOOLS_NDNGETFILE_HPP |
| 22 | |
| 23 | #include <ndn-cxx/face.hpp> |
| 24 | |
| 25 | namespace repo { |
| 26 | |
| 27 | class Consumer : boost::noncopyable |
| 28 | { |
| 29 | public: |
| 30 | Consumer(const std::string& dataName, std::ostream& os, |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 31 | bool verbose, bool versioned, bool single, |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 32 | int interestLifetime, int timeout, |
| 33 | bool mustBeFresh = false) |
| 34 | : m_dataName(dataName) |
| 35 | , m_os(os) |
| 36 | , m_verbose(verbose) |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 37 | , m_hasVersion(versioned) |
| 38 | , m_isSingle(single) |
| 39 | , m_isFinished(false) |
| 40 | , m_isFirst(true) |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 41 | , m_interestLifetime(interestLifetime) |
| 42 | , m_timeout(timeout) |
| 43 | , m_nextSegment(0) |
| 44 | , m_totalSize(0) |
| 45 | , m_retryCount(0) |
| 46 | , m_mustBeFresh(mustBeFresh) |
| 47 | { |
| 48 | } |
| 49 | |
| 50 | void |
| 51 | run(); |
| 52 | |
| 53 | private: |
| 54 | void |
| 55 | fetchData(const ndn::Name& name); |
| 56 | |
| 57 | void |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 58 | onVersionedData(const ndn::Interest& interest, ndn::Data& data); |
| 59 | |
| 60 | void |
| 61 | onUnversionedData(const ndn::Interest& interest, ndn::Data& data); |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 62 | |
| 63 | void |
| 64 | onTimeout(const ndn::Interest& interest); |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 65 | |
| 66 | void |
| 67 | readData(const ndn::Data& data); |
| 68 | |
| 69 | void |
| 70 | fetchNextData(const ndn::Name& name, const ndn::Data& data); |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 71 | |
| 72 | private: |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 73 | |
| 74 | ndn::Face m_face; |
| 75 | ndn::Name m_dataName; |
| 76 | std::ostream& m_os; |
| 77 | bool m_verbose; |
| 78 | bool m_hasVersion; |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 79 | bool m_isSingle; |
| 80 | bool m_isFinished; |
| 81 | bool m_isFirst; |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 82 | ndn::time::milliseconds m_interestLifetime; |
| 83 | ndn::time::milliseconds m_timeout; |
| 84 | uint64_t m_nextSegment; |
| 85 | int m_totalSize; |
| 86 | int m_retryCount; |
| 87 | bool m_mustBeFresh; |
| 88 | }; |
| 89 | |
| 90 | } // namespace repo |
| 91 | |
| 92 | #endif // REPO_NG_TOOLS_NDNGETFILE_HPP |