You.i Engine
CYIDownloadHelper Class Reference

Detailed Description

This class can be used to simplify the process of downloading data off of a web server. Before using this helper the CYIHTTPService must be started using CYIHTTPService::Start.

Downloads can be requested using a URL StartDownload(const CYIUrl &) where a network request will be internally instanciated and passed on to CYIHTTPService, or via a custom request using StartDownload(const std::shared_ptr<CYIHTTPRequest> &). In both cases, signals fired will use the URL (either supplied) or extracted (

See also

Starting a new download will cancel any download in progress only if it is for a different target URL (as defined above). Starting a download for same target URL as the one in progress will be ignored.

See also

#include <network/YiDownloadHelper.h>

Inheritance diagram for CYIDownloadHelper:

Public Types

enum  DownloadState {
  DownloadState::Idle = 0,
enum  FailureType {
  FailureType::InvalidURL = 0,

Public Member Functions

 CYIDownloadHelper ()
 CYIDownloadHelper (IYINetworkService *pNetwork)
virtual ~CYIDownloadHelper ()
const CYIUrlGetUrl () const
void StartDownload (const CYIUrl &url)
void StartDownload (const std::shared_ptr< CYIHTTPRequest > &request)
void CancelDownload ()
DownloadState GetDownloadState () const
const std::shared_ptr< CYIHTTPResponse > & GetResponse () const
void ClearResponse ()
- Public Member Functions inherited from CYISignalHandler
 CYISignalHandler ()
 CYISignalHandler (const CYISignalHandler &rSignalHandler)
virtual ~CYISignalHandler ()
CYISignalHandleroperator= (const CYISignalHandler &rSignalHandler)
void MoveToThread (CYIThread *pThread)
 This function allows the user to override the default thread affinity to any CYIThread that may or may not be running. More...
CYIThreadHandle GetThreadAffinity () const
void SetThreadAffinity (const CYIThreadHandle &rThreadAffinity)
virtual bool IsConnected () const
virtual bool IsConnected (const CYISignalBase &rSignal) const
void Disconnect (CYISignalBase &rSignal)
void DisconnectFromAllSignals ()
- Public Member Functions inherited from CYIThread::Listener
 Listener ()
virtual ~Listener ()
virtual void OnThreadStarted (CYIThread *)
virtual void OnThreadTerminated (CYIThread *)
virtual void OnThreadFinished (CYIThread *)

Public Attributes

CYISignal< FailureType, const CYIUrl & > DownloadFailed
CYISignal< const CYIUrl & > DownloadCancelled
CYISignal< const CYIUrl & > DownloadComplete

Protected Member Functions

virtual void OnRequestCompleted (const std::shared_ptr< CYIHTTPRequest > &, const std::shared_ptr< CYIHTTPResponse > &, bool)
virtual void OnRequestFailed (const std::shared_ptr< CYIHTTPRequest > &pRequest)
virtual void CancelDownloadImplementation ()
virtual void StartDownloadImpl ()

Protected Attributes

DownloadState m_state
std::shared_ptr< CYIHTTPRequestm_pCurrentRequest
std::shared_ptr< CYIHTTPResponsem_pCurrentResponse
std::recursive_mutex m_stateMutex

Member Enumeration Documentation

Represents the states the download helper can be in


The download helper is not downloading data.


The download helper is downloading data.

Represents the different types of failures that can occur while downloading data


The url provided is empty.


An error occurred while downloading data.

Constructor & Destructor Documentation

CYIDownloadHelper::CYIDownloadHelper ( )

Constructs a default CYIDownloadHelper.

A url must be set using SetUrl before a download can be succesfully started.
CYIDownloadHelper::CYIDownloadHelper ( IYINetworkService pNetwork)
virtual CYIDownloadHelper::~CYIDownloadHelper ( )

Member Function Documentation

void CYIDownloadHelper::CancelDownload ( )

Cancels the download of the current URL.

virtual void CYIDownloadHelper::CancelDownloadImplementation ( )

Called when a download is being cancelled. Implementations can assume that m_stateMutex is locked and m_state is DOWNLOADING.

If this function is overridden, CancelDownload() must be called in the subclass' destructor.
See also

Reimplemented in CYIAssetDownloadHelper.

void CYIDownloadHelper::ClearResponse ( )

Clears the response object (freeing memory) held in the class.

DownloadState CYIDownloadHelper::GetDownloadState ( ) const

Returns the current download state of the helper.

const std::shared_ptr<CYIHTTPResponse>& CYIDownloadHelper::GetResponse ( ) const

Returns the response received for the last download request. This is available after the completion callbacks are received.

const CYIUrl& CYIDownloadHelper::GetUrl ( ) const

Returns the current URL.

virtual void CYIDownloadHelper::OnRequestCompleted ( const std::shared_ptr< CYIHTTPRequest > &  ,
const std::shared_ptr< CYIHTTPResponse > &  ,

Called when the request has completed.

Reimplemented in CYIAssetDownloadHelper.

virtual void CYIDownloadHelper::OnRequestFailed ( const std::shared_ptr< CYIHTTPRequest > &  pRequest)

Called when the download fails. Emits the CYIDownloadHelper::DownloadFailed signal.

void CYIDownloadHelper::StartDownload ( const CYIUrl url)

Starts the download with url as the URL.

void CYIDownloadHelper::StartDownload ( const std::shared_ptr< CYIHTTPRequest > &  request)

Starts the download with a custom request.

virtual void CYIDownloadHelper::StartDownloadImpl ( )

Starts the download via CYIHTTPService based on the the m_pCurrentResponse built in StartDownload() APIs.

Reimplemented in CYIAssetDownloadHelper.

Member Data Documentation

CYISignal<const CYIUrl & > CYIDownloadHelper::DownloadCancelled

Signals that the download has been cancelled and provides the URL of the cancelled download.

CYISignal<const CYIUrl & > CYIDownloadHelper::DownloadComplete

Signals that the download has completed.

CYISignal<FailureType, const CYIUrl & > CYIDownloadHelper::DownloadFailed

Signals that the download has failed and provides the URL which the download failure occured along with the cause of failure.

std::shared_ptr<CYIHTTPRequest> CYIDownloadHelper::m_pCurrentRequest
std::shared_ptr<CYIHTTPResponse> CYIDownloadHelper::m_pCurrentResponse
IYINetworkService* CYIDownloadHelper::m_pNetworkService
DownloadState CYIDownloadHelper::m_state
std::recursive_mutex CYIDownloadHelper::m_stateMutex

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