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.
#include <network/YiAssetDownloadHelper.h>
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, FailureType::InvalidAsset } |
![]() | |
enum | DownloadState { DownloadState::Idle = 0, DownloadState::Downloading } |
enum | FailureType { FailureType::InvalidURL = 0, FailureType::NetworkError } |
Public Member Functions | |
CYIAssetDownloadHelper () | |
CYIAssetDownloadHelper (IYINetworkService *pNetwork) | |
virtual | ~CYIAssetDownloadHelper () |
DownloadState | GetDownloadState () const |
![]() | |
CYIDownloadHelper () | |
CYIDownloadHelper (IYINetworkService *pNetwork) | |
virtual | ~CYIDownloadHelper () |
const CYIUrl & | GetUrl () 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 () |
![]() | |
CYISignalHandler () | |
CYISignalHandler (const CYISignalHandler &rSignalHandler) | |
virtual | ~CYISignalHandler () |
CYISignalHandler & | operator= (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 () |
![]() | |
Listener () | |
virtual | ~Listener () |
virtual void | OnThreadStarted (CYIThread *) |
virtual void | OnThreadTerminated (CYIThread *) |
virtual void | OnThreadFinished (CYIThread *) |
![]() | |
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 |
![]() | |
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 |
![]() | |
virtual void | OnRequestFailed (const std::shared_ptr< CYIHTTPRequest > &pRequest) |
Additional Inherited Members | |
![]() | |
DownloadState | m_state |
std::shared_ptr< CYIHTTPRequest > | m_pCurrentRequest |
std::shared_ptr< CYIHTTPResponse > | m_pCurrentResponse |
IYINetworkService * | m_pNetworkService |
std::recursive_mutex | m_stateMutex |
|
strong |
|
strong |
CYIAssetDownloadHelper::CYIAssetDownloadHelper | ( | ) |
Constructs a default CYIAssetDownloadHelper.
CYIAssetDownloadHelper::CYIAssetDownloadHelper | ( | IYINetworkService * | pNetwork | ) |
|
virtual |
|
overrideprotectedvirtual |
Called when a download is being cancelled. Subclasses can implement this method to perform specific functions when a download is cancelled.
Reimplemented from CYIDownloadHelper.
DownloadState CYIAssetDownloadHelper::GetDownloadState | ( | ) | const |
Returns the current download state of the helper.
|
overrideprotectedvirtual |
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.
|
overrideprotectedvirtual |
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.
Reimplemented from CYIDownloadHelper.
|
overrideprotectedvirtual |
Starts the download via CYIHTTPService based on the the m_pCurrentResponse built in StartDownload() APIs.
Reimplemented from CYIDownloadHelper.
Signals that the asset download has been cancelled and provides the URL of the cancelled download.
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.
Signals that the asset download has completed.