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
CYIHTTPService

#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,
  FailureType::InvalidAsset
}
 
- Public Types inherited from CYIDownloadHelper
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
 
- 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 &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 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
 
IYINetworkServicem_pNetworkService
 
std::recursive_mutex m_stateMutex
 

Member Enumeration Documentation

Enumerator
Idle 
Downloading 
Enumerator
InvalidURL 
NetworkError 
InvalidAsset 

Constructor & Destructor Documentation

CYIAssetDownloadHelper::CYIAssetDownloadHelper ( )

Constructs a default CYIAssetDownloadHelper.

Note
A url must be set using SetUrl before an asset download can be succesfully started.
CYIAssetDownloadHelper::CYIAssetDownloadHelper ( IYINetworkService pNetwork)
virtual CYIAssetDownloadHelper::~CYIAssetDownloadHelper ( )
virtual

Member Function Documentation

virtual void CYIAssetDownloadHelper::CancelDownloadImplementation ( )
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.

virtual void CYIAssetDownloadHelper::OnDecodeComplete ( int32_t  jobID,
std::shared_ptr< CYIAsset pAsset,
int32_t  loadStatus,
void *  pListenerPrivate 
)
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.

virtual void CYIAssetDownloadHelper::OnRequestCompleted ( const std::shared_ptr< CYIHTTPRequest > &  pRequest,
const std::shared_ptr< CYIHTTPResponse > &  pResponse,
bool  cachedResponse 
)
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.

See also
OnDecodeComplete()
CYIAssetLoader

Reimplemented from CYIDownloadHelper.

virtual void CYIAssetDownloadHelper::StartDownloadImpl ( )
overrideprotectedvirtual

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

Reimplemented from CYIDownloadHelper.

Member Data Documentation

CYISignal<const CYIUrl & > CYIAssetDownloadHelper::AssetDownloadCancelled

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.

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: