blob: 92cf799a847f5dcb355bc18f22545d9e795610a2 [file] [log] [blame]
Alexander Afanasyev42290b22017-03-09 12:58:29 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Wentao Shangbcbc9292014-04-28 21:17:06 -07002/**
weijia yuan3aa8d2b2018-03-06 15:35:57 -08003 * Copyright (c) 2014-2018, Regents of the University of California.
Wentao Shangbcbc9292014-04-28 21:17:06 -07004 *
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
25namespace repo {
26
27class Consumer : boost::noncopyable
28{
29public:
30 Consumer(const std::string& dataName, std::ostream& os,
Weiqi Shi5822e342014-08-21 20:05:30 -070031 bool verbose, bool versioned, bool single,
Wentao Shangbcbc9292014-04-28 21:17:06 -070032 int interestLifetime, int timeout,
weijia yuan3aa8d2b2018-03-06 15:35:57 -080033 bool mustBeFresh = false,
34 bool canBePrefix = false)
Wentao Shangbcbc9292014-04-28 21:17:06 -070035 : m_dataName(dataName)
36 , m_os(os)
37 , m_verbose(verbose)
Weiqi Shi5822e342014-08-21 20:05:30 -070038 , m_hasVersion(versioned)
39 , m_isSingle(single)
40 , m_isFinished(false)
41 , m_isFirst(true)
Wentao Shangbcbc9292014-04-28 21:17:06 -070042 , m_interestLifetime(interestLifetime)
43 , m_timeout(timeout)
44 , m_nextSegment(0)
45 , m_totalSize(0)
46 , m_retryCount(0)
47 , m_mustBeFresh(mustBeFresh)
weijia yuan3aa8d2b2018-03-06 15:35:57 -080048 , m_canBePrefix(canBePrefix)
Wentao Shangbcbc9292014-04-28 21:17:06 -070049 {
50 }
51
52 void
53 run();
54
55private:
56 void
57 fetchData(const ndn::Name& name);
58
59 void
Alexander Afanasyev42290b22017-03-09 12:58:29 -080060 onVersionedData(const ndn::Interest& interest, const ndn::Data& data);
Weiqi Shi5822e342014-08-21 20:05:30 -070061
62 void
Alexander Afanasyev42290b22017-03-09 12:58:29 -080063 onUnversionedData(const ndn::Interest& interest, const ndn::Data& data);
Wentao Shangbcbc9292014-04-28 21:17:06 -070064
65 void
66 onTimeout(const ndn::Interest& interest);
Alexander Afanasyev42290b22017-03-09 12:58:29 -080067
Weiqi Shi5822e342014-08-21 20:05:30 -070068 void
69 readData(const ndn::Data& data);
70
71 void
72 fetchNextData(const ndn::Name& name, const ndn::Data& data);
Wentao Shangbcbc9292014-04-28 21:17:06 -070073
74private:
Wentao Shangbcbc9292014-04-28 21:17:06 -070075
76 ndn::Face m_face;
77 ndn::Name m_dataName;
78 std::ostream& m_os;
79 bool m_verbose;
80 bool m_hasVersion;
Weiqi Shi5822e342014-08-21 20:05:30 -070081 bool m_isSingle;
82 bool m_isFinished;
83 bool m_isFirst;
Wentao Shangbcbc9292014-04-28 21:17:06 -070084 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 yuan3aa8d2b2018-03-06 15:35:57 -080090 bool m_canBePrefix;
Wentao Shangbcbc9292014-04-28 21:17:06 -070091};
92
93} // namespace repo
94
95#endif // REPO_NG_TOOLS_NDNGETFILE_HPP