DownloadOp Class Reference

File download operation. This class is intended as a base class for new Internet-related operations - it has little use on its own. The older internet operations used in Webster 1 are derived straight from Operation and were a bit difficult to implement. More...

#include <inetop.h>

Inheritance diagram for DownloadOp:

Operation MessageHandler ListItem CCObject SimpleCCObject HelpDownloadOp OpAsynchBitmapImport OpAsynchFontInstall OpBitmapDownload OpGenericDownload List of all members.

Public Member Functions

 DownloadOp ()
 DownloadOp constructor.
virtual ~DownloadOp ()
 DownloadOp destructor.
virtual void Do (OpDescriptor *)
virtual BOOL OnIdleEvent ()
 
  • idle time polling loop; continues until either the download completes or the operation is terminated on receiving a death message. The appropriate functions are called according to the state of the download on completion (succeeded/aborted/failed)

virtual void DoWithParam (OpDescriptor *pOp, OpParam *pDownloadOpParam)
 Request a download with the parameters passed in pDownloadOpParam.
virtual void End ()
 overrides Operation::End() to avoid having an ERROR2 (caused by Document::GetSelectedSpread() returning NULL) go off when Camelot exits while a download is still in progress
virtual BOOL OnDeathMsg ()
virtual void OnDownloadSuccess ()
 
  • This function is called if the file download completes successfully so that we can process it or take some other action. Derived classes should override this function - the current implementation does nothing.

virtual void OnDownloadFail ()
 
  • This function is called if the file download fails. The current implemention simply outputs an error message based on the file type declared in DownloadOpParam. If you want something more sophisticated override this function in your class.

virtual void OnDownloadAbort ()
 
  • This function is called if the file download is cancelled by the user. Derived classes should override this function if some specific action is required in this case.

virtual void OnDownloadPending ()
 
  • This function is called if the file download is just in the process of working. Derived classes should override this function if some specific action is required in this case.


Static Public Member Functions

static BOOL Init ()
 Creates an OpDescriptor for a DownloadOp.
static OpState GetState (String_256 *, OpDescriptor *)
 Returns the OpState of the DownloadOp operation.

Public Attributes

DownloadOpParampParam

Protected Member Functions

virtual void OnDownloadProgress (const INT32 nPercentageCompleted)

Protected Attributes

DOWNLOAD_HANDLE m_hDownload
INT32 m_nPercentageCompleted

Detailed Description

File download operation. This class is intended as a base class for new Internet-related operations - it has little use on its own. The older internet operations used in Webster 1 are derived straight from Operation and were a bit difficult to implement.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/04/97
See also:
-

Definition at line 179 of file inetop.h.


Constructor & Destructor Documentation

DownloadOp::DownloadOp  ) 
 

DownloadOp constructor.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
3/04/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 170 of file inetop.cpp.

00171 {
00172     pParam = NULL;
00173     m_hDownload = 0;
00174     m_nPercentageCompleted = 0;
00175     OpFlags.HasOwnTimeIndicator = TRUE;
00176 //  GetApplication()->RegisterIdleProcessor(IDLEPRIORITY_LOW, this); // start the polling loop
00177 }       

DownloadOp::~DownloadOp  )  [virtual]
 

DownloadOp destructor.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/04/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
-

Definition at line 194 of file inetop.cpp.

00195 {
00196     GetApplication()->RemoveIdleProcessor(IDLEPRIORITY_LOW, this); // end polling loop
00197     if (pParam)
00198         delete pParam;
00199 }


Member Function Documentation

