libzypp 17.31.23
rangedownloader_p.h
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8----------------------------------------------------------------------/
9*
10* This file contains private API, this might break at any time between releases.
11* You have been warned!
12*
13*/
14#ifndef ZYPP_CURL_NG_NETWORK_PRIVATE_DOWNLOADERSTATES_RANGEDOWNLOADER_P_H_INCLUDED
15#define ZYPP_CURL_NG_NETWORK_PRIVATE_DOWNLOADERSTATES_RANGEDOWNLOADER_P_H_INCLUDED
16
17#include "base_p.h"
18#include "mirrorhandling_p.h"
19#include <zypp-core/zyppng/base/statemachine.h>
20
21namespace zyppng {
22
28
31
32 RangeDownloaderBaseState ( std::vector<Url> &&mirrors, DownloadPrivate &parent ) :
34 _fileMirrors = std::move(mirrors);
35 }
36
38 void reschedule ();
39
40 const NetworkRequestError &error () const {
41 return _error;
42 }
43
44 void setFailed ( NetworkRequestError &&err );
45 void setFailed ( std::string && reason );
46 virtual void setFinished ( );
47 void cancelAll ( const NetworkRequestError &err );
48
50 void onRequestProgress ( NetworkRequest &, off_t, off_t, off_t, off_t );
51 void onRequestFinished ( NetworkRequest &req , const NetworkRequestError &err );
52
53 // MirrorHandlingStateBase interface
54 void mirrorReceived(MirrorControl::MirrorPick mirror) override;
55 void failedToPrepare() override;
56
57 static zypp::ByteCount makeBlksize ( size_t filesize );
58
59 protected:
61 bool _inEnsureDownloadsRunning = false; //< Flag to prevent multiple entry to ensureDownloadsRunning
62
63 size_t _fileSize = 0; //< The expected filesize, this is used to make sure we do not write after the end offset of the expected file size
64 zypp::ByteCount _preferredChunkSize = 0; //< The preferred chunk size we want to download per request
65 std::list<Block> _ranges;
66
67 //keep a list with failed blocks in case we run out of mirrors,
68 //in that case we can retry to download them once we have a finished download
69 std::list<Block> _failedRanges;
70
71 off_t _downloadedMultiByteCount = 0; //< the number of bytes that were already fetched in RunningMulti state
72
73 std::vector< std::shared_ptr<Request> > _runningRequests;
74
75 // we only define the signals here and add the accessor functions in the subclasses, static casting of
76 // the class type is not allowed at compile time, so they would not be useable in the transition table otherwise
77 Signal< void () > _sigFinished;
78 Signal< void () > _sigFailed;
79
80 private:
81 void handleRequestError( std::shared_ptr<Request> req, const zyppng::NetworkRequestError &err );
82 bool addBlockRanges( std::shared_ptr<Request> req, std::vector<Block> &&blocks ) const;
83 void addNewRequest (std::shared_ptr<Request> req, const bool connectSignals = true );
84 bool assertExpectedFilesize ( off_t currentFilesize );
85
86 std::vector<Block> getNextBlocks ( const std::string &urlScheme );
87 std::vector<Block> getNextFailedBlocks( const std::string &urlScheme );
88 };
89
90
91}
92
93#endif
Store and operate with byte count.
Definition: ByteCount.h:31
std::pair< std::vector< Url >::const_iterator, MirrorHandle > MirrorPick
The NetworkRequestError class Represents a error that occured in.
std::vector< Block > getNextBlocks(const std::string &urlScheme)
void onRequestProgress(NetworkRequest &, off_t, off_t, off_t, off_t)
bool addBlockRanges(std::shared_ptr< Request > req, std::vector< Block > &&blocks) const
Just initialize the requests ranges from the internal blocklist.
void onRequestFinished(NetworkRequest &req, const NetworkRequestError &err)
void onRequestStarted(NetworkRequest &)
void handleRequestError(std::shared_ptr< Request > req, const zyppng::NetworkRequestError &err)
std::vector< std::shared_ptr< Request > > _runningRequests
bool assertExpectedFilesize(off_t currentFilesize)
std::vector< Block > getNextFailedBlocks(const std::string &urlScheme)
const NetworkRequestError & error() const
static zypp::ByteCount makeBlksize(size_t filesize)
void mirrorReceived(MirrorControl::MirrorPick mirror) override
void cancelAll(const NetworkRequestError &err)
void addNewRequest(std::shared_ptr< Request > req, const bool connectSignals=true)
void setFailed(NetworkRequestError &&err)
RangeDownloaderBaseState(std::vector< Url > &&mirrors, DownloadPrivate &parent)