blob: a34afa0f3c3f86f553e62f2ebc47e229af259f07 [file] [log] [blame]
spirosmastorakise0a74c72016-03-04 16:03:08 -08001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/**
3* Copyright (c) 2016 Regents of the University of California.
4*
5* This file is part of the nTorrent codebase.
6*
7* nTorrent is free software: you can redistribute it and/or modify it under the
8* terms of the GNU Lesser General Public License as published by the Free Software
9* Foundation, either version 3 of the License, or (at your option) any later version.
10*
11* nTorrent is distributed in the hope that it will be useful, but WITHOUT ANY
12* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14*
15* You should have received copies of the GNU General Public License and GNU Lesser
16* General Public License along with nTorrent, e.g., in COPYING.md file. If not, see
17* <http://www.gnu.org/licenses/>.
18*
19* See AUTHORS for complete list of nTorrent authors and contributors.
20*/
21
22#ifndef FETCHING_STRATEGY_MANAGER_HPP
23#define FETCHING_STRATEGY_MANAGER_HPP
24
spirosmastorakise0a74c72016-03-04 16:03:08 -080025#include <ndn-cxx/data.hpp>
Mickey Sweattb7ee19c2016-04-21 12:18:15 -070026#include <ndn-cxx/interest.hpp>
27#include <ndn-cxx/util/time.hpp>
spirosmastorakise0a74c72016-03-04 16:03:08 -080028
29namespace ndn {
30namespace ntorrent {
31
32class FetchingStrategyManager {
33 public:
34 /**
35 * @brief Default Constructor
36 */
37 FetchingStrategyManager() = default;
38
39 /**
40 * @brief Class Destructor
41 */
42 virtual
spirosmastorakis2f769c22016-03-12 11:46:04 -080043 ~FetchingStrategyManager();
spirosmastorakise0a74c72016-03-04 16:03:08 -080044
45 /**
46 * @brief Method called to start the torrent downloading
47 */
48 virtual void
49 start() = 0;
50
51 /**
52 * @brief Method called to pause the torrent downloading
53 */
54 virtual void
55 pause() = 0;
56
57 /**
58 * @brief Method called to continue the torrent downloading
59 */
60 virtual void
61 resume() = 0;
62
63 /**
64 * @brief Struct representing the status of the downloading
65 * process that will be passed to the application layer
66 */
67 struct status {
68 double downloadedPercent;
69 };
Mickey Sweattb7ee19c2016-04-21 12:18:15 -070070 /**
71 * @brief Seed downloaded data for the specified timeout.
72 * By default this will go into an infinite loop.
73 */
74 virtual void
75 seed(const time::milliseconds& timeout = time::milliseconds::zero()) const = 0;
spirosmastorakise0a74c72016-03-04 16:03:08 -080076
77 private:
78 /**
79 * @brief Callback to be called when data is received
80 */
81 virtual void
82 onDataPacketReceived(const ndn::Data& data) = 0;
83
84 /**
85 * @brief Callback to be called when data retrieval failed
86 */
87 virtual void
88 onDataRetrievalFailure(const ndn::Interest& interest, const std::string& errorCode) = 0;
89
90 /**
91 * @brief Callback to be called when a file manifest is received
92 */
93 virtual void
94 onManifestReceived(const std::vector<Name>& packetNames) = 0;
95};
96
spirosmastorakis2f769c22016-03-12 11:46:04 -080097inline
98FetchingStrategyManager::~FetchingStrategyManager()
99{
100}
101
spirosmastorakise0a74c72016-03-04 16:03:08 -0800102} // namespace ntorrent
103} // namespace ndn
104
105#endif // FETCHING_STRATEGY_MANAGER_HPP