blob: 86dcad77b17d858e2e1400a9f625d5f9204db5c3 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Klaus Schneider59ec95a2017-09-14 17:50:00 -07002/*
3 * Copyright (c) 2016-2017, Regents of the University of California,
Andrea Tosatto672b9a72016-01-05 16:18:20 +01004 * 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
Klaus Schneider59ec95a2017-09-14 17:50:00 -070026 * @author Klaus Schneider
Andrea Tosatto672b9a72016-01-05 16:18:20 +010027 */
28
29#ifndef NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP
30#define NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP
31
32#include "core/common.hpp"
33
34namespace ndn {
35namespace chunks {
36
37/**
38 * @brief Segmented version Producer
39 *
40 * Packetizes and publishes data from an input stream under /prefix/<version>/<segment number>.
41 * The current time is used as the version number. The store has always at least one element (also
42 * with empty input stream).
43 */
44class Producer : noncopyable
45{
46public:
47 /**
48 * @brief Create the Producer
49 *
50 * @prefix prefix used to publish data, if the last component of prefix is not a version number
51 * the current time is used as version number.
52 */
53 Producer(const Name& prefix, Face& face, KeyChain& keyChain,
54 const security::SigningInfo& signingInfo, time::milliseconds freshnessPeriod,
Klaus Schneider59ec95a2017-09-14 17:50:00 -070055 size_t maxSegmentSize, bool isQuiet = false, bool isVerbose = false,
56 bool needToPrintVersion = false, std::istream& is = std::cin);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010057
58 /**
59 * @brief Run the Producer
60 */
61 void
62 run();
63
64private:
65 void
66 onInterest(const Interest& interest);
67
68 /**
69 * @brief Split the input stream in data packets and save them to the store
70 *
71 * Create data packets reading all the characters from the input stream until EOF, or an
72 * error occurs. Each data packet has a maximum payload size of m_maxSegmentSize value and is
73 * stored inside the vector m_store. An empty data packet is created and stored if the input
74 * stream is empty.
75 *
76 * @return Number of data packets contained in the store after the operation
77 */
78 void
79 populateStore(std::istream& is);
80
81 void
82 onRegisterFailed(const Name& prefix, const std::string& reason);
83
84PUBLIC_WITH_TESTS_ELSE_PRIVATE:
85 std::vector<shared_ptr<Data>> m_store;
86
87private:
88 Name m_prefix;
89 Name m_versionedPrefix;
90 Face& m_face;
91 KeyChain& m_keyChain;
92 security::SigningInfo m_signingInfo;
93 time::milliseconds m_freshnessPeriod;
94 size_t m_maxSegmentSize;
Klaus Schneider59ec95a2017-09-14 17:50:00 -070095 bool m_isQuiet;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010096 bool m_isVerbose;
97};
98
99} // namespace chunks
100} // namespace ndn
101
102#endif // NDN_TOOLS_CHUNKS_PUTCHUNKS_PRODUCER_HPP