BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase Class Reference

Implements the core multi-thread download functionality based on source AIFile objects. More...

#include <mtdl.h>

Inherited by BazisLib::Network::MultiThreaded::MultiThreadHTTPDownloader.

Collaboration diagram for BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase:

Collaboration graph
[legend]

List of all members.

Classes

class  WorkerThread
 Represents a worker thread for multi-thread downloading. More...

Public Types

enum  DownloadState {
  NotStarted, Preparing, Downloading, Aborted,
  Error, Completed, Queued
}
typedef std::vector
< FileChunkDatabase::PendingChunk
ChunkList

Public Member Functions

 MultiThreadDownloaderBase (unsigned ThreadCount=5)
bool WaitForDownloadComplete (unsigned Timeout=INFINITE)
void StopDownload ()
 Stops current download and waits for threads to terminate.
ActionStatus ResumeDownload ()
 Starts download or resumes a paused/aborted/completed one.
void AllowFileAppending (bool FileAppendingAllowed)
void SetProgressHandler (PNETPROGRESSPROC pHandler, void *pContext)
ChunkList ExtractSortedDoneChunkList ()
ULONGLONG GetDownloadingFileSize ()
virtual ~MultiThreadDownloaderBase ()
virtual void SetTimeout (unsigned Timeout)=0
unsigned GetAdditionalStatusCode ()
ActionStatus ApplyThreadCount (unsigned NewThreadCount)
 Applies new thread count, that will be used after download restart.
ActionStatus GetStatus ()
bool IsDownloading ()
unsigned GetActiveThreads ()
unsigned GetMaxThreads ()
ULONGLONG GetFileSize ()
ULONGLONG GetDoneSize ()
DownloadState GetCurrentState ()
ULONGLONG GetDoneAtStart ()
FragmentFileFormat GetFormat ()

Protected Member Functions

ActionStatus StartMTDownload ()
 Downloads a file in a multi-thread mode.
ActionStatus FirstThreadService (ManagedPointer< AIFile > *ppFile)
 Wrapper for FirstThreadServiceMain().
ActionStatus FirstThreadServiceMain (ManagedPointer< AIFile > *ppFile)
 Gathers basic information about the file and starts either single- or multi-thread downloading.
ActionStatus DownloadFileInSingleThread (ManagedPointer< AIFile > &pFile, ManagedPointer< AIFile > &pDestFile)
 This method is called by FirstThreadServiceMain() when a file does not support resuming.
ActionStatusFlagErrorAndGetStatusPointer ()
 Sets current download state to Error and returns the status pointer.
void FlagAborted ()
void FlagCompleted ()
virtual ManagedPointer< AIFileOpenSourceFile (unsigned ThreadID)=0
virtual ManagedPointer< AIFileOpenDestinationFile ()=0
virtual void CancelSourceFileIO (const ConstManagedPointer< AIFile > &pFile)=0
virtual unsigned GetAdditionalErrorCode (const ConstManagedPointer< AIFile > &pFile, bool IgnoreSuccessfulCodes)=0

Protected Attributes

PNETPROGRESSPROC m_pHandler
void * m_pProgressContext
FragmentFileFormat m_PreferredFormat
ULONGLONG m_FileSize
bool m_bForceZeroFilling
bool m_bSupportResume
 Specifies whether an already existing file may fail the operation.

Private Member Functions

 DECLARE_REFERENCE (AIFragmentFormatDriver, m_pFormatDriver)
void CleanupThreadList ()
 Deleted previously created thread objects.

Private Attributes

unsigned m_ThreadCount
AtomicInt32 m_RunningThreadCount
Event m_AllThreadsDone
ActionStatus m_LastDownloadStatus
FileChunkDatabase m_Database
ULONGLONG m_BytesDone
ULONGLONG m_DoneAtStart
std::list< WorkerThread * > m_Threads
InProcessMutex m_ThreadStopMutex
 Locked when the download is stopped. TryLocked when thread 1 creates other threads.
InProcessMutex m_FastSaveMutex
DateTime m_LastStateSaveTime
DownloadState m_CurrentState
unsigned m_AdditionalErrorCode


Detailed Description

Implements the core multi-thread download functionality based on source AIFile objects.

This class implements the multi-threaded file downloading independently of the exact file type. The exact file types are supported in child classes.

Currently, only MultiThreadHTTPDownloader for downloading HTTP files is implemented.

