blob: c34ff5e1874607133eaeffc0b51582d64862b0b7 [file] [log] [blame]
Andrea Tosatto672b9a72016-01-05 16:18:20 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento887336c2017-09-19 15:25:23 -04002/*
3 * Copyright (c) 2016-2017, Regents of the University of California,
4 * Colorado State University,
5 * University Pierre & Marie Curie, Sorbonne University.
Andrea Tosatto672b9a72016-01-05 16:18:20 +01006 *
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_CATCHUNKS_DISCOVER_VERSION_HPP
29#define NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_HPP
30
31#include "core/common.hpp"
32#include "options.hpp"
33
34namespace ndn {
35namespace chunks {
36
37class DataFetcher;
38
39/**
40 * @brief Base class of services for discovering the latest Data version
41 *
42 * DiscoverVersion's user is notified once after identifying the latest retrievable version or
43 * on failure to find any Data version.
44 */
45class DiscoverVersion : virtual protected Options, noncopyable
46{
47public: // signals
48 /**
49 * @brief Signal emited when the first segment of a specific version is found.
50 */
51 signal::Signal<DiscoverVersion, const Data&> onDiscoverySuccess;
52
53 /**
54 * @brief Signal emitted when a failure occurs.
55 */
56 signal::Signal<DiscoverVersion, const std::string&> onDiscoveryFailure;
57
58 DECLARE_SIGNAL_EMIT(onDiscoverySuccess)
59 DECLARE_SIGNAL_EMIT(onDiscoveryFailure)
60
61public:
62 /**
63 * @brief create a DiscoverVersion service
64 */
65 DiscoverVersion(const Name& prefix, Face& face, const Options& options);
66
Davide Pesavento887336c2017-09-19 15:25:23 -040067 virtual
68 ~DiscoverVersion();
69
Andrea Tosatto672b9a72016-01-05 16:18:20 +010070 /**
71 * @brief identify the latest Data version published.
72 */
73 virtual void
74 run() = 0;
75
76protected:
77 void
78 expressInterest(const Interest& interest, int maxRetriesNack, int maxRetriesTimeout);
79
80 virtual void
81 handleData(const Interest& interest, const Data& data);
82
83 virtual void
84 handleNack(const Interest& interest, const std::string& reason);
85
86 virtual void
87 handleTimeout(const Interest& interest, const std::string& reason);
88
89protected:
90 const Name m_prefix;
91 Face& m_face;
92 shared_ptr<DataFetcher> fetcher;
93};
94
95} // namespace chunks
96} // namespace ndn
97
98#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_HPP