void DownloadOp::Do OpDescriptor NotUsed  )  [virtual]
 

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
20/1/97
Parameters:
OpDescriptor* (unused) [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: Always fails - should not be called

See also:
-

Reimplemented from Operation.

Definition at line 263 of file inetop.cpp.

00264 {
00265     ERROR3("This operation does not provide a Do() function - Use DoWithParam");
00266     End();
00267 }

void DownloadOp::DoWithParam OpDescriptor pOp,
OpParam pDownloadOpParam
[virtual]
 

Request a download with the parameters passed in pDownloadOpParam.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
pOp - OpDescriptor as for all Do() functions [INPUTS] pDownloadOpParam - pointer to DownloadOpParam structure . This structure must be created on the heap as it should not be destroyed when it goes out of scope.
- none [OUTPUTS] Note that this function returns immediately after starting the download.
Returns:
-

Reimplemented from Operation.

Definition at line 286 of file inetop.cpp.

00287 {
00288     DownloadOpParam *pInfo = (DownloadOpParam*) pDownloadOpParam;
00289     if (pInfo == NULL)
00290     {
00291         ERROR3("DoWithParam called with invalid pointer");
00292         goto FAIL;
00293     }
00294     else
00295     {
00296         if (!pInfo->file.IsValid() || pInfo->strURL.IsEmpty())
00297         {
00298             ERROR3("Invalid file path or URL");
00299             goto FAIL;
00300         }
00301         // Register the file for download
00302         DOWNLOADINFO downloadInfo;
00303         downloadInfo.strURL = pInfo->strURL;
00304         downloadInfo.strLocalFile = (String_256) pInfo->file.GetPath();
00305         downloadInfo.nFileType = pInfo->type;
00306         downloadInfo.nPriority = pInfo->priority;
00307         downloadInfo.strDescription = pInfo->strDescription;
00308         downloadInfo.bHasProgressDlg = TRUE;
00309 
00310         // NEW! Tell this downloader that we can handle status messages
00311         // (We don't use Idle event polling)
00312         downloadInfo.hwndNotifyWindow = GetMainFrame()->GetSafeHwnd();
00313         downloadInfo.lNotifyToken = (INT32)this;
00314 
00315         m_hDownload = InternetManager::RegisterDownload(&downloadInfo);
00316         if (!m_hDownload || m_hDownload == (DOWNLOAD_HANDLE) INVALID_HANDLE_VALUE)
00317         {
00318             ERROR3("Failed to register download");
00319             goto FAIL;
00320         }
00321         pParam = pInfo;
00322         if (pInfo->Output)
00323             *(pInfo->Output) = TRUE;
00324     }
00325     return;
00326 
00327 FAIL:
00328         if (pInfo->Output)
00329             *(pInfo->Output) = FALSE;
00330         FailAndDiscard(); 
00331         End();
00332 }

void DownloadOp::End  )  [virtual]
 

overrides Operation::End() to avoid having an ERROR2 (caused by Document::GetSelectedSpread() returning NULL) go off when Camelot exits while a download is still in progress

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
21/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Errors: -

See also:
Operation::End()

Reimplemented from Operation.

Definition at line 352 of file inetop.cpp.

00353 {
00354     if (m_hDownload)
00355         InternetManager::UnregisterDownload(m_hDownload);
00356     if (Document::GetSelectedSpread())
00357         Operation::End();
00358     else
00359         EndOp();
00360 }   

OpState DownloadOp::GetState String_256 pString,
OpDescriptor pOpDesc
[static]
 

Returns the OpState of the DownloadOp operation.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/04/97
See also:

Reimplemented in OpGenericDownload, HelpDownloadOp, and OpBitmapDownload.

Definition at line 240 of file inetop.cpp.

00241 {
00242     OpState OpSt;
00243     return(OpSt);
00244 }

BOOL DownloadOp::Init void   )  [static]
 

Creates an OpDescriptor for a DownloadOp.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
4/04/97
Returns:
FALSE if it fails (due to lack of memory)
See also:

Reimplemented from SimpleCCObject.

Reimplemented in OpAsynchFontInstall, OpAsynchBitmapImport, OpGenericDownload, HelpDownloadOp, and OpBitmapDownload.

Definition at line 214 of file inetop.cpp.

00215 {  
00216     return RegisterOpDescriptor(
00217         0,                              // Tool ID
00218         _R(IDS_OPDOWNLOAD),             // String resource ID
00219         CC_RUNTIME_CLASS(DownloadOp),   // Runtime class
00220         OPTOKEN_OPDOWNLOAD,         // Token string
00221         DownloadOp::GetState,           // GetState function
00222         0,                              // Help ID
00223         0,                              // Bubble ID
00224         0,                              // Resource ID
00225         0                               // Control ID
00226     );
00227 }   

virtual BOOL DownloadOp::OnDeathMsg void   )  [inline, virtual]
 

Reimplemented from MessageHandler.

Definition at line 195 of file inetop.h.

00195 { End(); return TRUE;}

void DownloadOp::OnDownloadAbort  )  [virtual]
 

  • This function is called if the file download is cancelled by the user. Derived classes should override this function if some specific action is required in this case.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Reimplemented in OpGenericDownload, and HelpDownloadOp.

Definition at line 480 of file inetop.cpp.

00481 {
00482 }

void DownloadOp::OnDownloadFail  )  [virtual]
 

  • This function is called if the file download fails. The current implemention simply outputs an error message based on the file type declared in DownloadOpParam. If you want something more sophisticated override this function in your class.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Reimplemented in OpGenericDownload, HelpDownloadOp, and OpBitmapDownload.

