event.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 7k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //+-----------------------------------------------------------------------
  2. //
  3. //  event.cpp:  Implementation of the CEventBroker class.
  4. //              This class translates internal ADC/OSP events into
  5. //              appropriate notifications for the external world.
  6. //
  7. //------------------------------------------------------------------------
  8. #include "priv.h"
  9. // Do not build this file if on Win9X or NT4
  10. #ifndef DOWNLEVEL_PLATFORM
  11. #include "event.h"
  12. //#include "dump.h"
  13. // constructor
  14. CEventBroker::CEventBroker(LPWSTR pszQualifier) : _cRef(1)
  15. {
  16.     ASSERT(NULL == _pospl);
  17.     ASSERT(NULL == _pdsl);
  18.     TraceAddRef(CEventBroker, _cRef);
  19.     _cbstrQualifier = SysAllocString(pszQualifier);
  20. }
  21. // destructor
  22. CEventBroker::~CEventBroker()
  23. {
  24.     TraceMsg(TF_OBJLIFE, "(EventBroker) destroying");
  25.     
  26.     SetDataSourceListener(NULL);
  27.     SetOSPListener(NULL);
  28.     if (_cbstrQualifier)
  29.         SysFreeString(_cbstrQualifier);
  30. }
  31. /*--------------------------------------------------------------------
  32. Purpose: IUnknown::QueryInterface
  33. */
  34. STDMETHODIMP CEventBroker::QueryInterface(REFIID riid, LPVOID * ppvObj)
  35. {
  36.     static const QITAB qit[] = {
  37.         QITABENT(CEventBroker, IARPEvent),
  38.         { 0 },
  39.     };
  40.     return QISearch(this, (LPCQITAB)qit, riid, ppvObj);
  41. }
  42. STDMETHODIMP_(ULONG) CEventBroker::AddRef()
  43. {
  44.     ++_cRef;
  45.     TraceAddRef(CEventBroker, _cRef);
  46.     return _cRef;
  47. }
  48. STDMETHODIMP_(ULONG) CEventBroker::Release()
  49. {
  50.     ASSERT(_cRef > 0);
  51.     _cRef--;
  52.     TraceRelease(CEventBroker, _cRef);
  53.     
  54.     if (_cRef > 0)
  55.         return _cRef;
  56.     delete this;
  57.     return 0;
  58. }
  59. /*-------------------------------------------------------------------------
  60. Purpose: IARPEvent::SetDataSourceListener
  61.          Sets the Data Source listener.
  62.          If pdsl is NULL, no notifcations are sent.
  63. */
  64. STDMETHODIMP CEventBroker::SetDataSourceListener(DataSourceListener * pdsl)
  65. {
  66.     // If we've changed/reset the data source listener, make sure we don't
  67.     // think we've fired dataMemberChanged on it yet.
  68.     ATOMICRELEASE(_pdsl);
  69.     _pdsl = pdsl;
  70.     if (_pdsl)
  71.         _pdsl->AddRef();
  72.     return S_OK;
  73. }
  74. /*-------------------------------------------------------------------------
  75. Purpose: IARPEvent::SetOSPListener
  76.          Sets the OSP listener.
  77.          If pospl is NULL, no notifications are sent.
  78. */
  79. STDMETHODIMP CEventBroker::SetOSPListener(OLEDBSimpleProviderListener *pospl)
  80. {
  81.     ATOMICRELEASE(_pospl);
  82.     _pospl = pospl;
  83.     if (_pospl)
  84.         _pospl->AddRef();
  85.         
  86.     return S_OK;
  87. }
  88. /*-------------------------------------------------------------------------
  89. Purpose: IARPEvent::IsOSPListener
  90.          Returns S_OK if the given listener is the current OSP listener.
  91. */
  92. STDMETHODIMP CEventBroker::IsOSPListener(OLEDBSimpleProviderListener *pospl)
  93. {
  94.     return (pospl == _pospl) ? S_OK : S_FALSE;
  95. }
  96. /*-------------------------------------------------------------------------
  97. Purpose: IARPEvent::RowChanged
  98.          Fired when the OSP updated some fields in a row.
  99. */
  100. STDMETHODIMP CEventBroker::RowChanged(DBROWCOUNT iRow)
  101. {
  102.     ASSERT(iRow >= 0);
  103.     
  104.     if (_pospl)
  105.     {
  106.         TraceMsg(TF_DSO, "(CEventBroker) rowChanged %d", iRow);
  107.     
  108.         _pospl->cellChanged(iRow, -1);
  109.     }
  110.     return S_OK;
  111. }
  112. /*-------------------------------------------------------------------------
  113. Purpose: IARPEvent::AboutToDeleteRows
  114.          Fired when the OSP is going to delete some rows.
  115. */
  116. STDMETHODIMP CEventBroker::AboutToDeleteRows(DBROWCOUNT iRowStart, DBROWCOUNT cRows)
  117. {
  118.     ASSERT(iRowStart >= 0);
  119.     ASSERT(cRows > 0);
  120.     
  121.     if (_pospl)
  122.     {
  123.         TraceMsg(TF_DSO, "(CEventBroker) AboutToDeleteRows(%d, %d)", iRowStart, cRows);
  124.     
  125.         _pospl->aboutToDeleteRows(iRowStart, cRows);
  126.     }
  127.     return S_OK;
  128. }
  129. /*-------------------------------------------------------------------------
  130. Purpose: IARPEvent::DeletedRows
  131.          Fired when the OSP has deleted some rows.
  132. */
  133. STDMETHODIMP CEventBroker::DeletedRows(DBROWCOUNT iRowStart, DBROWCOUNT cRows)
  134. {
  135.     ASSERT(iRowStart >= 0);
  136.     ASSERT(cRows > 0);
  137.     
  138.     if (_pospl)
  139.     {
  140.         TraceMsg(TF_DSO, "(CEventBroker) DeletedRows(%d, %d)", iRowStart, cRows);
  141.     
  142.         _pospl->deletedRows(iRowStart, cRows);
  143.     }
  144.     return S_OK;
  145. }
  146. /*-------------------------------------------------------------------------
  147. Purpose: IARPEvent::RowsAvailable
  148.          Fired when the OSP has enumerated some rows.
  149. */
  150. STDMETHODIMP CEventBroker::RowsAvailable(DBROWCOUNT iRowStart, DBROWCOUNT cRows)
  151. {
  152.     ASSERT(iRowStart >= 0);
  153.     ASSERT(cRows > 0);
  154.     
  155.     if (_pospl)
  156.     {
  157.         TraceMsg(TF_DSO, "(CEventBroker) RowsAvailable(%d, %d)", iRowStart, cRows);
  158.         
  159.         _pospl->rowsAvailable(iRowStart, cRows);
  160.     }
  161.     return S_OK;
  162. }
  163. /*-------------------------------------------------------------------------
  164. Purpose: IARPEvent::LoadCompleted
  165.          Fired when the OSP has finished enumerating its data.
  166. */
  167. STDMETHODIMP CEventBroker::LoadCompleted(void)
  168. {
  169.     if (_pospl)
  170.     {
  171.         TraceMsg(TF_DSO, "(CEventBroker) LoadCompleted");
  172.         _pospl->transferComplete(OSPXFER_COMPLETE);
  173.     }
  174.     return S_OK;
  175. }
  176. /*-------------------------------------------------------------------------
  177. Purpose: IARPEvent::LoadAborted
  178.          Fired when the OSP has aborted its enumeration.
  179. */
  180. STDMETHODIMP CEventBroker::LoadAborted(void)
  181. {
  182.     // Right now, any error results in not returning an SP object,
  183.     // therefore we should not fire transfer complete.
  184.     if (_pospl)
  185.     {
  186.         TraceMsg(TF_DSO, "(CEventBroker) LoadAborted");
  187.     
  188.         _pospl->transferComplete(OSPXFER_ABORT);
  189.     }
  190.     return S_OK;
  191. }
  192. /*-------------------------------------------------------------------------
  193. Purpose: IARPEvent::DataSetChanged
  194.          Fired when the OSP's data set has changed (resorted, refiltered, etc.)
  195. */
  196. STDMETHODIMP CEventBroker::DataSetChanged(void)
  197. {
  198.     if (_pdsl)
  199.     {
  200.         TraceMsg(TF_DSO, "(CEventBroker) DataSetChanged");
  201.         
  202.         _pdsl->dataMemberChanged(_cbstrQualifier);
  203.     }
  204.     return S_OK;
  205. }
  206. /*----------------------------------------------------------
  207. Purpose: Create-instance function for CARPEvent
  208. */
  209. HRESULT CARPEvent_CreateInstance(REFIID riid, LPVOID * ppvObj, LPWSTR pszQualifier)
  210. {
  211.     HRESULT hres = E_OUTOFMEMORY;
  212.     *ppvObj = NULL;
  213.     
  214.     CEventBroker * pObj = new CEventBroker(pszQualifier);
  215.     if (pObj)
  216.     {
  217.         hres = pObj->QueryInterface(riid, ppvObj);
  218.         pObj->Release();
  219.     }
  220.     return hres;
  221. }
  222. #endif //DOWNLEVEL_PLATFORM