blob: 061a2bff7002c4d7050a387c36ce0694f16e31f4 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3 * Copyright (c) 2016, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
6 *
7 * This file is part of ndn-tools (Named Data Networking Essential Tools).
8 * See AUTHORS.md for complete list of ndn-tools authors and contributors.
9 *
10 * ndn-tools is free software: you can redistribute it and/or modify it under the terms
11 * of the GNU General Public License as published by the Free Software Foundation,
12 * either version 3 of the License, or (at your option) any later version.
13 *
14 * ndn-tools is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 * PURPOSE. See the GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * ndn-tools, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
20 *
21 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
22 *
23 * @author Wentao Shang
24 * @author Steve DiBenedetto
25 * @author Andrea Tosatto
26 */
27
28#ifndef NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP
29#define NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP
30
31#include "core/common.hpp"
32
33namespace ndn {
34namespace chunks {
35
36/**
37 * @brief Segmented version Producer
38 *
39 * Packetizes and publishes data from an input stream under /prefix/<version>/<segment number>.
40 * The current time is used as the version number. The store has always at least one element (also
41 * with empty input stream).
42 */
43class Producer : noncopyable
44{
45public:
46 /**
47 * @brief Create the Producer
48 *
49 * @prefix prefix used to publish data, if the last component of prefix is not a version number
50 * the current time is used as version number.
51 */
52 Producer(const Name& prefix, Face& face, KeyChain& keyChain,
53 const security::SigningInfo& signingInfo, time::milliseconds freshnessPeriod,
54 size_t maxSegmentSize, bool isVerbose = false, bool needToPrintVersion = false,
55 std::istream& is = std::cin);
56
57 /**
58 * @brief Run the Producer
59 */
60 void
61 run();
62
63private:
64 void
65 onInterest(const Interest& interest);
66
67 /**
68 * @brief Split the input stream in data packets and save them to the store
69 *
70 * Create data packets reading all the characters from the input stream until EOF, or an
71 * error occurs. Each data packet has a maximum payload size of m_maxSegmentSize value and is
72 * stored inside the vector m_store. An empty data packet is created and stored if the input
73 * stream is empty.
74 *
75 * @return Number of data packets contained in the store after the operation
76 */
77 void
78 populateStore(std::istream& is);
79
80 void
81 onRegisterFailed(const Name& prefix, const std::string& reason);
82
83PUBLIC_WITH_TESTS_ELSE_PRIVATE:
84 std::vector<shared_ptr<Data>> m_store;
85
86private:
87 Name m_prefix;
88 Name m_versionedPrefix;
89 Face& m_face;
90 KeyChain& m_keyChain;
91 security::SigningInfo m_signingInfo;
92 time::milliseconds m_freshnessPeriod;
93 size_t m_maxSegmentSize;
94 bool m_isVerbose;
95};
96
97} // namespace chunks
98} // namespace ndn
99
100#endif // NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP