progdown.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:6k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Version: RCSL 1.0/RPSL 1.0
  3.  *
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
  5.  *
  6.  * The contents of this file, and the files included with this file, are
  7.  * subject to the current version of the RealNetworks Public Source License
  8.  * Version 1.0 (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the RealNetworks Community Source License Version 1.0
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
  12.  * in which case the RCSL will apply. You may also obtain the license terms
  13.  * directly from RealNetworks.  You may not use this file except in
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or
  16.  * RCSL for the rights, obligations and limitations governing use of the
  17.  * contents of the file.
  18.  *
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the
  20.  * developer of the Original Code and owns the copyrights in the portions
  21.  * it created.
  22.  *
  23.  * This file, and the files included with this file, is distributed and made
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
  28.  *
  29.  * Technology Compatibility Kit Test Suite(s) Location:
  30.  *    http://www.helixcommunity.org/content/tck
  31.  *
  32.  * Contributor(s):
  33.  *
  34.  * ***** END LICENSE BLOCK ***** */
  35. #ifndef PROGDOWN_H
  36. #define PROGDOWN_H
  37. // Forward declarations
  38. typedef _INTERFACE IHXDataFile  IHXDataFile;
  39. typedef _INTERFACE IHXScheduler IHXScheduler;
  40. typedef _INTERFACE IHXRegistry  IHXRegistry;
  41. class CHXGenericCallback;
  42. // Defines - these can all be overridden
  43. // with preferences (see CheckPreferenceValues())
  44. #define PROGDOWN_STAT_INTERVAL_DEFAULT  1000 // Check filesize at this interval
  45. #define PROGDOWN_STAT_INTERVAL_INITIAL     8 // Initially start at this interval and backoff (CANNOT BE ZERO)
  46. #define PROGDOWN_FAIL_INTERVAL_DEFAULT   100 // Retry failed seeks/reads at this interval
  47. #define PROGDOWN_FINISHED_TIME_DEFAULT  5000 // If filesize unchanged for this duration,
  48.                                              // then assume the download is finished
  49. #define PROGDOWN_FORMER_PROG_RETRY_INIT   20 // If we were formerly progressive but not now, retry this many
  50.                                              // times before failing out
  51. #define PROGDOWN_NOT_PROG_RETRY_INIT      40 // If we have never been progressive, retry this many
  52.                                              // times before failing out
  53. class CProgressiveDownloadMonitorResponse : public IUnknown
  54. {
  55. public:
  56.     // IUnknown methods
  57.     STDMETHOD(QueryInterface)   (THIS_ REFIID riid, void** ppvObj) PURE;
  58.     STDMETHOD_(ULONG32,AddRef)  (THIS) PURE;
  59.     STDMETHOD_(ULONG32,Release) (THIS) PURE;
  60.     // CProgressiveDownloadMonitorResponse methods
  61.     STDMETHOD(ProgressiveCallback) (THIS) PURE;
  62. };
  63. class CProgressiveDownloadMonitor : public CHXBaseCountingObject
  64. {
  65. public:
  66.     CProgressiveDownloadMonitor();
  67.     virtual ~CProgressiveDownloadMonitor();
  68.     HX_RESULT   Init(IUnknown* pContext, IHXDataFile* pFile,
  69.                      CProgressiveDownloadMonitorResponse* pResponse);
  70.     HX_RESULT   Close();
  71.     BOOL        IsProgressive() { return m_bIsProgressive; }
  72.     BOOL        HasBeenProgressive() { return m_bHasBeenProgressive; }
  73.     UINT32      GetFormerProgressiveRetryCount() { return m_ulFormerProgRetryCount; }
  74.     void        DecrementFormerProgressiveRetryCount() { if (m_ulFormerProgRetryCount) m_ulFormerProgRetryCount--; }
  75.     UINT32      GetNotProgressiveRetryCount() { return m_ulNotProgRetryCount; }
  76.     void        DecrementNotProgressiveRetryCount() { if (m_ulNotProgRetryCount) m_ulNotProgRetryCount--; }
  77.     void        ResetNotProgressiveRetryCount() { m_ulNotProgRetryCount = m_ulNotProgRetryInit; }
  78.     HX_RESULT   ScheduleCallback();
  79.     BOOL        IsCallbackPending();
  80.     void        CancelCallback();
  81.     HX_RESULT   BeginSizeMonitoring();
  82.     void        EndSizeMonitoring();
  83.     UINT32      GetFileSizeNow();
  84.     void        MonitorFileSize();
  85.     static void StatCallback(void* pArg);
  86.     static void ProgCallback(void* pArg);
  87. protected:
  88.     IUnknown*                            m_pContext;
  89.     IHXDataFile*                         m_pDataFile;
  90.     CProgressiveDownloadMonitorResponse* m_pResponse;
  91.     IHXScheduler*                        m_pScheduler;
  92.     IHXRegistry*                         m_pRegistry;
  93.     CHXGenericCallback*                  m_pStatCallback;
  94.     CHXGenericCallback*                  m_pProgCallback;
  95.     UINT32                               m_ulStatCallbackInterval;
  96.     UINT32                               m_ulCurStatInterval;
  97.     UINT32                               m_ulProgCallbackInterval;
  98.     UINT32                               m_ulFinishedTime;
  99.     UINT32                               m_ulLastFileSize;
  100.     UINT32                               m_ulTickAtLastFileSize;
  101.     UINT32                               m_ulURLRegistryID;
  102.     UINT32                               m_ulIsProgRegistryID;
  103.     UINT32                               m_ulFormerProgRetryCount;
  104.     UINT32                               m_ulFormerProgRetryInit;
  105.     UINT32                               m_ulNotProgRetryCount;
  106.     UINT32                               m_ulNotProgRetryInit;
  107.     BOOL                                 m_bIsProgressive;
  108.     BOOL                                 m_bMonitorEnabled;
  109.     BOOL                                 m_bHasBeenProgressive;
  110.     void      CheckPreferenceValues(REF(BOOL)   rbMonitorEnabled,
  111.                                     REF(UINT32) rulStatCallbackInterval,
  112.                                     REF(UINT32) rulProgCallbackInterval,
  113.                                     REF(UINT32) rulFinishedTime,
  114.                                     REF(UINT32) rulFormerProgRetryCount,
  115.                                     REF(UINT32) rulNotProgRetryCount);
  116.     HX_RESULT InitRegistryStats();
  117.     void      UpdateRegistryStats();
  118.     void      ScheduleStatCallback();
  119. };
  120. #endif /* #ifndef PROGDOWN_H */