delagent.h
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 5k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //
  2. // Delivery Agents base class
  3. #ifndef _DELAGENT_H
  4. #define _DELAGENT_H
  5. #include "offline.h"
  6. #define INET_S_AGENT_BASIC_SUCCESS           _HRESULT_TYPEDEF_(0x000C0FFEL)
  7. class CDeliveryAgent :  public ISubscriptionAgentControl,
  8.                         public IShellPropSheetExt,
  9. #ifdef UNICODE
  10.                         public IExtractIconA,
  11. #endif
  12.                         public IExtractIcon,
  13.                         public ISubscriptionAgentShellExt
  14. {
  15. private:
  16. // Data for our OLE support
  17.     ULONG           m_cRef;
  18. #ifdef AGENT_AUTODIAL
  19.     enum DIALER_STATUS { DIALER_OFFLINE, DIALER_CONNECTING, DIALER_ONLINE };
  20.     DIALER_STATUS   m_iDialerStatus;
  21. #endif
  22.     enum {
  23.         FLAG_BUSY          =0x00010000,   // addrefed ourselves; between begin & end reports
  24.         FLAG_PAUSED        =0x00020000,   // We are paused
  25.         FLAG_OPSTARTED     =0x00040000,   // We've entered StartOperation
  26.     };
  27.     // Derived agents can use high 8 bits of this field
  28.     DWORD       m_dwAgentFlags;
  29.     void        SendUpdateBegin();
  30.     void        SendUpdateEnd();
  31.     HRESULT     ProcessEndItem(ISubscriptionItem *pEndItem);
  32. protected:
  33.     // Upper 16 bits allowable here
  34.     enum    {
  35.         FLAG_HOSTED        =0x00100000,     // hosted by another delivery agent
  36.         FLAG_CHANGESONLY   =0x00200000,     // We're in "Changes Only" mode
  37.         FLAG_WAITING_FOR_INCREASED_CACHE = 0x00400000, // Special paused state
  38.     };
  39.     POOEBuf         m_pBuf;
  40.     HPROPSHEETPAGE  m_hPage[MAX_WC_AGENT_PAGES];
  41.     ISubscriptionAgentEvents *m_pAgentEvents;
  42.     ISubscriptionItem        *m_pSubscriptionItem;
  43.     
  44.     SUBSCRIPTIONCOOKIE      m_SubscriptionCookie;
  45.     long        m_lSizeDownloadedKB;    // Size downloaded in KB
  46.     SCODE       m_scEndStatus;
  47.     void        SendUpdateNone();   // Call from StartOperation if we won't be doing anything
  48.     void        SendUpdateProgress(LPCWSTR pwszURL, long lProgress, long lMax, long lCurSizeKB=-1);
  49.     BOOL        IsAgentFlagSet(int iFlag) { return (m_dwAgentFlags & iFlag); }
  50.     void        ClearAgentFlag(int iFlag) { m_dwAgentFlags &= ~iFlag; }
  51.     void        SetAgentFlag(int iFlag) { m_dwAgentFlags |= iFlag; }
  52.     
  53.     HRESULT     CheckResponseCode(DWORD dwHttpResponseCode);    // Also sets EndStatus. E_ABORT on error.
  54. //  DIALER_STATUS GetDialerStatus() { return m_iDialerStatus; }
  55.     void          SetEndStatus(SCODE sc) { m_scEndStatus = sc; }
  56.     virtual ~CDeliveryAgent();
  57. public:
  58.     CDeliveryAgent();
  59.     BOOL        GetBusy() { return IsAgentFlagSet(FLAG_BUSY); }
  60.     BOOL        IsPaused() { return IsAgentFlagSet(FLAG_PAUSED); }
  61.     SCODE       GetEndStatus() { return m_scEndStatus; }
  62.     // IUnknown members
  63.     STDMETHODIMP         QueryInterface(REFIID riid, void **punk);
  64.     STDMETHODIMP_(ULONG) AddRef(void);
  65.     STDMETHODIMP_(ULONG) Release(void);
  66.     // ISubscriptionAgentControl members
  67.     STDMETHODIMP    StartUpdate(IUnknown *pItem, IUnknown *punkAdvise);
  68.     STDMETHODIMP    PauseUpdate(DWORD dwFlags);
  69.     STDMETHODIMP    ResumeUpdate(DWORD dwFlags);
  70.     STDMETHODIMP    AbortUpdate(DWORD dwFlags);
  71.     STDMETHODIMP    SubscriptionControl(IUnknown *pItem, DWORD dwControl);   // Called on delete
  72.     // IShellPropSheetExt members
  73.     STDMETHODIMP    AddPages(LPFNADDPROPSHEETPAGE, LPARAM);
  74.     STDMETHODIMP    ReplacePage(UINT, LPFNADDPROPSHEETPAGE, LPARAM);
  75.     // ISubscriptionAgentShellExt
  76.     STDMETHODIMP    Initialize(SUBSCRIPTIONCOOKIE *pSubscriptionCookie, 
  77.                                LPCWSTR pwszURL, LPCWSTR pwszName, 
  78.                                SUBSCRIPTIONTYPE subsType);
  79.     STDMETHODIMP    RemovePages(HWND hdlg);
  80.     STDMETHODIMP    SaveSubscription();
  81.     STDMETHODIMP    URLChange(LPCWSTR pwszNewURL);
  82. #ifdef UNICODE
  83.     //  IExtractIconA
  84.     STDMETHODIMP    GetIconLocation(UINT uFlags, LPSTR szIconFile, UINT cchMax, int * piIndex, UINT * pwFlags);
  85.     STDMETHODIMP    Extract(LPCSTR pszFile, UINT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIconSize);
  86. #endif
  87.     //  IExtractIconT
  88.     STDMETHODIMP    GetIconLocation(UINT uFlags, LPTSTR szIconFile, UINT cchMax, int * piIndex, UINT * pwFlags);
  89.     STDMETHODIMP    Extract(LPCTSTR pszFile, UINT nIconIndex, HICON * phiconLarge, HICON * phiconSmall, UINT nIconSize);
  90. private:
  91.     // Functions we provide common implementations for
  92.     HRESULT DoStartDownload();
  93. #ifdef AGENT_AUTODIAL
  94.     HRESULT NotifyAutoDialer();
  95.     HRESULT OnInetOnline();
  96.     HRESULT OnInetOffline();
  97. #endif
  98. protected:
  99.     // Virtual functions for our derived classes to override as necessary
  100.     // We provide implementations which should be called after processing
  101.     virtual HRESULT     AgentPause(DWORD dwFlags);
  102.     virtual HRESULT     AgentResume(DWORD dwFlags);
  103.     virtual HRESULT     AgentAbort(DWORD dwFlags);
  104.     virtual HRESULT     ModifyUpdateEnd(ISubscriptionItem *pEndItem, UINT *puiRes);
  105.     virtual HRESULT     StartOperation();       // connects to internet
  106.     virtual HRESULT     StartDownload() = 0;    // we just got connected
  107.     virtual void        CleanUp();
  108. };
  109. #endif // _DELAGENT_H