libzypp 17.31.23
zyppng::Download Class Reference

#include </home/abuild/rpmbuild/BUILD/libzypp-17.31.23/zypp-curl/ng/network/downloader.h>

Inheritance diagram for zyppng::Download:

Public Types

enum  State {
  InitialState , DetectMetaLink , DlMetaLinkInfo , PrepareMulti ,
  DlMetalink , DlZChunkHead , DlZChunk , DlSimple ,
  Finished
}
 
using Ptr = DownloadRef
 
using WeakPtr = DownloadWeakRef
 

Public Member Functions

virtual ~Download ()
 
State state () const
 
NetworkRequestError lastRequestError () const
 
bool hasError () const
 
std::string errorString () const
 
void start ()
 
void prioritize ()
 
void cancel ()
 
void setStopOnMetalink (const bool set=true)
 
bool stoppedOnMetalink () const
 
DownloadSpecspec ()
 
const DownloadSpecspec () const
 
uint64_t lastAuthTimestamp () const
 
NetworkRequestDispatcher & dispatcher () const
 
SignalProxy< void(Download &req)> sigStarted ()
 
SignalProxy< void(Download &req, State state)> sigStateChanged ()
 
SignalProxy< void(Download &req, off_t dlnow)> sigAlive ()
 
SignalProxy< void(Download &req, off_t dltotal, off_t dlnow)> sigProgress ()
 
SignalProxy< void(Download &req)> sigFinished ()
 
SignalProxy< void(Download &req, NetworkAuthData &auth, const std::string &availAuth)> sigAuthRequired ()
 

Private Member Functions

 Download (Downloader &parent, std::shared_ptr< NetworkRequestDispatcher > requestDispatcher, std::shared_ptr< MirrorControl > mirrors, DownloadSpec &&spec)
 

Friends

class zyppng::Downloader
 

Detailed Description

The Download class represents a possibly multipart download.

The Download class is a more high level interface compared to

See also
zyppng::NetworkRequest, it can internally make use of features like metalinks and tries to be as resilient as possible with errors during a download. Due to this it is represented internally as a state machine. All transitions are signalled and can be followed.
zyppng::EventLoop::Ptr loop = zyppng::EventLoop::create();
dl.queueEmpty().connect( [ &loop ]( zyppng::Downloader & ) {
loop->quit();
});
zypp::Url url ( "https://download.opensuse.org/distribution/leap/15.0/repo/oss/x86_64/0ad-0.0.22-lp150.2.10.x86_64.rpm" );
zypp::Pathname target("/tmp/0ad-0.0.22-lp150.2.10.x86_64.rpm");
std::shared_ptr<zyppng::Download> req = dl.downloadFile( zypp::DownloadSpec(url, target) );
req->sigStarted().connect( []( zyppng::Download &dl ) {
std::cout << "Download started: " << dl.targetPath() << std::endl;
});
req->sigFinished().connect( []( zyppng::Download &dl ) {
std::cout << "Download finished: " << dl.targetPath() << std::endl;
if ( dl.state() != zyppng::Download::Success )
std::cout << "\t has error: " << dl.errorString() << std::endl;
});
req->sigAlive().connect( []( zyppng::Download &dl, off_t dlnow ) {
std::cout << dl.targetPath().asString() << " at: " << std::endl
<< "dlnow: "<< dlnow<< std::endl;
});
req->sigProgress().connect( []( zyppng::Download &dl, off_t dltotal, off_t dlnow ) {
std::cout << dl.targetPath().asString() << " at: " << std::endl
<< "dltotal: "<< dltotal<< std::endl
<< "dlnow: "<< dlnow<< std::endl;
});
req->start();
loop->run();
Url manipulation class.
Definition: Url.h:92
std::string errorString() const
Definition: downloader.cc:232
State state() const
Definition: downloader.cc:211
The Downloader class.
Definition: downloader.h:39
SignalProxy< void(Downloader &parent)> queueEmpty()
Definition: downloader.cc:415
std::shared_ptr< Download > downloadFile(const DownloadSpec &spec)
Definition: downloader.cc:388
std::string asString(TInt val, char zero='0', char one='1')
For printing bits.
Definition: Bit.h:57

Definition at line 126 of file downloader.h.

Member Typedef Documentation

◆ Ptr

using zyppng::Download::Ptr = DownloadRef

Definition at line 132 of file downloader.h.

◆ WeakPtr

using zyppng::Download::WeakPtr = DownloadWeakRef

Definition at line 133 of file downloader.h.

Member Enumeration Documentation

◆ State

The states of the internal state machine. Each of them represents a different stage of the lifetime of a Download.

Enumerator
InitialState 
DetectMetaLink 
DlMetaLinkInfo 
PrepareMulti 
DlMetalink 
DlZChunkHead 
DlZChunk 
DlSimple 
Finished 

Definition at line 139 of file downloader.h.

Constructor & Destructor Documentation

◆ ~Download()

zyppng::Download::~Download ( )
virtual

Definition at line 205 of file downloader.cc.

◆ Download()

