Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 1 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
Davide Pesavento | 887336c | 2017-09-19 15:25:23 -0400 | [diff] [blame^] | 2 | /* |
| 3 | * Copyright (c) 2016-2017, Regents of the University of California, |
| 4 | * Colorado State University, |
| 5 | * University Pierre & Marie Curie, Sorbonne University. |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 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_CATCHUNKS_DISCOVER_VERSION_HPP |
| 29 | #define NDN_TOOLS_CHUNKS_CATCHUNKS_DISCOVER_VERSION_HPP |
| 30 | |
| 31 | #include "core/common.hpp" |
| 32 | #include "options.hpp" |
| 33 | |
| 34 | namespace ndn { |
| 35 | namespace chunks { |
| 36 | |
| 37 | class 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 | */ |
| 45 | class DiscoverVersion : virtual protected Options, noncopyable |
| 46 | { |
| 47 | public: // 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 | |
| 61 | public: |
| 62 | /** |
| 63 | * @brief create a DiscoverVersion service |
| 64 | */ |
| 65 | DiscoverVersion(const Name& prefix, Face& face, const Options& options); |
| 66 | |
Davide Pesavento | 887336c | 2017-09-19 15:25:23 -0400 | [diff] [blame^] | 67 | virtual |
| 68 | ~DiscoverVersion(); |
| 69 | |
Andrea Tosatto | 672b9a7 | 2016-01-05 16:18:20 +0100 | [diff] [blame] | 70 | /** |
| 71 | * @brief identify the latest Data version published. |
| 72 | */ |
| 73 | virtual void |
| 74 | run() = 0; |
| 75 | |
| 76 | protected: |
| 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 | |
| 89 | protected: |
| 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 |