#include <camnet.h>
Inheritance diagram for AsynchDownload:
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_256 & | GetTargetURL () |
const String_256 & | GetLocalFileName () |
const String_256 & | GetFileDescription () |
const HWND & | GetNotifyHWND () |
const INT32 & | GetNotifyToken () |
const String_256 & | GetCacheFileName () |
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 |
AsynchBindStatusCallback * | m_pCallback |
Static Protected Attributes | |
static INT32 | m_nNormalPriorityInstanceCount = 0 |
static INT32 | m_nHighPriorityInstanceCount = 0 |
Friends | |
class | AsynchBindStatusCallback |
class | InternetManager |
Classes | |
class | AsynchBindStatusCallback |
Definition at line 163 of file camnet.h.
|
Definition at line 169 of file camnet.h. 00169 {PRIORITY_NORMAL = 1, PRIORITY_HIGH};
|
|
Definition at line 171 of file camnet.h. 00171 {STATE_ERROR = 0, STATE_PENDING, STATE_SUCCEEDED, STATE_ABORTED, STATE_FAILED};
|
|
Constructor. > AsynchDownload::AsynchDownload(DOWNLOAD_HANDLE hDownload, LPDOWNLOADINFO pDownloadInfo)
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 }
|
|
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 }
|
|
cancels this download.
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 }
|
|
Releases COM objects allocated during the binding process.
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 }
|
|
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()
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 }
|
|
Definition at line 210 of file camnet.h. 00210 {return m_ulDownloaded;}
|
|
Definition at line 204 of file camnet.h. 00204 {return m_strCacheFileName;}
|
|
Definition at line 195 of file camnet.h. 00195 {return m_strDescription;}
|
|
Definition at line 232 of file camnet.h. 00232 { return m_nFileType;}
|
|
Definition at line 186 of file camnet.h. 00186 {return m_Handle;}
|
|
Definition at line 242 of file camnet.h. 00242 {return (priority == PRIORITY_NORMAL) ? m_nNormalPriorityInstanceCount : m_nHighPriorityInstanceCount;}
|
|
Definition at line 192 of file camnet.h. 00192 {return m_strLocalFilePath;}
|
|
Definition at line 198 of file camnet.h. 00198 {return m_hwndNotifyWindow;}
|
|
Definition at line 201 of file camnet.h. 00201 {return m_lNotifyToken;}
|
|
Definition at line 213 of file camnet.h. 00213 {return m_nPercentageDownloaded;}
|
|
Definition at line 235 of file camnet.h. 00235 { return m_Priority;}
|
|
Definition at line 207 of file camnet.h. 00207 {return m_ulFileSize;}
|
|
Definition at line 189 of file camnet.h. 00189 {return m_strTargetURL;}
|
|
Definition at line 226 of file camnet.h. 00226 { return m_bSuccess;}
|
|
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.
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 }
|
|
called in case of network error to retry the download
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 }
|
|
Definition at line 223 of file camnet.h. 00223 {return DoBind();}
|
|
Definition at line 229 of file camnet.h. 00229 { return m_bAbort;}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|