AsynchDownload Class Reference

Asynchronous download class - downloads a url to a local file using HTTP Used by the download manager. More...

#include <camnet.h>

Inheritance diagram for AsynchDownload:

CCObject SimpleCCObject List of all members.

Public Types

enum  Priority { PRIORITY_NORMAL = 1, PRIORITY_HIGH }
enum  State {
  STATE_ERROR = 0, STATE_PENDING, STATE_SUCCEEDED, STATE_ABORTED,
  STATE_FAILED
}

Public Member Functions

 AsynchDownload (INT32 hDownload, LPDOWNLOADINFO pDownloadInfo)
 Constructor.
 ~AsynchDownload ()
const INT32 GetHandle ()
const String_256GetTargetURL ()
const String_256GetLocalFileName ()
const String_256GetFileDescription ()
const HWND & GetNotifyHWND ()
const INT32 & GetNotifyToken ()
const String_256GetCacheFileName ()
const UINT32 GetRemoteFileSize ()
const UINT32 GetBytesDownloaded ()
const INT32 GetPercentageDownloaded ()
HRESULT AbortDownload ()
 cancels this download.
HRESULT StartDownload ()
BOOL HasSucceeded ()
BOOL WasAborted ()
INT32 GetFileType ()
Priority GetPriority ()
void Release ()
 Provides a safe way to free memory and resources allocated to this download Should be used in preference to the delete operator which may cause access violations if the download is still in progress.

Static Public Member Functions

static INT32 GetInstanceCount (Priority priority)

Protected Member Functions

HRESULT DoBind ()
 Binds asynchronously an URL moniker to local storage (a file in the Internet cache) The function returns immediately an HRESULT indicating merely whether the bind was started successfuly, or failed due to invalid data, insufficient memory, etc., not waiting for the bind to complete. The result of the started bind operation is returned by AsynchBindCallback::OnStopBind().
void Cleanup ()
 Releases COM objects allocated during the binding process.
HRESULT Retry ()
 called in case of network error to retry the download

Protected Attributes

INT32 m_Handle
String_256 m_strTargetURL
String_256 m_strLocalFilePath
BOOL m_bHasProgressDlg
String_256 m_strDescription
BOOL m_bAbort
BOOL m_bSuccess
UINT32 m_ulFileSize
UINT32 m_ulDownloaded
INT32 m_nPercentageDownloaded
String_256 m_strCacheFileName
IMoniker * m_pMoniker
IBindCtx * m_pBindContext
Priority m_Priority
HWND m_hwndNotifyWindow
INT32 m_lNotifyToken
INT32 m_nFileType
INT32 m_nAttempts
AsynchBindStatusCallbackm_pCallback

Static Protected Attributes

static INT32 m_nNormalPriorityInstanceCount = 0
static INT32 m_nHighPriorityInstanceCount = 0

Friends

class AsynchBindStatusCallback
class InternetManager

Classes

class  AsynchBindStatusCallback

Detailed Description

Asynchronous download class - downloads a url to a local file using HTTP Used by the download manager.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
11/12/96
See also:
InternetManager

Definition at line 163 of file camnet.h.


Member Enumeration Documentation

enum AsynchDownload::Priority
 

Enumerator:
PRIORITY_NORMAL 
PRIORITY_HIGH 

Definition at line 169 of file camnet.h.

enum AsynchDownload::State
 

Enumerator:
STATE_ERROR 
STATE_PENDING 
STATE_SUCCEEDED 
STATE_ABORTED 
STATE_FAILED 

Definition at line 171 of file camnet.h.


Constructor & Destructor Documentation

AsynchDownload::AsynchDownload INT32  hDownload,
LPDOWNLOADINFO  pDownloadInfo
 

Constructor.

> AsynchDownload::AsynchDownload(DOWNLOAD_HANDLE hDownload, LPDOWNLOADINFO pDownloadInfo)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
hDownload - handle of download as assigned by the InternetManager [INPUTS] pDownloadInfo - pointer to DOWNLOADINFO struct
Notes: This constructor is not meant to be called directly - use InternetManager::RegisterDownload() if you want to download a file

Definition at line 166 of file camnet.cpp.

00167 {
00168     m_Handle = hDownload;
00169     m_bSuccess = FALSE;
00170     m_ulFileSize = 0;
00171     m_ulDownloaded = 0;
00172     m_nPercentageDownloaded = 0;
00173     m_bAbort = FALSE;
00174     m_pMoniker = NULL;
00175     m_pBindContext = NULL;
00176     m_pCallback = NULL;
00177     m_strTargetURL = pDownloadInfo->strURL;
00178     m_strLocalFilePath = pDownloadInfo->strLocalFile;
00179     m_nFileType = (FileType) pDownloadInfo->nFileType;
00180     m_nAttempts = 0;
00181     m_Priority = (Priority) pDownloadInfo->nPriority;
00182     m_bHasProgressDlg = pDownloadInfo->bHasProgressDlg;
00183     if (m_bHasProgressDlg = pDownloadInfo->bHasProgressDlg)
00184         m_strDescription = pDownloadInfo->strDescription;
00185     if (m_Priority == PRIORITY_NORMAL)
00186         m_nNormalPriorityInstanceCount++;
00187     else if (m_Priority == PRIORITY_HIGH)
00188         m_nHighPriorityInstanceCount++;
00189 
00190     m_hwndNotifyWindow = pDownloadInfo->hwndNotifyWindow;
00191     m_lNotifyToken = pDownloadInfo->lNotifyToken;
00192 
00193     AfxOleLockApp();
00194 }

AsynchDownload::~AsynchDownload  ) 
 

Definition at line 196 of file camnet.cpp.

00197 {
00198     // Deallocate whatever resources were alocated during the binding operation
00199     Cleanup();
00200     if (m_Priority == PRIORITY_NORMAL)
00201         m_nNormalPriorityInstanceCount--;
00202     else if (m_Priority == PRIORITY_HIGH)
00203         m_nHighPriorityInstanceCount--;
00204     AfxOleUnlockApp();
00205 }


Member Function Documentation

HRESULT AsynchDownload::AbortDownload  ) 
 

cancels this download.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
- [INPUTS]
Returns:
- S_OK if the download operation operation was successfully aborted.
  • S_FALSE if the download was already aborted.
  • E_FAIL if the download operation could not be aborted.

Definition at line 356 of file camnet.cpp.

00357  {
00358     if (m_bAbort)
00359         return S_FALSE;
00360     else
00361         m_bAbort = TRUE;
00362     if (m_pCallback)
00363     {
00364         if (m_pCallback->m_pBinding)
00365             return m_pCallback->m_pBinding->Abort();
00366         else
00367             return E_FAIL;
00368     }
00369     return E_FAIL;
00370 }

void AsynchDownload::Cleanup  )  [protected]
 

Releases COM objects allocated during the binding process.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
- [INPUTS]
Returns:
-

Definition at line 293 of file camnet.cpp.

00294 {
00295     if (m_pCallback)
00296     {
00297         m_pCallback->Release();
00298         m_pCallback = NULL;
00299     }
00300     if (m_pMoniker)
00301     {
00302         m_pMoniker->Release();
00303         m_pMoniker = NULL;
00304     }
00305     if (m_pBindContext)
00306     {
00307         m_pBindContext->Release();
00308         m_pBindContext = NULL;
00309     }
00310 }

HRESULT AsynchDownload::DoBind  )  [protected]
 

Binds asynchronously an URL moniker to local storage (a file in the Internet cache) The function returns immediately an HRESULT indicating merely whether the bind was started successfuly, or failed due to invalid data, insufficient memory, etc., not waiting for the bind to complete. The result of the started bind operation is returned by AsynchBindCallback::OnStopBind().

> HRESULT AsynchDownload::DoBind()

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
none [INPUTS] Return: S_OK if successful, E_FAIL otherwise

Definition at line 227 of file camnet.cpp.

00228 {
00229     if (m_strTargetURL.IsEmpty() || m_strLocalFilePath.IsEmpty())
00230     {
00231         ERROR3("Invalid (empty) URL or file path");
00232         return E_FAIL;
00233     }
00234 #ifdef _DEBUG
00235     String_256 strErrorMsg(m_strTargetURL); // we keep a non-wide copy of the URL for error reporting purposes
00236 #endif
00237     WCHAR wchURL[INTERNET_MAX_PATH_LENGTH];
00238     MultiByteToWideChar(CP_ACP, 0,  (TCHAR*) m_strTargetURL, -1, wchURL, INTERNET_MAX_PATH_LENGTH);
00239     if (IsValidURL(NULL, wchURL, 0) == S_FALSE)
00240     {
00241 #ifdef _DEBUG
00242         strErrorMsg += _T(" is not a valid URL");
00243         ERROR3(strErrorMsg);
00244 #endif
00245         return E_FAIL;
00246     }
00247     IStream* pStream = NULL;
00248     m_pCallback = new AsynchBindStatusCallback(this);
00249     if (!m_pCallback)
00250     { 
00251         ERROR3("Memory allocation error");
00252         return E_OUTOFMEMORY;
00253     }
00254     HRESULT hr = CreateURLMoniker(NULL, wchURL, &m_pMoniker);
00255     if (FAILED(hr))
00256     {
00257         ERROR3("Could not create URL Moniker");
00258         Cleanup();
00259         return hr;
00260     }
00261     hr = CreateBindCtx(0, &m_pBindContext);
00262     if (FAILED(hr))
00263     {
00264         ERROR3("Could not create bind context");
00265         Cleanup();
00266         return hr;
00267     }
00268     hr = RegisterBindStatusCallback(m_pBindContext, m_pCallback, 0, 0L);
00269     if (FAILED(hr))
00270     {
00271         ERROR3("Failed to register callback object");
00272         Cleanup();
00273         return hr;
00274     }
00275     hr = m_pMoniker->BindToStorage(m_pBindContext, 0, IID_IStream, (void**)&pStream);
00276     m_nAttempts++;
00277     return hr;
00278 }

const UINT32 AsynchDownload::GetBytesDownloaded  )  [inline]
 

Definition at line 210 of file camnet.h.

00210 {return m_ulDownloaded;}

const String_256& AsynchDownload::GetCacheFileName  )  [inline]
 

Definition at line 204 of file camnet.h.

00204 {return m_strCacheFileName;}

const String_256& AsynchDownload::GetFileDescription  )  [inline]
 

Definition at line 195 of file camnet.h.

00195 {return m_strDescription;}

INT32 AsynchDownload::GetFileType  )  [inline]
 

Definition at line 232 of file camnet.h.

00232 { return m_nFileType;} 

const INT32 AsynchDownload::GetHandle  )  [inline]
 

Definition at line 186 of file camnet.h.

00186 {return m_Handle;}

static INT32 AsynchDownload::GetInstanceCount Priority  priority  )  [inline, static]
 

Definition at line 242 of file camnet.h.

const String_256& AsynchDownload::GetLocalFileName  )  [inline]
 

Definition at line 192 of file camnet.h.

00192 {return m_strLocalFilePath;}

const HWND& AsynchDownload::GetNotifyHWND  )  [inline]
 

Definition at line 198 of file camnet.h.

00198 {return m_hwndNotifyWindow;}

const INT32& AsynchDownload::GetNotifyToken  )  [inline]
 

Definition at line 201 of file camnet.h.

00201 {return m_lNotifyToken;}

const INT32 AsynchDownload::GetPercentageDownloaded  )  [inline]
 

Definition at line 213 of file camnet.h.

00213 {return m_nPercentageDownloaded;}

Priority AsynchDownload::GetPriority  )  [inline]
 

Definition at line 235 of file camnet.h.

00235 { return m_Priority;} 

const UINT32 AsynchDownload::GetRemoteFileSize  )  [inline]
 

Definition at line 207 of file camnet.h.

00207 {return m_ulFileSize;} 

const String_256& AsynchDownload::GetTargetURL  )  [inline]
 

Definition at line 189 of file camnet.h.

00189 {return m_strTargetURL;}

BOOL AsynchDownload::HasSucceeded  )  [inline]
 

Definition at line 226 of file camnet.h.

00226 { return m_bSuccess;}

void AsynchDownload::Release void   ) 
 

Provides a safe way to free memory and resources allocated to this download Should be used in preference to the delete operator which may cause access violations if the download is still in progress.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
- [INPUTS]
Returns:
-

