You.i Engine
CYIAbstractDownloadHelper Class Referenceabstract

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.

See also
CYIHTTPService

#include <network/YiAbstractDownloadHelper.h>

Inheritance diagram for CYIAbstractDownloadHelper:

Public Types

enum  DOWNLOAD_STATE {
  IDLE = 0,
  DOWNLOADING
}
 
enum  FAILURE_TYPE {
  INVALID_URL = 0,
  NETWORK_ERROR
}
 

Public Member Functions

 CYIAbstractDownloadHelper ()
 
 CYIAbstractDownloadHelper (const CYIUrl &url)
 
virtual ~CYIAbstractDownloadHelper ()
 
const CYIUrlGetUrl () const
 
void SetUrl (const CYIUrl &url)
 
void StartDownload ()
 
void StartDownload (const CYIUrl &url)
 
void CancelDownload ()
 
DOWNLOAD_STATE GetDownloadState () const
 
- 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 Member Functions inherited from CYIScriptableObject
 CYIScriptableObject ()
 
 CYIScriptableObject (const CYIScriptableObject &other)
 
CYIScriptableObjectoperator= (const CYIScriptableObject &other)
 
virtual ~CYIScriptableObject ()
 
CYIBindingImplementationGetBindingImplementation () const
 
void SetBindingImplementation (CYIBindingImplementation *pBindingImplementation)
 
virtual const CYIRuntimeTypeInfoGetRuntimeTypeInfoForScriptObject () const
 

Public Attributes

CYISignal< FAILURE_TYPE, 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 ()=0
 

Protected Attributes

DOWNLOAD_STATE m_state
 
CYIUrl m_url
 
std::shared_ptr< CYIHTTPRequestm_pCurrentRequest
 
std::shared_ptr< CYIHTTPResponsem_pCurrentResponse
 
CYIRecursiveMutex m_stateMutex
 

Member Enumeration Documentation

Represents the states the download helper can be in

Enumerator
IDLE 

The download helper is not downloading data.

DOWNLOADING 

The download helper is downloading data.

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

Enumerator
INVALID_URL 

The url provided is empty.

NETWORK_ERROR 

An error occurred while downloading data.

Constructor & Destructor Documentation

CYIAbstractDownloadHelper::CYIAbstractDownloadHelper ( )

Constructs a default CYIAbstractDownloadHelper.

Note
A url must be set using SetUrl before a download can be succesfully started.
CYIAbstractDownloadHelper::CYIAbstractDownloadHelper ( const CYIUrl url)

Constructs a CYIAbstractDownloadHelper initialized with a url.

virtual CYIAbstractDownloadHelper::~CYIAbstractDownloadHelper ( )
virtual

Member Function Documentation

void CYIAbstractDownloadHelper::CancelDownload ( )

Cancels the download of the current URL.

virtual void CYIAbstractDownloadHelper::CancelDownloadImplementation ( )
protectedpure virtual

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

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

Implemented in CYIAssetDownloadHelper, and CYIRemoteAssetDownloadHelper.

DOWNLOAD_STATE CYIAbstractDownloadHelper::GetDownloadState ( ) const

Returns the current download state of the helper.

const CYIUrl& CYIAbstractDownloadHelper::GetUrl ( ) const

Returns the current URL.

virtual void CYIAbstractDownloadHelper::OnRequestCompleted ( const std::shared_ptr< CYIHTTPRequest > &  ,
const std::shared_ptr< CYIHTTPResponse > &  ,
bool   
)
protectedvirtual

Called when the request has completed.

Reimplemented in CYIAssetDownloadHelper, and CYIRemoteAssetDownloadHelper.

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

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

void CYIAbstractDownloadHelper::SetUrl ( const CYIUrl url)

Sets the current URL to be used on download.

Note
If there is a download in progress settings a new URL via this API will cancel the current download.
void CYIAbstractDownloadHelper::StartDownload ( )

Starts the download with the current URL.

void CYIAbstractDownloadHelper::StartDownload ( const CYIUrl url)

Starts the download with url as the URL.

See also
SetUrl
StartDownload

Member Data Documentation

CYISignal<const CYIUrl & > CYIAbstractDownloadHelper::DownloadCancelled

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

CYISignal<const CYIUrl & > CYIAbstractDownloadHelper::DownloadComplete

Signals that the download has completed.

CYISignal<FAILURE_TYPE, const CYIUrl & > CYIAbstractDownloadHelper::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> CYIAbstractDownloadHelper::m_pCurrentRequest
protected
std::shared_ptr<CYIHTTPResponse> CYIAbstractDownloadHelper::m_pCurrentResponse
protected
DOWNLOAD_STATE CYIAbstractDownloadHelper::m_state
protected
CYIRecursiveMutex CYIAbstractDownloadHelper::m_stateMutex
mutableprotected
CYIUrl CYIAbstractDownloadHelper::m_url
protected

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