Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

282 lines
6.4 KiB

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