Definition at line 387 of file camnet.cpp.

00388 {
00389     if (m_pCallback && m_pCallback->m_pBinding)
00390         m_pCallback->m_pBinding->Abort();
00391     else
00392         delete this;
00393 }

HRESULT AsynchDownload::Retry  )  [protected]
 

called in case of network error to retry the download

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
18/11/96
Parameters:
- [INPUTS]
Returns:
- always S_OK

Definition at line 323 of file camnet.cpp.

00324 {
00325     if (m_nAttempts <= MAX_ATTEMPTS) // try another bind if we're allowed
00326     {
00327         TRACEUSER( "adrian", _T("\n\nRetrying the %d time to download %s\n\n"), m_nAttempts, (TCHAR*) m_strTargetURL);
00328         Cleanup();
00329         DoBind();
00330     }
00331     else // just inform the download manager that we're done
00332     {
00333         TRACEUSER( "adrian", _T("\n\nGiving up on %s\n\n"), (TCHAR*) m_strTargetURL);
00334         InternetManager::OnDownloadComplete(this);
00335     }
00336     return S_OK;
00337 }

HRESULT AsynchDownload::StartDownload  )  [inline]
 

Definition at line 223 of file camnet.h.

00223 {return DoBind();}

BOOL AsynchDownload::WasAborted  )  [inline]
 

Definition at line 229 of file camnet.h.

00229 { return m_bAbort;}


Friends And Related Function Documentation

friend class AsynchBindStatusCallback [friend]
 

Definition at line 354 of file camnet.h.

friend class InternetManager [friend]
 

Definition at line 355 of file camnet.h.


Member Data Documentation

BOOL AsynchDownload::m_bAbort [protected]
 

Definition at line 257 of file camnet.h.

BOOL AsynchDownload::m_bHasProgressDlg [protected]
 

Definition at line 255 of file camnet.h.

BOOL AsynchDownload::m_bSuccess [protected]
 

Definition at line 258 of file camnet.h.

INT32 AsynchDownload::m_Handle [protected]
 

Definition at line 252 of file camnet.h.

HWND AsynchDownload::m_hwndNotifyWindow [protected]
 

Definition at line 266 of file camnet.h.

INT32 AsynchDownload::m_lNotifyToken [protected]
 

Definition at line 267 of file camnet.h.

INT32 AsynchDownload::m_nAttempts [protected]
 

Definition at line 269 of file camnet.h.

INT32 AsynchDownload::m_nFileType [protected]
 

Definition at line 268 of file camnet.h.

INT32 AsynchDownload::m_nHighPriorityInstanceCount = 0 [static, protected]
 

Definition at line 271 of file camnet.h.

INT32 AsynchDownload::m_nNormalPriorityInstanceCount = 0 [static, protected]
 

Definition at line 270 of file camnet.h.

INT32 AsynchDownload::m_nPercentageDownloaded [protected]
 

Definition at line 261 of file camnet.h.

IBindCtx* AsynchDownload::m_pBindContext [protected]
 

Definition at line 264 of file camnet.h.

AsynchBindStatusCallback* AsynchDownload::m_pCallback [protected]
 

Definition at line 352 of file camnet.h.

IMoniker* AsynchDownload::m_pMoniker [protected]
 

Definition at line 263 of file camnet.h.

Priority AsynchDownload::m_Priority [protected]
 

Definition at line 265 of file camnet.h.

String_256 AsynchDownload::m_strCacheFileName [protected]
 

Definition at line 262 of file camnet.h.

String_256 AsynchDownload::m_strDescription [protected]
 

Definition at line 256 of file camnet.h.

String_256 AsynchDownload::m_strLocalFilePath [protected]
 

Definition at line 254 of file camnet.h.

String_256 AsynchDownload::m_strTargetURL [protected]
 

Definition at line 253 of file camnet.h.

UINT32 AsynchDownload::m_ulDownloaded [protected]
 

Definition at line 260 of file camnet.h.

UINT32 AsynchDownload::m_ulFileSize [protected]
 

Definition at line 259 of file camnet.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:50:03 2007 for Camelot by  doxygen 1.4.4