You.i Engine
CYIAssetDownloadHelper Class Reference

Detailed Description

A download helper class used for downloading assets off of web servers.

This class can be used to simplify the process of downloading image files or other asset types off of a web server. 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  DOWNLOAD_STATE {
  IDLE = CYIAbstractDownloadHelper::IDLE,
  DOWNLOADING = CYIAbstractDownloadHelper::DOWNLOADING
}
 
enum  FAILURE_TYPE {
  INVALID_URL = CYIAbstractDownloadHelper::INVALID_URL,
  NETWORK_ERROR = CYIAbstractDownloadHelper::NETWORK_ERROR,
  INVALID_ASSET
}
 
- Public Types inherited from CYIAbstractDownloadHelper
enum  DOWNLOAD_STATE {
  IDLE = 0,
  DOWNLOADING
}
 
enum  FAILURE_TYPE {
  INVALID_URL = 0,
  NETWORK_ERROR
}
 

Public Member Functions

 CYIAssetDownloadHelper ()
 
 CYIAssetDownloadHelper (const CYIUrl &url)
 
virtual ~CYIAssetDownloadHelper ()
 
DOWNLOAD_STATE GetDownloadState () const
 
- Public Member Functions inherited from CYIAbstractDownloadHelper
 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 Member Functions inherited from CYIAssetLoader::DecodeListener
virtual ~DecodeListener ()
 

Public Attributes

CYISignal< const std::shared_ptr< CYIAsset > &, const CYIUrl & > AssetReady
 
CYISignal< FAILURE_TYPE, const CYIUrl & > AssetDownloadFailed
 
CYISignal< const CYIUrl & > AssetDownloadCancelled
 
- Public Attributes inherited from CYIAbstractDownloadHelper
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 > &pRequest, const std::shared_ptr< CYIHTTPResponse > &pResponse, bool bCachedResponse) override
 
virtual void OnDecodeComplete (int32_t nJobID, std::shared_ptr< CYIAsset > pAsset, int32_t nLoadStatus, void *pListenerPrivate) override
 
virtual void CancelDownloadImplementation () override
 
- Protected Member Functions inherited from CYIAbstractDownloadHelper
virtual void OnRequestFailed (const std::shared_ptr< CYIHTTPRequest > &pRequest)
 

Additional Inherited Members

- Protected Attributes inherited from CYIAbstractDownloadHelper
DOWNLOAD_STATE m_state
 
CYIUrl m_url
 
std::shared_ptr< CYIHTTPRequestm_pCurrentRequest
 
std::shared_ptr< CYIHTTPResponsem_pCurrentResponse
 
CYIRecursiveMutex m_stateMutex
 

Member Enumeration Documentation

Enumerator
IDLE 
DOWNLOADING 
Enumerator
INVALID_URL 
NETWORK_ERROR 
INVALID_ASSET 

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 ( const CYIUrl url)

Constructs a CYIAssetDownloadHelper initialized with an asset url.

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.

Implements CYIAbstractDownloadHelper.

DOWNLOAD_STATE CYIAssetDownloadHelper::GetDownloadState ( ) const

Returns the current download state of the helper.

virtual void CYIAssetDownloadHelper::OnDecodeComplete ( int32_t  nJobID,
std::shared_ptr< CYIAsset pAsset,
int32_t  nLoadStatus,
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  bCachedResponse 
)
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 CYIAbstractDownloadHelper.

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<FAILURE_TYPE, 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: