IStreamCallback

Class Hierarchy
C++
class IStreamCallback;
File

IStreamEngine.h

Description

CryPak supports asynchronous reading through this interface. The callback is called from the main thread in the frame update loop.

The callback receives packets through StreamOnComplete() and StreamOnProgress(). The second one can be used to update the asset based on the partial data that arrived. the callback that will be called by the streaming engine must be implemented by all clients that want to use StreamingEngine services

Remarks

the pStream interface is guaranteed to be locked (have reference count > 0) while inside the function, but can vanish any time outside the function. If you need it, keep it from the beginning (after call to StartRead()) some or all callbacks MAY be called from inside IStreamEngine::StartRead()

Example
IStreamEngine *pStreamEngine = g_pISystem->GetStreamEngine();     // get streaming engine
IStreamCallback *pAsyncCallback = &MyClass;                                  // user
StreamReadParams params;
params.dwUserData = 0;
params.nSize = 0;
params.pBuffer = NULL;
params.nLoadTime = 10000;
params.nMaxLoadTime = 10000;
pStreamEngine->StartRead(  .. pAsyncCallback .. params .. );          // registers callback
IStreamCallback::~IStreamCallback Destructor
C++
virtual ~IStreamCallback();
IStreamCallback::StreamAsyncOnComplete Method
C++
virtual void StreamAsyncOnComplete(IReadStream* pStream, unsigned nError);
Description

Signals that reading the requested data has completed (with or without error). This callback is always called, whether an error occurs or not. pStream will signal either IsFinished() or IsError() and will hold the (perhaps partially) read data until this interface is released. GetBytesRead() will return the size of the file (the completely read buffer) in case of successful operation end or the size of partially read data in case of error (0 if nothing was read). Pending status is true during this callback, because the callback itself is the part of IO operation. nError == 0 : Success nError != 0 : Error code

IStreamCallback::StreamOnComplete Method
C++
virtual void StreamOnComplete(IReadStream* pStream, unsigned nError);
Description

Signals that reading the requested data has completed (with or without error). This callback is always called, whether an error occurs or not. pStream will signal either IsFinished() or IsError() and will hold the (perhaps partially) read data until this interface is released. GetBytesRead() will return the size of the file (the completely read buffer) in case of successful operation end or the size of partially read data in case of error (0 if nothing was read). Pending status is true during this callback, because the callback itself is the part of IO operation. nError == 0 : Success nError != 0 : Error code

IStreamCallback::StreamOnNeedStorage Method
C++
virtual void* StreamOnNeedStorage(IReadStream* pStream, unsigned nSize, bool & bAbortOnFailToAlloc);
Description

Signals that the file length for the request has been found, and that storage is needed Either a pointer to a block of nSize bytes can be returned, into which the file will be streamed, or NULL can be returned, in which case temporary memory will be allocated internally by the stream engine (which will be freed upon job completion).