blob: 5049cc2d31688192ab5511eba22523df56167d0f [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/*
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -08003 * Copyright (c) 2016-2019, Regents of the University of California,
Davide Pesavento887336c2017-09-19 15:25:23 -04004 * 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
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070026 * @author Chavoosh Ghasemi
Andrea Tosatto672b9a72016-01-05 16:18:20 +010027 */
28
29#ifndef NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_HPP
30#define NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_HPP
31
32#include "core/common.hpp"
33#include "options.hpp"
34
35namespace ndn {
36namespace chunks {
37
38class DataFetcher;
39
40/**
41 * @brief Base class of services for discovering the latest Data version
42 *
43 * DiscoverVersion's user is notified once after identifying the latest retrievable version or
44 * on failure to find any Data version.
45 */
46class DiscoverVersion : virtual protected Options, noncopyable
47{
48public: // signals
49 /**
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080050 * @brief Signal emitted when the versioned name of Data is found.
Andrea Tosatto672b9a72016-01-05 16:18:20 +010051 */
Chavoosh Ghasemi5cb67012019-02-15 09:56:57 -080052 signal::Signal<DiscoverVersion, Name> onDiscoverySuccess;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010053
54 /**
55 * @brief Signal emitted when a failure occurs.
56 */
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070057 signal::Signal<DiscoverVersion, std::string> onDiscoveryFailure;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010058
59public:
60 /**
61 * @brief create a DiscoverVersion service
62 */
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070063 DiscoverVersion(const Name& prefix, Face& face, const Options& options);
Davide Pesavento887336c2017-09-19 15:25:23 -040064
Andrea Tosatto672b9a72016-01-05 16:18:20 +010065 /**
66 * @brief identify the latest Data version published.
67 */
Andrea Tosatto672b9a72016-01-05 16:18:20 +010068 void
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070069 run();
Andrea Tosatto672b9a72016-01-05 16:18:20 +010070
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070071private:
72 void
73 handleData(const Interest& interest, const Data& data);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010074
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070075private:
Andrea Tosatto672b9a72016-01-05 16:18:20 +010076 const Name m_prefix;
77 Face& m_face;
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070078 shared_ptr<DataFetcher> m_fetcher;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010079};
80
81} // namespace chunks
82} // namespace ndn
83
84#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_HPP