Remarks:
Note that a single MultiThreadDownloaderBase instance is associated with a single file being downloaded. To deal with multiple downloads, use the DownloadManager class.

Member Typedef Documentation


Member Enumeration Documentation

Enumerator:
NotStarted 
Preparing 
Downloading 
Aborted 
Error 
Completed 
Queued 


Constructor & Destructor Documentation

BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::MultiThreadDownloaderBase ( unsigned  ThreadCount = 5  ) 

virtual BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::~MultiThreadDownloaderBase (  )  [virtual]


Member Function Documentation

void BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::AllowFileAppending ( bool  FileAppendingAllowed  )  [inline]

ActionStatus BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::ApplyThreadCount ( unsigned  NewThreadCount  )  [inline]

Applies new thread count, that will be used after download restart.

This method updates the maximum thread count used by the downloader.

Remarks:
The method does not have an instant effect. For the changing to have effect, the download process should be restarted.

virtual void BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::CancelSourceFileIO ( const ConstManagedPointer< AIFile > &  pFile  )  [protected, pure virtual]

void BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::CleanupThreadList (  )  [private]

Deleted previously created thread objects.

Attention:
This method should only be called after all worker threads are terminated.

BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::DECLARE_REFERENCE ( AIFragmentFormatDriver  ,
m_pFormatDriver   
) [private]

ActionStatus BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::DownloadFileInSingleThread ( ManagedPointer< AIFile > &  pFile,
ManagedPointer< AIFile > &  pDestFile 
) [protected]

This method is called by FirstThreadServiceMain() when a file does not support resuming.

ChunkList BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::ExtractSortedDoneChunkList (  )  [inline]

Here is the call graph for this function:

ActionStatus BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::FirstThreadService ( ManagedPointer< AIFile > *  ppFile  )  [protected]

ActionStatus BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::FirstThreadServiceMain ( ManagedPointer< AIFile > *  ppFile  )  [protected]

Gathers basic information about the file and starts either single- or multi-thread downloading.

void BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::FlagAborted (  )  [inline, protected]

Here is the call graph for this function:

void BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::FlagCompleted (  )  [inline, protected]

ActionStatus* BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::FlagErrorAndGetStatusPointer (  )  [inline, protected]

Sets current download state to Error and returns the status pointer.

This method should be used to retreive status variable pointer for error flagging purposes. It ensures synchronization with the m_CurrentState field.

Here is the call graph for this function:

unsigned BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetActiveThreads (  )  [inline]

virtual unsigned BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetAdditionalErrorCode ( const ConstManagedPointer< AIFile > &  pFile,
bool  IgnoreSuccessfulCodes 
) [protected, pure virtual]

unsigned BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetAdditionalStatusCode (  )  [inline]

DownloadState BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetCurrentState (  )  [inline]

ULONGLONG BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetDoneAtStart (  )  [inline]

ULONGLONG BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetDoneSize (  )  [inline]

ULONGLONG BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetDownloadingFileSize (  ) 

ULONGLONG BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetFileSize (  )  [inline]

FragmentFileFormat BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetFormat (  )  [inline]

unsigned BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetMaxThreads (  )  [inline]

ActionStatus BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::GetStatus (  )  [inline]

bool BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::IsDownloading (  )  [inline]

virtual ManagedPointer<AIFile> BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::OpenDestinationFile (  )  [protected, pure virtual]

virtual ManagedPointer<AIFile> BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::OpenSourceFile ( unsigned  ThreadID  )  [protected, pure virtual]

ActionStatus BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::ResumeDownload (  )  [inline]

Starts download or resumes a paused/aborted/completed one.

Here is the call graph for this function:

void BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::SetProgressHandler ( PNETPROGRESSPROC  pHandler,
void *  pContext 
) [inline]

virtual void BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::SetTimeout ( unsigned  Timeout  )  [pure virtual]

ActionStatus BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::StartMTDownload (  )  [protected]

Downloads a file in a multi-thread mode.

Remarks:
MultiThreadDownloaderBase class can download only one file at a single time. If you want to download more files, create multiple instances of this class.

void BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::StopDownload (  ) 

Stops current download and waits for threads to terminate.

bool BazisLib::Network::MultiThreaded::MultiThreadDownloaderBase::WaitForDownloadComplete ( unsigned  Timeout = INFINITE  ) 


Member Data Documentation

Specifies whether an already existing file may fail the operation.

Locked when the download is stopped. TryLocked when thread 1 creates other threads.


The documentation for this class was generated from the following file:
SourceForge.net Logo