blob: 8e84440fef9bdd4d19198aed5e1e8d8a2b540975 [file] [log] [blame]
Wentao Shangbcbc9292014-04-28 21:17:06 -07001/* -*- 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
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,
33 bool mustBeFresh = false)
34 : m_dataName(dataName)
35 , m_os(os)
36 , m_verbose(verbose)
Weiqi Shi5822e342014-08-21 20:05:30 -070037 , m_hasVersion(versioned)
38 , m_isSingle(single)
39 , m_isFinished(false)
40 , m_isFirst(true)
Wentao Shangbcbc9292014-04-28 21:17:06 -070041 , 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
53private:
54 void
55 fetchData(const ndn::Name& name);
56
57 void
Weiqi Shi5822e342014-08-21 20:05:30 -070058 onVersionedData(const ndn::Interest& interest, ndn::Data& data);
59
60 void
61 onUnversionedData(const ndn::Interest& interest, ndn::Data& data);
Wentao Shangbcbc9292014-04-28 21:17:06 -070062
63 void
64 onTimeout(const ndn::Interest& interest);
Weiqi Shi5822e342014-08-21 20:05:30 -070065
66 void
67 readData(const ndn::Data& data);
68
69 void
70 fetchNextData(const ndn::Name& name, const ndn::Data& data);
Wentao Shangbcbc9292014-04-28 21:17:06 -070071
72private:
Wentao Shangbcbc9292014-04-28 21:17:06 -070073
74 ndn::Face m_face;
75 ndn::Name m_dataName;
76 std::ostream& m_os;
77 bool m_verbose;
78 bool m_hasVersion;
Weiqi Shi5822e342014-08-21 20:05:30 -070079 bool m_isSingle;
80 bool m_isFinished;
81 bool m_isFirst;
Wentao Shangbcbc9292014-04-28 21:17:06 -070082 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