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.

171 lines
4.5 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999.
  5. //
  6. // File: watch.hxx
  7. //
  8. // Contents:
  9. //
  10. // History: 15 Aug 1996 DLee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #pragma once
  14. #include <ocidl.h>
  15. const unsigned cmsNotifySpacing = 1000;
  16. const unsigned cmsStartSpacing = 100;
  17. const unsigned cmsBackoff = 100;
  18. const unsigned cmsSleep = 50;
  19. class CRowsetNotifyWatch : public IRowsetWatchNotify
  20. {
  21. public:
  22. CRowsetNotifyWatch(HWND hwnd) :
  23. _cRef(1),
  24. _hwndNotify(hwnd),
  25. _cmsTicks(GetTickCount() + cmsNotifySpacing),
  26. _cmsSpacing( cmsStartSpacing ),
  27. _fHoldNotifications( FALSE ),
  28. _fIgnore( FALSE ),
  29. _wnLast( 0 )
  30. {
  31. srchDebugOut((DEB_TRACE,"CRowsetNotifyWatch::Construct\n"));
  32. }
  33. ~CRowsetNotifyWatch()
  34. {
  35. srchDebugOut((DEB_TRACE,"CRowsetNotifyWatch::~\n"));
  36. }
  37. // IUnknown methods.
  38. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID *ppiuk)
  39. {
  40. srchDebugOut((DEB_TRACE,"CRowsetNotifyWatch::QI\n"));
  41. *ppiuk = (void **) this; // hold our breath and jump
  42. AddRef();
  43. return S_OK;
  44. }
  45. STDMETHOD_(ULONG, AddRef) (THIS)
  46. {
  47. srchDebugOut((DEB_TRACE,"CRowsetNotifyWatch::AddRef\n"));
  48. return ++_cRef;
  49. }
  50. STDMETHOD_(ULONG, Release) (THIS)
  51. {
  52. srchDebugOut((DEB_TRACE,"CRowsetNotifyWatch::Release\n"));
  53. ULONG tmp = --_cRef;
  54. if ( 0 == _cRef )
  55. delete this;
  56. return tmp;
  57. }
  58. // IRowsetNotifyWatch method
  59. STDMETHOD( OnChange) (THIS_ IRowset* pRowset, DBWATCHNOTIFY changeType)
  60. {
  61. AddRef();
  62. srchDebugOut((DEB_TRACE,"CRowsetNotifyWatch::OnChange Top\n"));
  63. if ( DBWATCHNOTIFY_QUERYDONE != changeType )
  64. {
  65. while ( ( _fHoldNotifications ) ||
  66. ( ( GetTickCount() - _cmsTicks ) < _cmsSpacing ) )
  67. {
  68. if ( ( _fIgnore ) ||
  69. ( 1 == _cRef ) ) // did we die in our sleep?
  70. break;
  71. Sleep( cmsSleep );
  72. }
  73. }
  74. if ( ( !_fIgnore ) &&
  75. ( _cRef > 1 ) ) // did we (the query) die in our sleep?
  76. {
  77. _wnLast = changeType;
  78. PostMessage( _hwndNotify,
  79. wmNotification,
  80. changeType,
  81. (LPARAM) pRowset );
  82. _cmsTicks = GetTickCount();
  83. _cmsSpacing = __min( cmsNotifySpacing,
  84. cmsBackoff + _cmsSpacing );
  85. srchDebugOut(( DEB_TRACE, "CRowsetNotifyWatch::OnChange Blasted\n" ));
  86. }
  87. else
  88. {
  89. srchDebugOut((DEB_TRACE,"CRowsetNotifyWatch::OnChange die\n"));
  90. }
  91. Release();
  92. return S_OK;
  93. }
  94. // private methods
  95. void HoldNotifications( BOOL f )
  96. {
  97. _fHoldNotifications = f;
  98. _cmsTicks = GetTickCount();
  99. }
  100. void IgnoreNotifications( BOOL fIgnore )
  101. { _fIgnore = fIgnore; }
  102. private:
  103. ULONG _cRef;
  104. HWND _hwndNotify;
  105. ULONG _cmsTicks;
  106. ULONG _cmsSpacing;
  107. BOOL _fHoldNotifications;
  108. BOOL _fIgnore;
  109. DBWATCHNOTIFY _wnLast;
  110. };
  111. class CSearchQuery;
  112. class CBookMark;
  113. class CWatchQuery
  114. {
  115. public:
  116. CWatchQuery (CSearchQuery* pSearch, IRowsetScroll* pRowset);
  117. ~CWatchQuery ();
  118. BOOL Ok () const { return _pRowsetWatch != 0; }
  119. void Notify (HWND hwndList, DBWATCHNOTIFY changeType);
  120. void NotifyComplete();
  121. void RowsChanged (HWND hwnd);
  122. void Extend (HWATCHREGION hRegion);
  123. void Move (HWATCHREGION hRegion);
  124. void Shrink (HWATCHREGION hRegion, CBookMark& bmk, ULONG cRows);
  125. HWATCHREGION Handle() { return _hRegion; }
  126. void IgnoreNotifications( BOOL fIgnore )
  127. { _pNotifyWatch->IgnoreNotifications( fIgnore ); }
  128. private:
  129. void ExecuteScript (HWND hwndList, ULONG cChanges, DBROWWATCHCHANGE* aScript);
  130. CSearchQuery* _pClient;
  131. BOOL _fEverGotARowsChanged;
  132. DBWATCHNOTIFY _wnLast;
  133. IConnectionPointContainer *_pContainer;
  134. IConnectionPoint * _pPoint;
  135. DWORD _dwAdviseID;
  136. CRowsetNotifyWatch * _pNotifyWatch;
  137. IRowsetWatchRegion* _pRowsetWatch;
  138. HWATCHREGION _hRegion;
  139. DWORD _mode;
  140. };