You.i Engine
CYIAssetDownloadHelper Class Reference

Detailed Description

A download helper class used for downloading assets off of web servers or locally when a local path URI is given.

This class can be used to simplify the process of downloading image files or other asset types off of a web server or locally. Before using this helper the CYIHTTPService must be started using CYIHTTPService::Start. The helper adds downloaded assets to the CYIAssetManager. When the helper receives a cached response from the HTTP service it will attempt to retreive an asset from the asset manager in order to reuse it.

See also

#include <network/YiAssetDownloadHelper.h>

Inheritance diagram for CYIAssetDownloadHelper:

Public Types

enum  DownloadState {
  DownloadState::Idle = (size_t)CYIDownloadHelper::DownloadState::Idle,
  DownloadState::Downloading = (size_t)CYIDownloadHelper::DownloadState::Downloading
enum  FailureType {
  FailureType::InvalidURL = (size_t)CYIDownloadHelper::FailureType::InvalidURL,
  FailureType::NetworkError = (size_t)CYIDownloadHelper::FailureType::NetworkError,
- Public Types inherited from CYIDownloadHelper
enum  DownloadState {
  DownloadState::Idle = 0,
enum  FailureType {
  FailureType::InvalidURL = 0,

Public Member Functions

 CYIAssetDownloadHelper ()
 CYIAssetDownloadHelper (IYINetworkService *pNetwork)
virtual ~CYIAssetDownloadHelper ()
DownloadState GetDownloadState () const
- Public Member Functions inherited from CYIDownloadHelper
 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 Member Functions inherited from CYIAssetLoader::DecodeListener
virtual ~DecodeListener ()
virtual void OnDecodeStarted (int32_t jobID, void *pListenerPrivate)
virtual void OnDecodeCancelled (int32_t jobID, void *pListenerPrivate)

Public Attributes

CYISignal< const std::shared_ptr< CYIAsset > &, const CYIUrl &> AssetReady
CYISignal< FailureType, const CYIUrl &> AssetDownloadFailed
CYISignal< const CYIUrl &> AssetDownloadCancelled
- Public Attributes inherited from CYIDownloadHelper
CYISignal< FailureType, const CYIUrl &> DownloadFailed
CYISignal< const CYIUrl &> DownloadCancelled
CYISignal< const CYIUrl &> DownloadComplete

Protected Member Functions

virtual void StartDownloadImpl () override
virtual void OnRequestCompleted (const std::shared_ptr< CYIHTTPRequest > &pRequest, const std::shared_ptr< CYIHTTPResponse > &pResponse, bool cachedResponse) override
virtual void OnDecodeComplete (int32_t jobID, std::shared_ptr< CYIAsset > pAsset, int32_t loadStatus, void *pListenerPrivate) override
virtual void CancelDownloadImplementation () override
- Protected Member Functions inherited from CYIDownloadHelper
virtual void OnRequestFailed (const std::shared_ptr< CYIHTTPRequest > &pRequest)

Additional Inherited Members

- Protected Attributes inherited from CYIDownloadHelper
DownloadState m_state
std::shared_ptr< CYIHTTPRequestm_pCurrentRequest
std::shared_ptr< CYIHTTPResponsem_pCurrentResponse
std::recursive_mutex m_stateMutex

Member Enumeration Documentation

◆ DownloadState


◆ FailureType


Constructor & Destructor Documentation

◆ CYIAssetDownloadHelper() [1/2]

CYIAssetDownloadHelper::CYIAssetDownloadHelper ( )

Constructs a default CYIAssetDownloadHelper.

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

◆ CYIAssetDownloadHelper() [2/2]

CYIAssetDownloadHelper::CYIAssetDownloadHelper ( IYINetworkService pNetwork)

◆ ~CYIAssetDownloadHelper()

virtual CYIAssetDownloadHelper::~CYIAssetDownloadHelper ( )

Member Function Documentation

◆ CancelDownloadImplementation()

virtual void CYIAssetDownloadHelper::CancelDownloadImplementation ( )

Called when a download is being cancelled. Subclasses can implement this method to perform specific functions when a download is cancelled.

Reimplemented from CYIDownloadHelper.

◆ GetDownloadState()

DownloadState CYIAssetDownloadHelper::GetDownloadState ( ) const

Returns the current download state of the helper.

◆ OnDecodeComplete()

virtual void CYIAssetDownloadHelper::OnDecodeComplete ( int32_t  jobID,
std::shared_ptr< CYIAsset pAsset,
int32_t  loadStatus,
void *  pListenerPrivate 

Called when the asset decoding completes. If successful the asset will be emitted in the CYIAssetDownloadHelper::AssetReady signal. If unsuccessful the CYIAssetDownloadHelper::AssetDownloadFailed signal will be emmited.

Implements CYIAssetLoader::DecodeListener.

◆ OnRequestCompleted()

virtual void CYIAssetDownloadHelper::OnRequestCompleted ( const std::shared_ptr< CYIHTTPRequest > &  pRequest,
const std::shared_ptr< CYIHTTPResponse > &  pResponse,
bool  cachedResponse 

Called when the request has completed. Implementor should call the base class to register the CYIAssetDownloadHelper to be a CYIAssetLoader::DecodeListener, and start the asset's decoding using the CYIAssetLoader. If the asset can't be decoded the CYIAssetDownloadHelper::AssetDownloadFailed signal will be emitted.

See also

Reimplemented from CYIDownloadHelper.

◆ StartDownloadImpl()

virtual void CYIAssetDownloadHelper::StartDownloadImpl ( )

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

Reimplemented from CYIDownloadHelper.

Member Data Documentation

◆ AssetDownloadCancelled

CYISignal<const CYIUrl & > CYIAssetDownloadHelper::AssetDownloadCancelled

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

◆ AssetDownloadFailed

CYISignal<FailureType, const CYIUrl & > CYIAssetDownloadHelper::AssetDownloadFailed

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

◆ AssetReady

CYISignal<const std::shared_ptr<CYIAsset> &, const CYIUrl & > CYIAssetDownloadHelper::AssetReady

Signals that the asset download has completed.

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