zyppng::Download::Download ( Downloader parent,
std::shared_ptr< NetworkRequestDispatcher >  requestDispatcher,
std::shared_ptr< MirrorControl mirrors,
DownloadSpec &&  spec 
)
private

A download can only directly be created by the

See also
zyppng::Downloader

Definition at line 199 of file downloader.cc.

Member Function Documentation

◆ state()

Download::State zyppng::Download::state ( ) const

Returns the current internal state of the Download

See also
zyppng::Download::State

Definition at line 211 of file downloader.cc.

◆ lastRequestError()

NetworkRequestError zyppng::Download::lastRequestError ( ) const

Returns the last

See also
zyppng::NetworkRequestError enountered while downloading the file. This will just represent the very last error that could not be recovered from. In case of a Metalink download that ususally means that all mirrors and the initial URL failed to download for some reason.

Definition at line 219 of file downloader.cc.

◆ hasError()

bool zyppng::Download::hasError ( ) const

Returns true if lastRequestError would return a valid NetworkRequestError

Definition at line 227 of file downloader.cc.

◆ errorString()

std::string zyppng::Download::errorString ( ) const

Returns a readable reason why the download failed.

See also
lastRequestError

Definition at line 232 of file downloader.cc.

◆ start()

void zyppng::Download::start ( )

Triggers the start of the download, this needs to be called in order for the statemachine to advance.

Definition at line 242 of file downloader.cc.

◆ prioritize()

void zyppng::Download::prioritize ( )

This will raise all requests currenty in pending state to have NetworkRequest::Critial priority, which means they will be started even before requests with NetworkRequest::High priority.

Note
Use this feature only if the request result is required right away because the application is waiting for it, overuse of this might hurt performance

Definition at line 247 of file downloader.cc.

◆ cancel()

void zyppng::Download::cancel ( )

Aborts the current download

Definition at line 269 of file downloader.cc.

◆ setStopOnMetalink()

void zyppng::Download::setStopOnMetalink ( const bool  set = true)

This will finalize the download once a metalink file was received. This is a special setting used if the metalink file should be processed outside of the Downloader.

Definition at line 275 of file downloader.cc.

◆ stoppedOnMetalink()

bool zyppng::Download::stoppedOnMetalink ( ) const

Returns true if the download was stopped after receiving metalink data. The target file will contain the metalink description.

Definition at line 280 of file downloader.cc.

◆ spec() [1/2]

DownloadSpec & zyppng::Download::spec ( )

Returns a reference to the internally used download spec.

See also
zyppng::DownloadSpec
Note
Changing settings after the download started might result in undefined or weird behaviour

Definition at line 285 of file downloader.cc.

◆ spec() [2/2]

const DownloadSpec & zyppng::Download::spec ( ) const

Definition at line 290 of file downloader.cc.

◆ lastAuthTimestamp()

uint64_t zyppng::Download::lastAuthTimestamp ( ) const

Returns the timestamp of the last auth credentials that were loaded from the CredentialManager. If no credentials were tried, this returns 0

Definition at line 295 of file downloader.cc.

◆ dispatcher()

zyppng::NetworkRequestDispatcher & zyppng::Download::dispatcher ( ) const

Returns a reference to the internally used

See also
zyppng::NetworkRequestDispatcher

Definition at line 300 of file downloader.cc.

◆ sigStarted()

SignalProxy< void(Download &req)> zyppng::Download::sigStarted ( )

Signals that the dispatcher dequeued the request and actually starts downloading data

Definition at line 305 of file downloader.cc.

◆ sigStateChanged()

SignalProxy< void(Download &req, Download::State state)> zyppng::Download::sigStateChanged ( )

Signals that the state of the Download has changed

Definition at line 310 of file downloader.cc.

◆ sigAlive()

SignalProxy< void(zyppng::Download &req, off_t dlnow)> zyppng::Download::sigAlive ( )

Signals that the download is alive but still in initial stage ( trying to figure out if metalink / zsync )

Definition at line 315 of file downloader.cc.

◆ sigProgress()

SignalProxy< void(Download &req, off_t dltotal, off_t dlnow)> zyppng::Download::sigProgress ( )

Signals if there was data read from the download

Definition at line 320 of file downloader.cc.

◆ sigFinished()

SignalProxy< void(Download &req)> zyppng::Download::sigFinished ( )

Signals that the download finished.

Definition at line 325 of file downloader.cc.

◆ sigAuthRequired()

SignalProxy< void(zyppng::Download &req, zyppng::NetworkAuthData &auth, const std::string &availAuth)> zyppng::Download::sigAuthRequired ( )

Is emitted when a request requires authentication and it was not given or if auth failed. A connected slot should fill in the auth information in order to provide login credentials.

Note
the URL in the auth data is set to the url of the request needing authorization. This URL can be different than the one in the spec, due to redirect/metalink. Also the lastDatabaseUpdate field is set to the timestamp of the auth data that was tried already ( if available )

Definition at line 330 of file downloader.cc.

Friends And Related Function Documentation

◆ zyppng::Downloader

friend class zyppng::Downloader
friend

Definition at line 265 of file downloader.h.


The documentation for this class was generated from the following files: