Leaked source code of windows server 2003
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.

216 lines
6.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1998.
  5. //
  6. // File: rownotfy.hxx
  7. //
  8. // Contents: Rowset notification connection points
  9. //
  10. // Classes: CRowsetNotification
  11. // CRowsetAsynchNotification
  12. //
  13. // History: 16 Feb 1998 AlanW Created from conpt.hxx
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include <conpt.hxx>
  18. //+-------------------------------------------------------------------------
  19. //
  20. // Class: CRowsetNotification
  21. //
  22. // Purpose: Implements IConnectionPoint for IRowsetNotify
  23. //
  24. // Interface: IConnectionPoint
  25. //
  26. // Notes:
  27. //
  28. //--------------------------------------------------------------------------
  29. class CRowsetNotification : public CConnectionPointBase
  30. {
  31. public:
  32. CRowsetNotification ( ) :
  33. CConnectionPointBase( IID_IRowsetNotify )
  34. {
  35. }
  36. //
  37. // IRowsetNotify methods.
  38. //
  39. STDMETHOD(OnFieldChange) ( IRowset * pRowset,
  40. HROW hRow,
  41. DBORDINAL cColumns,
  42. DBORDINAL rgColumns[],
  43. DBREASON eReason,
  44. DBEVENTPHASE ePhase,
  45. BOOL fCantDeny );
  46. STDMETHOD(OnRowChange) ( IRowset * pRowset,
  47. DBCOUNTITEM cRows,
  48. const HROW rghRows[],
  49. DBREASON eReason,
  50. DBEVENTPHASE ePhase,
  51. BOOL fCantDeny );
  52. STDMETHOD(OnRowsetChange) ( IRowset * pRowset,
  53. DBREASON eReason,
  54. DBEVENTPHASE ePhase,
  55. BOOL fCantDeny );
  56. //
  57. // Connection point management
  58. //
  59. virtual void AddConnectionPoints(CConnectionPointContainer * pCPC)
  60. {
  61. SetContainer( pCPC );
  62. pCPC->AddConnectionPoint( _iidSink, this );
  63. }
  64. virtual void StopNotifications(void)
  65. {
  66. Disconnect();
  67. }
  68. BOOL IsNotifyActive(void)
  69. {
  70. return GetAdviseCount() != 0;
  71. }
  72. private:
  73. BOOL DoRowsetChangeCallout ( CEnumConnectionsLite & Enum,
  74. IRowset * pRowset,
  75. DBREASON eReason,
  76. DBEVENTPHASE ePhase,
  77. BOOL fCantDeny );
  78. };
  79. class PQuery;
  80. //+-------------------------------------------------------------------------
  81. //
  82. // Class: CRowsetAsynchNotification
  83. //
  84. // Purpose: Implements IConnectionPoint for IRowsetNotify, IDBAsynchNotify,
  85. // IRowsetWatchNotify
  86. //
  87. // Interface: IConnectionPoint
  88. //
  89. // Notes:
  90. //
  91. //--------------------------------------------------------------------------
  92. class CRowsetAsynchNotification : public CRowsetNotification
  93. {
  94. public:
  95. // Sleep timeouts, in msec.
  96. enum {
  97. defNotificationSleepDuration = 100,
  98. #if CIDBG == 1 // for checked builds, allow a longer timeout for stress
  99. defNotifyThreadTerminateTimeout = 60000
  100. #else
  101. defNotifyThreadTerminateTimeout = 10000
  102. #endif
  103. };
  104. CRowsetAsynchNotification (PQuery & query,
  105. ULONG hCursor,
  106. IRowset * pRowset,
  107. CCIOleDBError & ErrorObject,
  108. BOOL fWatch);
  109. ~CRowsetAsynchNotification ( );
  110. STDMETHOD_(ULONG, AddRef) (THIS);
  111. STDMETHOD_(ULONG, Release) (THIS);
  112. //
  113. // Connection point management
  114. //
  115. inline void AddConnectionPoints(CConnectionPointContainer * pCPC);
  116. void StopNotifications(void);
  117. private:
  118. static DWORD _NotifyThread( CRowsetAsynchNotification *self );
  119. DWORD _DoNotifications(void);
  120. BOOL _DoAsynchNotification(void);
  121. BOOL _DoWatchNotification(void);
  122. void _StartNotifyThread(void);
  123. void _EndNotifyThread(void);
  124. static void AdviseHelper( PVOID pHelperConext,
  125. CConnectionPointBase * pConnPt,
  126. CConnectionContext * pConnCtx );
  127. static void UnadviseHelper( PVOID pHelperConext,
  128. CConnectionPointBase * pConnPt,
  129. CConnectionContext * pConnCtx,
  130. CReleasableLock & lock );
  131. BOOL _fDoWatch; // if TRUE, do watch notification
  132. BOOL _fPopulationComplete; // if TRUE, rowset population is done
  133. ULONG _cAdvise; // number of active advises
  134. CConnectionPointBase _AsynchConnectionPoint;
  135. CConnectionPointBase _WatchConnectionPoint;
  136. PQuery & _query;
  137. ULONG _hCursor; // A handle to the table cursor
  138. IRowset * const _pRowset;
  139. HANDLE _threadNotify;
  140. DWORD _threadNotifyId;
  141. CEventSem _evtEndNotifyThread;
  142. };
  143. //+-------------------------------------------------------------------------
  144. //
  145. // Method: CRowsetAsynchNotification::AddConnectionPoints, public
  146. //
  147. // Synopsis: Sets up linkages between the connection point container
  148. // and all the connection points
  149. //
  150. // Arguments: [pCPC] - a pointer to the connection point container
  151. //
  152. // History: 16 Feb 1998 Alanw
  153. //
  154. //--------------------------------------------------------------------------
  155. void CRowsetAsynchNotification::AddConnectionPoints(
  156. CConnectionPointContainer * pCPC)
  157. {
  158. CRowsetNotification::SetContainer( pCPC );
  159. pCPC->AddConnectionPoint( _iidSink, (CRowsetNotification* )this );
  160. _AsynchConnectionPoint.SetContainer( pCPC );
  161. _AsynchConnectionPoint.SetAdviseHelper( &AdviseHelper, this );
  162. _AsynchConnectionPoint.SetUnadviseHelper( &UnadviseHelper, this );
  163. pCPC->AddConnectionPoint( IID_IDBAsynchNotify,
  164. &_AsynchConnectionPoint );
  165. if ( _fDoWatch )
  166. {
  167. _WatchConnectionPoint.SetContainer( pCPC );
  168. _WatchConnectionPoint.SetAdviseHelper( &AdviseHelper, this );
  169. _WatchConnectionPoint.SetUnadviseHelper( &UnadviseHelper, this );
  170. pCPC->AddConnectionPoint( IID_IRowsetWatchNotify,
  171. &_WatchConnectionPoint );
  172. }
  173. }