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

Windows Kernel

Development Platform:

Visual C++

  1. //+-----------------------------------------------------------------------
  2. //
  3. //  Add/Remove Programs Data Source Object
  4. //
  5. //------------------------------------------------------------------------
  6. #ifndef _DATASRC_H_
  7. #define _DATASRC_H_
  8. #include <simpdata.h>       // for OLEDBSimpleProvider
  9. #include "mtxarray.h"       // for CMtxArray
  10. #include "worker.h"
  11. #include "iface.h"          // for IARPSimpleProvider
  12. // The load state progression can be as follows:
  13. //
  14. //  LS_NOTSTARTED  -->  LS_LOADING_SLOWINFO -->  LS_DONE
  15. //
  16. // or
  17. //
  18. //  LS_NOTSTARTED  -->  LS_DONE
  19. //  
  20. enum LOAD_STATE
  21. {
  22.     LS_NOTSTARTED,                  // OSP is not initialized
  23.     LS_LOADING_SLOWINFO,            // loading slow info (worker thread)
  24.     LS_DONE,                        // completely finished
  25. };
  26. // Do not build this file if on Win9X or NT4
  27. #ifndef DOWNLEVEL_PLATFORM
  28. //------------------------------------------------------------------------
  29. //
  30. //  CDataSrc (ARP Data Source Object)
  31. //
  32. //  This is the OSP (OLEDB Simple Provider).  It organizes
  33. //  the data in matrix form and disseminates the data to the data
  34. //  consumer via the OLEDBSimpleProvider interface.
  35. //
  36. //------------------------------------------------------------------------
  37. class CDataSrc : public CWorkerThread,
  38.                 public OLEDBSimpleProvider,
  39.                 public IWorkerEvent,
  40.                 public IARPSimpleProvider,
  41.                 public ISequentialStream
  42. {
  43. public:
  44.     // *** IUnknown ***
  45.     virtual STDMETHODIMP_(ULONG) AddRef   (void) {return CWorkerThread::AddRef();};
  46.     virtual STDMETHODIMP_(ULONG) Release  (void) {return CWorkerThread::Release();};
  47.     virtual STDMETHODIMP QueryInterface   (REFIID riid, LPVOID * ppvObj);
  48.     // *** ISequentialStream ***
  49.     STDMETHOD(Read)             (void * pvData, ULONG cbData, ULONG * pcbRead);
  50.     STDMETHOD(Write)            (void const * pvData, ULONG cbData, ULONG * pcbWritten);
  51.     
  52.     // *** OLEDBSimpleProvider ***
  53.     STDMETHOD(getRowCount)      (DBROWCOUNT *pcRows);
  54.     STDMETHOD(getColumnCount)   (DB_LORDINAL *pcCols);
  55.     STDMETHOD(getRWStatus)      (DBROWCOUNT iRow, DB_LORDINAL iCol, OSPRW *prwStatus);
  56.     STDMETHOD(getVariant)       (DBROWCOUNT iRow, DB_LORDINAL iCol, OSPFORMAT format, VARIANT *pVar);
  57.     STDMETHOD(setVariant)       (DBROWCOUNT iRow, DB_LORDINAL iCol, OSPFORMAT format, VARIANT Var);
  58.     STDMETHOD(getLocale)        (BSTR *pbstrLocale);
  59.     STDMETHOD(deleteRows)       (DBROWCOUNT iRow, DBROWCOUNT cRows, DBROWCOUNT *pcRowsDeleted);
  60.     STDMETHOD(insertRows)       (DBROWCOUNT iRow, DBROWCOUNT cRows, DBROWCOUNT *pcRowsInserted);
  61.     STDMETHOD(find)             (DBROWCOUNT iRowStart, DB_LORDINAL iCol, VARIANT val,
  62.                                  OSPFIND findFlags, OSPCOMP compType, DBROWCOUNT *piRowFound);
  63.     STDMETHOD(addOLEDBSimpleProviderListener)(OLEDBSimpleProviderListener *pospIListener);
  64.     STDMETHOD(removeOLEDBSimpleProviderListener)(OLEDBSimpleProviderListener *pospIListener);
  65.     STDMETHOD(getEstimatedRows) (DBROWCOUNT *pcRows);
  66.     STDMETHOD(isAsync)          (BOOL *pbAsync);
  67.     STDMETHOD(stopTransfer)     (void);
  68.     // *** IWorkerEvent methods ***
  69.     STDMETHOD(FireOnDataReady)  (DBROWCOUNT iRow);
  70.     STDMETHOD(FireOnFinished)   (void);
  71.     STDMETHOD(FireOnDatasetChanged)   (void);
  72.     
  73.     // *** IARPSimpleProvider methods ***
  74.     STDMETHOD(Initialize)       (IShellAppManager * psam, IARPEvent *, DWORD dwEnum);
  75.     STDMETHOD(EnumerateItemsAsync)   (void);
  76.     STDMETHOD(Recalculate)      (void);
  77.     STDMETHOD(SetSortCriteria)  (BSTR bstrSortExpr);
  78.     STDMETHOD(SetFilter)        (BSTR bstrFilter);
  79.     STDMETHOD(Sort)             (void);
  80.     STDMETHOD(DoCommand)        (HWND hwndParent, APPCMD appcmd, DBROWCOUNT iRow);
  81.     STDMETHOD(TransferData)     (IARPSimpleProvider * parposp);
  82.     CDataSrc();
  83.     // *** IARPWorker *** (overide)
  84.     STDMETHOD(KillWT)           (void);
  85.     
  86. private:
  87.     virtual ~CDataSrc();
  88.     inline BOOL _IsValidDataRow(DBROWCOUNT iRow);
  89.     inline BOOL _IsValidRow(DBROWCOUNT iRow);
  90.     inline BOOL _IsValidCol(DB_LORDINAL iCol);
  91.     inline BOOL _IsValidCell(DBROWCOUNT iRow, DB_LORDINAL iCol);
  92.     DBROWCOUNT _CalcRows(void);
  93.     DB_LORDINAL _CalcCols(void);
  94.     HRESULT _ApplySortCriteria(BOOL bFireDataSetChanged);
  95.     IAppData * _GetAppData(DBROWCOUNT iRow);
  96.     // NOTE: this is not used to kill the apps enumeration thread!!
  97.     // kills only the thread that get slow appinfo. 
  98.     HRESULT _KillMtxWorkerThread(void);
  99.     HRESULT _EnumAppItems(DWORD dwEnum, LPCWSTR pszCategory);
  100.     DWORD   _ThreadStartProc();
  101.             
  102.     ULONG        _cRef;          // interface reference count
  103.     LOAD_STATE  _loadstate;
  104.     DB_LORDINAL _cCols;         // count of columns
  105.     DBROWCOUNT  _cRows;         // count of rows
  106.     DWORD       _dwEnum;        // items to enumerate (ENUM_*)
  107.     BITBOOL     _fSortDirty: 1; // TRUE: the sort criteria is dirty
  108.     BITBOOL     _fFilterDirty: 1; // TRUE: the sort criteria is dirty
  109.     BITBOOL     _fAppsEnumed : 1; // TRUE if we have already finished enumerating apps
  110.     BITBOOL     _fInEnumOp : 1;   // TRUE if we are in a enumeraion opertion
  111.     IShellAppManager * _psam;
  112.     IARPEvent * _parpevt;
  113.     IMtxArray * _pmtxarray;     // data is stored here
  114.     CComBSTR    _cbstrSort;     // sort string.  contains name of column to sort.
  115.     CComBSTR    _cbstrCategory; // category.  used only for published apps.
  116. };
  117. HRESULT CDataSrc_CreateInstance(REFIID riid, LPVOID * ppvObj);
  118. #endif //DOWNLEVEL_PLATFORM
  119. #endif // _DATASRC_H_