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.

190 lines
3.4 KiB

  1. #include "shellprv.h"
  2. #pragma hdrstop
  3. #include "subdata.h"
  4. ///////////////////////////////////////////////////////////////////////////////
  5. //
  6. ///////////////////////////////////////////////////////////////////////////////
  7. BOOL CSubData::Init(CSubDataProvider* pSDProv, SUBDATACB fctCB, PVOID pvData)
  8. {
  9. _pSDProv = pSDProv;
  10. _fctCB = fctCB;
  11. _pvData = pvData;
  12. #ifdef DEBUG
  13. ASSERT(!_fInited);
  14. _fInited = TRUE;
  15. #endif
  16. return TRUE;
  17. }
  18. BOOL CSubData::InitStatic(STATICSUBDATACB fctStaticCB, PVOID pvData)
  19. {
  20. _fStatic = TRUE;
  21. _fctStaticCB = fctStaticCB;
  22. _pvData = pvData;
  23. #ifdef DEBUG
  24. ASSERT(!_fInited);
  25. _fInited = TRUE;
  26. #endif
  27. return TRUE;
  28. }
  29. BOOL CSubData::InitExpiration(DWORD cTick)
  30. {
  31. ASSERT(_fInited);
  32. _cTickExpiration = cTick;
  33. return TRUE;
  34. }
  35. BOOL CSubData::Update()
  36. {
  37. ASSERT(_fInited);
  38. BOOL fNeedUpdate = FALSE;
  39. BOOL fRet = TRUE;
  40. if (!_fHoldUpdate)
  41. {
  42. // Check if we need to update the info?
  43. if (_IsValid())
  44. {
  45. // Did we at least update once?
  46. if (!_GetTickLastUpdate())
  47. {
  48. // No
  49. fNeedUpdate = TRUE;
  50. }
  51. else
  52. {
  53. // Is the information expired?
  54. if (_IsExpired())
  55. {
  56. // Yes
  57. fNeedUpdate = TRUE;
  58. }
  59. }
  60. }
  61. if (!_IsValid() || fNeedUpdate)
  62. {
  63. _fInvalid = FALSE;
  64. fRet = _Call();
  65. }
  66. // TBDTBD: in DEBUG_PARANOID do call anyway to see if accurate
  67. }
  68. return fRet;
  69. }
  70. void CSubData::HoldUpdates()
  71. {
  72. ASSERT(_fInited);
  73. _fHoldUpdate = TRUE;
  74. }
  75. void CSubData::ResumeUpdates()
  76. {
  77. ASSERT(_fInited);
  78. _fHoldUpdate = FALSE;
  79. }
  80. void CSubData::Invalidate()
  81. {
  82. _fInvalid = TRUE;
  83. }
  84. CSubData::CSubData() : _cTickExpiration(EXPIRATION_NEVER)
  85. {}
  86. ///////////////////////////////////////////////////////////////////////////////
  87. //
  88. ///////////////////////////////////////////////////////////////////////////////
  89. BOOL CSubData::_Call()
  90. {
  91. // TBDTBD: Getsystemtime for stats
  92. BOOL fRet = TRUE;
  93. if (!_fStatic)
  94. {
  95. if (_fctCB)
  96. {
  97. // Calling with the CSubDataProvider ptr the passed in
  98. // CSubDataProvider's member fct
  99. fRet = (_pSDProv->*_fctCB)(_GetDataPtr());
  100. }
  101. }
  102. else
  103. {
  104. if (_fctStaticCB)
  105. {
  106. fRet = _fctStaticCB(_GetDataPtr());
  107. }
  108. }
  109. _SetTickLastUpdate(GetTickCount());
  110. return fRet;
  111. }
  112. void CSubData::_SetTickLastUpdate(DWORD dwTick)
  113. {
  114. _dwTickLast = dwTick;
  115. }
  116. DWORD CSubData::_GetTickLastUpdate()
  117. {
  118. return _dwTickLast;
  119. }
  120. DWORD* CSubData::_GetTickLastUpdatePtr()
  121. {
  122. return &_dwTickLast;
  123. }
  124. PVOID CSubData::_GetDataPtr()
  125. {
  126. ASSERT(_pvData);
  127. return _pvData;
  128. }
  129. void CSubData::_SetDataPtr(PVOID pvData)
  130. {
  131. _pvData = pvData;
  132. }
  133. BOOL CSubData::_IsExpired()
  134. {
  135. BOOL fExpired = FALSE;
  136. DWORD dwTickCurrent = GetTickCount();
  137. // Is the information expired? Check also for the wrapping case.
  138. if ((EXPIRATION_NEVER != _cTickExpiration) && ((_GetTickLastUpdate() > dwTickCurrent) ||
  139. ((dwTickCurrent - _GetTickLastUpdate()) > _cTickExpiration)))
  140. {
  141. // Yes
  142. fExpired = TRUE;
  143. }
  144. return fExpired;
  145. }
  146. BOOL CSubData::_IsValid()
  147. {
  148. return !_fInvalid;
  149. }