Definition at line 456 of file inetop.cpp.

00457 {
00458         String_256 strTemp;
00459         strTemp.MakeMsg(_R(IDS_DOWNLOADFAILED), (TCHAR*) (String_256) GetStringField((UINT32) pParam->type, _R(IDS_GALLERY_DESCRIPTIONS)), (TCHAR*) pParam->strDescription);
00460         Error::SetError(0, strTemp, 0);
00461         InformError();
00462 }

void DownloadOp::OnDownloadPending  )  [virtual]
 

  • This function is called if the file download is just in the process of working. Derived classes should override this function if some specific action is required in this case.

Author:
Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
Date:
04/05/2004
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Definition at line 502 of file inetop.cpp.

00503 {
00504     // check the percentage downloaded so far
00505     INT32 nPercentageCompleted = 0;
00506     nPercentageCompleted = InternetManager::GetPercentageDownloaded(m_hDownload);
00507 //  ERROR3IF(nPercentageCompleted == -1, "Invalid download handle");
00508     if (nPercentageCompleted != -1)
00509     {
00510         if (nPercentageCompleted != m_nPercentageCompleted) // we made some progress
00511         {
00512             m_nPercentageCompleted = nPercentageCompleted;
00513             OnDownloadProgress(nPercentageCompleted);
00514         }
00515     }
00516 }

virtual void DownloadOp::OnDownloadProgress const INT32  nPercentageCompleted  )  [inline, protected, virtual]
 

Definition at line 204 of file inetop.h.

00204 {}; // called when a new chunk of data arrives 

void DownloadOp::OnDownloadSuccess  )  [virtual]
 

  • This function is called if the file download completes successfully so that we can process it or take some other action. Derived classes should override this function - the current implementation does nothing.

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
-

Reimplemented in OpAsynchFontInstall, OpAsynchBitmapImport, OpGenericDownload, HelpDownloadOp, and OpBitmapDownload.

Definition at line 437 of file inetop.cpp.

00438 {
00439 }

BOOL DownloadOp::OnIdleEvent void   )  [virtual]
 

  • idle time polling loop; continues until either the download completes or the operation is terminated on receiving a death message. The appropriate functions are called according to the state of the download on completion (succeeded/aborted/failed)

Author:
Adrian_Stoicar (Xara Group Ltd) <camelotdev@xara.com>
Date:
7/01/97
Parameters:
- [INPUTS]
- [OUTPUTS]
Returns:
- TRUE if we want to continue polling, FALSE otherwise

Reimplemented from Operation.

Definition at line 381 of file inetop.cpp.

00382 {
00383 //ERROR2(FALSE, "DownloadOp::OnIdleEvent should no longer be called!!!");
00384     INT32 nPercentageCompleted = 0;
00385     ERROR2IF(!pParam, FALSE, "Unexpected NULL pointer");
00386     switch (InternetManager::GetDownloadState(m_hDownload))
00387     {
00388         case AsynchDownload::STATE_PENDING:
00389             // check the percentage downloaded so far
00390             nPercentageCompleted = InternetManager::GetPercentageDownloaded(m_hDownload);
00391             ERROR3IF(nPercentageCompleted == -1, "Invalid download handle");
00392             if (nPercentageCompleted != m_nPercentageCompleted) // we made some progress
00393             {
00394                 m_nPercentageCompleted = nPercentageCompleted;
00395                 OnDownloadProgress(nPercentageCompleted);
00396             }
00397             // download pending, so we continue polling
00398             return TRUE;
00399         case AsynchDownload::STATE_SUCCEEDED:
00400             // file has transferred successfully, we call OnDownloadSuccess() to process it
00401             OnDownloadSuccess();
00402             SucceedAndDiscard();
00403             End();
00404             return FALSE;
00405         case AsynchDownload::STATE_FAILED:
00406             OnDownloadFail();
00407             break;
00408         case AsynchDownload::STATE_ABORTED:
00409             OnDownloadAbort();
00410             break;
00411         default:
00412             ERROR3("Error or unrecognized state");
00413     }
00414     FailAndDiscard();
00415     End();
00416     return FALSE;
00417 }


Member Data Documentation

DOWNLOAD_HANDLE DownloadOp::m_hDownload [protected]
 

Definition at line 202 of file inetop.h.

INT32 DownloadOp::m_nPercentageCompleted [protected]
 

Definition at line 203 of file inetop.h.

DownloadOpParam* DownloadOp::pParam
 

Definition at line 184 of file inetop.h.


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