blob: 1098d85e871be32b4801ee6288904270b5fe0ed5 [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/*
Davide Pesavento5748e822024-01-26 18:40:22 -05003 * Copyright (c) 2016-2024, 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
Andrea Tosatto672b9a72016-01-05 16:18:20 +010032#include "options.hpp"
33
Davide Pesavento5748e822024-01-26 18:40:22 -050034#include <ndn-cxx/face.hpp>
Davide Pesaventoa0e6b602021-01-21 19:47:04 -050035#include <ndn-cxx/util/signal.hpp>
36
Davide Pesaventob3570c62022-02-19 19:19:00 -050037namespace ndn::chunks {
Andrea Tosatto672b9a72016-01-05 16:18:20 +010038
39class DataFetcher;
40
41/**
Davide Pesavento97a33b22019-10-17 22:10:47 -040042 * @brief Service for discovering the latest Data version.
Andrea Tosatto672b9a72016-01-05 16:18:20 +010043 *
44 * DiscoverVersion's user is notified once after identifying the latest retrievable version or
45 * on failure to find any Data version.
46 */
Davide Pesavento97a33b22019-10-17 22:10:47 -040047class DiscoverVersion
Andrea Tosatto672b9a72016-01-05 16:18:20 +010048{
Andrea Tosatto672b9a72016-01-05 16:18:20 +010049public:
Davide Pesavento97a33b22019-10-17 22:10:47 -040050 DiscoverVersion(Face& face, const Name& prefix, const Options& options);
Davide Pesavento887336c2017-09-19 15:25:23 -040051
Andrea Tosatto672b9a72016-01-05 16:18:20 +010052 /**
Davide Pesaventoa0e6b602021-01-21 19:47:04 -050053 * @brief Signal emitted when the versioned name of Data is found.
Andrea Tosatto672b9a72016-01-05 16:18:20 +010054 */
Junxiao Shi869d73e2023-08-10 22:52:26 +000055 signal::Signal<DiscoverVersion, Name> onDiscoverySuccess;
Davide Pesaventoa0e6b602021-01-21 19:47:04 -050056
57 /**
58 * @brief Signal emitted when a failure occurs.
59 */
Junxiao Shi869d73e2023-08-10 22:52:26 +000060 signal::Signal<DiscoverVersion, std::string> onDiscoveryFailure;
Davide Pesaventoa0e6b602021-01-21 19:47:04 -050061
Andrea Tosatto672b9a72016-01-05 16:18:20 +010062 void
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070063 run();
Andrea Tosatto672b9a72016-01-05 16:18:20 +010064
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070065private:
66 void
67 handleData(const Interest& interest, const Data& data);
Andrea Tosatto672b9a72016-01-05 16:18:20 +010068
Chavoosh Ghasemibb2d2802019-03-26 16:07:58 -070069private:
Andrea Tosatto672b9a72016-01-05 16:18:20 +010070 Face& m_face;
Davide Pesavento97a33b22019-10-17 22:10:47 -040071 const Name m_prefix;
72 const Options& m_options;
Davide Pesavento5748e822024-01-26 18:40:22 -050073 std::shared_ptr<DataFetcher> m_fetcher;
Andrea Tosatto672b9a72016-01-05 16:18:20 +010074};
75
Davide Pesaventob3570c62022-02-19 19:19:00 -050076} // namespace ndn::chunks
Andrea Tosatto672b9a72016-01-05 16:18:20 +010077
78#endif // NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_HPP