libzypp  17.22.0
zyppng::Download Class Reference

#include <downloader.h>

Inheritance diagram for zyppng::Download:

Public Types

enum  State {
  InitialState, Initializing = 10, Running = 20, RunningMulti = 30,
  Success = 200, Failed
}
 
using Ptr = std::shared_ptr< Download >
 
using WeakPtr = std::shared_ptr< Download >
 
- Public Types inherited from zyppng::Base
using Ptr = std::shared_ptr< Base >
 
using WeakPtr = std::weak_ptr< Base >
 

Public Member Functions

 Download (DownloadPrivate &&prv)
 
Url url () const
 
zypp::Pathname targetPath () const
 
State state () const
 
NetworkRequestError lastRequestError () const
 
std::string errorString () const
 
TransferSettingssettings ()
 
void start ()
 
void setMultiPartHandlingEnabled (bool enable=true)
 
void setCheckExistsOnly (bool set=true)
 
void setDeltaFile (const zypp::Pathname &file)
 
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 ()
 
- Public Member Functions inherited from zyppng::Base
 Base ()
 
virtual ~Base ()
 
WeakPtr parent () const
 
void addChild (Base::Ptr child)
 
void removeChild (Ptr child)
 
const std::unordered_set< Ptr > & children () const
 
template<typename T >
std::vector< std::weak_ptr< T > > findChildren () const
 
template<typename T >
std::shared_ptr< T > shared_this () const
 
template<typename T >
std::shared_ptr< T > shared_this ()
 
template<typename T >
std::weak_ptr< T > weak_this () const
 
template<typename T >
std::weak_ptr< T > weak_this ()
 

Additional Inherited Members

- Protected Member Functions inherited from zyppng::Base
 Base (BasePrivate &dd)
 
- Protected Attributes inherited from zyppng::Base
std::unique_ptr< BasePrivated_ptr
 

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.
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( 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;
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();

Definition at line 123 of file downloader.h.

Member Typedef Documentation

◆ Ptr

using zyppng::Download::Ptr = std::shared_ptr<Download>

Definition at line 129 of file downloader.h.

◆ WeakPtr

using zyppng::Download::WeakPtr = std::shared_ptr<Download>

Definition at line 130 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 
Initializing 
Running 
RunningMulti 
Success 
Failed 

Definition at line 136 of file downloader.h.

Constructor & Destructor Documentation

◆ Download()

zyppng::Download::Download ( zyppng::DownloadPrivate &&  prv)

A download can only directly be created by the

See also
zyppng::Downloader

Definition at line 678 of file downloader.cc.

Member Function Documentation

◆ url()

Url zyppng::Download::url ( ) const

Returns the source URL of the download

Definition at line 682 of file downloader.cc.

◆ targetPath()

zypp::filesystem::Pathname zyppng::Download::targetPath ( ) const

Returns the target file path, this is where the downloaded data is stored

Definition at line 687 of file downloader.cc.

◆ state()

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

Returns the current internal state of the Download

See also
zyppng::Download::State

Definition at line 692 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 697 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 702 of file downloader.cc.

◆ settings()

TransferSettings & zyppng::Download::settings ( )

Returns a writeable reference to the

See also
zyppng::TransferSettings for the download. The settings are reused for possible sub downloads, however authentication data is stripped if the subdownload uses a different host to fetch the data from. If there is no auth data known
sigAuthRequired is emitted.

Definition at line 712 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 717 of file downloader.cc.

◆ setMultiPartHandlingEnabled()

void zyppng::Download::setMultiPartHandlingEnabled ( bool  enable = true)

Enabled or disabled multipart handling. Enabled by default.

Note
if Multipart is enabled the Download tells the server that it accepts metalink files by adding a specific header to the request.

Definition at line 722 of file downloader.cc.

◆ setCheckExistsOnly()

void zyppng::Download::setCheckExistsOnly ( bool  set = true)

Enables a special mode, in this case only the existance of the file is checked but no data is actually downloaded

Definition at line 727 of file downloader.cc.

◆ setDeltaFile()

void zyppng::Download::setDeltaFile ( const zypp::Pathname file)

Set a already existing local file to be used for partial downloading, in case of a multichunk download all chunks from the file that have the expected checksum will be reused instead of downloaded

Definition at line 737 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 742 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 747 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 752 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 757 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 762 of file downloader.cc.

◆ sigFinished()

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

Signals that the download finished.

Definition at line 767 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.

Definition at line 772 of file downloader.cc.


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