Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 2 | /** |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 3 | * Copyright (c) 2014-2018, Regents of the University of California. |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 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, |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 33 | bool mustBeFresh = false, |
| 34 | bool canBePrefix = false) |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 35 | : m_dataName(dataName) |
| 36 | , m_os(os) |
| 37 | , m_verbose(verbose) |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 38 | , m_hasVersion(versioned) |
| 39 | , m_isSingle(single) |
| 40 | , m_isFinished(false) |
| 41 | , m_isFirst(true) |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 42 | , m_interestLifetime(interestLifetime) |
| 43 | , m_timeout(timeout) |
| 44 | , m_nextSegment(0) |
| 45 | , m_totalSize(0) |
| 46 | , m_retryCount(0) |
| 47 | , m_mustBeFresh(mustBeFresh) |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 48 | , m_canBePrefix(canBePrefix) |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 49 | { |
| 50 | } |
| 51 | |
| 52 | void |
| 53 | run(); |
| 54 | |
| 55 | private: |
| 56 | void |
| 57 | fetchData(const ndn::Name& name); |
| 58 | |
| 59 | void |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 60 | onVersionedData(const ndn::Interest& interest, const ndn::Data& data); |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 61 | |
| 62 | void |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 63 | onUnversionedData(const ndn::Interest& interest, const ndn::Data& data); |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 64 | |
| 65 | void |
| 66 | onTimeout(const ndn::Interest& interest); |
Alexander Afanasyev | 42290b2 | 2017-03-09 12:58:29 -0800 | [diff] [blame] | 67 | |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 68 | void |
| 69 | readData(const ndn::Data& data); |
| 70 | |
| 71 | void |
| 72 | fetchNextData(const ndn::Name& name, const ndn::Data& data); |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 73 | |
| 74 | private: |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 75 | |
| 76 | ndn::Face m_face; |
| 77 | ndn::Name m_dataName; |
| 78 | std::ostream& m_os; |
| 79 | bool m_verbose; |
| 80 | bool m_hasVersion; |
Weiqi Shi | 5822e34 | 2014-08-21 20:05:30 -0700 | [diff] [blame] | 81 | bool m_isSingle; |
| 82 | bool m_isFinished; |
| 83 | bool m_isFirst; |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 84 | ndn::time::milliseconds m_interestLifetime; |
| 85 | ndn::time::milliseconds m_timeout; |
| 86 | uint64_t m_nextSegment; |
| 87 | int m_totalSize; |
| 88 | int m_retryCount; |
| 89 | bool m_mustBeFresh; |
weijia yuan | 3aa8d2b | 2018-03-06 15:35:57 -0800 | [diff] [blame] | 90 | bool m_canBePrefix; |
Wentao Shang | bcbc929 | 2014-04-28 21:17:06 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | } // namespace repo |
| 94 | |
| 95 | #endif // REPO_NG_TOOLS_NDNGETFILE_HPP |