LibPkg
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
pkg::download Class Reference

A class for downloading a file from a URL. More...

#include <download.h>

Public Types

enum  state_type { state_download, state_done, state_fail }
 
typedef unsigned long long size_type
 A type for representing byte counts. More...
 

Public Member Functions

 download (const string &url, const string &pathname)
 Construct download action. More...
 
 ~download ()
 Destroy download action. More...
 
state_type state () const
 Get current state of the download. More...
 
CURLcode result () const
 Get libcurl result code. More...
 
string message () const
 Get libcurl error message. More...
 
size_type bytes_done ()
 Get number of bytes downloaded. More...
 
size_type bytes_total ()
 Get total number of bytes to download. More...
 
size_t write_callback (char *buffer, size_t size, size_t nitems)
 Handler for CURLOPT_WRITEFUNCTION callbacks. More...
 
int progress_callback (double dltotal, double dlnow)
 Handler for CURLOPT_PROGRESSFUNCTION callbacks. More...
 
void message_callback (CURLMsg *msg)
 Handler for Curl messages. More...
 

Static Public Member Functions

static void poll_all ()
 Poll all download operations. More...
 

Static Public Attributes

static const size_type npos =static_cast<size_type>(-1)
 A null value for use in place of a byte count. More...
 

Detailed Description

A class for downloading a file from a URL.

Member Typedef Documentation

◆ size_type

typedef unsigned long long pkg::download::size_type

A type for representing byte counts.

Member Enumeration Documentation

◆ state_type

Enumerator
state_download 

The state in which the download is in progress.

state_done 

The state in which the download has been successfully completed.

state_fail 

The state in which the download has failed.

Constructor & Destructor Documentation

◆ download()

pkg::download::download ( const string &  url,
const string &  pathname 
)

Construct download action.

Parameters
urlthe URL from which to download
pathnamethe pathname to which the file is to be written

References __riscosify_control.

◆ ~download()

pkg::download::~download ( )

Destroy download action.

References __riscosify_control.

Member Function Documentation

◆ state()

state_type pkg::download::state ( ) const
inline

Get current state of the download.

Returns
the current state

Referenced by pkg::update::poll(), and pkg::commit::poll().

◆ result()

CURLcode pkg::download::result ( ) const
inline

Get libcurl result code.

Returns
the result code

◆ message()

string pkg::download::message ( ) const
inline

Get libcurl error message.

Returns
the message

Referenced by pkg::update::poll(), and pkg::commit::poll().

◆ bytes_done()

size_type pkg::download::bytes_done ( )
inline

Get number of bytes downloaded.

Returns
the number of bytes downloaded

Referenced by pkg::update::poll().

◆ bytes_total()

size_type pkg::download::bytes_total ( )
inline

Get total number of bytes to download.

Returns
the total number of bytes, or npos if not known

References message_callback(), poll_all(), progress_callback(), and write_callback().

Referenced by pkg::update::poll().

◆ write_callback()

size_t pkg::download::write_callback ( char *  buffer,
size_t  size,
size_t  nitems 
)

Handler for CURLOPT_WRITEFUNCTION callbacks.

Parameters
bufferthe data buffer
sizethe size of each data item
nitemsthe number of data items
Returns
the number of bytes written (size*nitems)

Referenced by bytes_total().

◆ progress_callback()

int pkg::download::progress_callback ( double  dltotal,
double  dlnow 
)

Handler for CURLOPT_PROGRESSFUNCTION callbacks.

Parameters
dltotalthe total number of bytes to download, or 0 if not known
dlnowthe number of bytes downloaded
Returns
zero

References npos, and state_download.

Referenced by bytes_total().

◆ message_callback()

void pkg::download::message_callback ( CURLMsg *  msg)

Handler for Curl messages.

Parameters
msgthe message

References pkg::LOG_INFO_DOWNLOAD_DATA, pkg::LOG_INFO_DOWNLOAD_HEADER, pkg::LOG_INFO_DOWNLOAD_INFO, state_done, and state_fail.

Referenced by bytes_total(), and poll_all().

◆ poll_all()

void pkg::download::poll_all ( )
static

Poll all download operations.

References __riscosify_control, and message_callback().

Referenced by bytes_total().

Member Data Documentation

◆ npos

const size_type pkg::download::npos =static_cast<size_type>(-1)
static

A null value for use in place of a byte count.

Referenced by progress_callback().


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

Reference Manual LibPkg Version 0.6.1 (28 Jan 2015)