blob: 26a4956c4002811fa933b91b2a7ee1e4f7fc8d55 [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,
31 bool verbose, bool unversioned,
32 int interestLifetime, int timeout,
33 bool mustBeFresh = false)
34 : m_dataName(dataName)
35 , m_os(os)
36 , m_verbose(verbose)
37 , m_hasVersion(unversioned)
38 , m_interestLifetime(interestLifetime)
39 , m_timeout(timeout)
40 , m_nextSegment(0)
41 , m_totalSize(0)
42 , m_retryCount(0)
43 , m_mustBeFresh(mustBeFresh)
44 {
45 }
46
47 void
48 run();
49
50private:
51 void
52 fetchData(const ndn::Name& name);
53
54 void
55 onData(const ndn::Interest& interest, ndn::Data& data);
56
57 void
58 onTimeout(const ndn::Interest& interest);
59
60private:
61 static const int MAX_RETRY;
62
63 ndn::Face m_face;
64 ndn::Name m_dataName;
65 std::ostream& m_os;
66 bool m_verbose;
67 bool m_hasVersion;
68 ndn::time::milliseconds m_interestLifetime;
69 ndn::time::milliseconds m_timeout;
70 uint64_t m_nextSegment;
71 int m_totalSize;
72 int m_retryCount;
73 bool m_mustBeFresh;
74};
75
76} // namespace repo
77
78#endif // REPO_NG_TOOLS_NDNGETFILE_HPP