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 &signalHandler)
virtual ~CYISignalHandler ()
CYISignalHandleroperator= (const CYISignalHandler &signalHandler)
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 &threadAffinity)
virtual bool IsConnected () const
virtual bool IsConnected (const CYISignalBase &signal) const
void Disconnect (CYISignalBase &signal)
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

◆ DownloadState

Represents the states the download helper can be in


The download helper is not downloading data.


The download helper is downloading data.

◆ FailureType

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() [1/2]

CYIDownloadHelper::CYIDownloadHelper ( )

Constructs a default CYIDownloadHelper.

A url must be set using SetUrl before a download can be succesfully started.

◆ CYIDownloadHelper() [2/2]

CYIDownloadHelper::CYIDownloadHelper ( IYINetworkService pNetwork)

◆ ~CYIDownloadHelper()

virtual CYIDownloadHelper::~CYIDownloadHelper ( )

Member Function Documentation

◆ CancelDownload()

void CYIDownloadHelper::CancelDownload ( )

Cancels the download of the current URL.

◆ CancelDownloadImplementation()

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.

◆ ClearResponse()

void CYIDownloadHelper::ClearResponse ( )

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

◆ GetDownloadState()

DownloadState CYIDownloadHelper::GetDownloadState ( ) const

Returns the current download state of the helper.

◆ GetResponse()

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.

◆ GetUrl()

const CYIUrl& CYIDownloadHelper::GetUrl ( ) const

Returns the current URL.

◆ OnRequestCompleted()

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

Called when the request has completed.

Reimplemented in CYIAssetDownloadHelper.

◆ OnRequestFailed()

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

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

◆ StartDownload() [1/2]

void CYIDownloadHelper::StartDownload ( const CYIUrl url)

Starts the download with url as the URL.

◆ StartDownload() [2/2]

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

Starts the download with a custom request.

◆ StartDownloadImpl()

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

◆ DownloadCancelled

CYISignal<const CYIUrl & > CYIDownloadHelper::DownloadCancelled

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

◆ DownloadComplete

CYISignal<const CYIUrl & > CYIDownloadHelper::DownloadComplete

Signals that the download has completed.

◆ DownloadFailed

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.

◆ m_pCurrentRequest

std::shared_ptr<CYIHTTPRequest> CYIDownloadHelper::m_pCurrentRequest

◆ m_pCurrentResponse

std::shared_ptr<CYIHTTPResponse> CYIDownloadHelper::m_pCurrentResponse

◆ m_pNetworkService

IYINetworkService* CYIDownloadHelper::m_pNetworkService

◆ m_state

DownloadState CYIDownloadHelper::m_state

◆ m_stateMutex

std::recursive_mutex CYIDownloadHelper::m_stateMutex

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