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.

236 lines
6.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: CASYNCLB.CXX
  7. //
  8. // Contents:
  9. //
  10. // Classes: Implements the IAsyncLockBytes class.
  11. //
  12. // Functions:
  13. //
  14. // History: 12-13-95 JoeS (Joe Souza) Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #include <urlint.h>
  18. #include <urlmon.hxx>
  19. #include "casynclb.hxx"
  20. CAsyncLockBytes::CAsyncLockBytes(ILockBytes *pLB) : _CRefs()
  21. {
  22. _cbFillOffset.QuadPart = 0;
  23. _fFillDone = FALSE;
  24. _pLBchain = pLB;
  25. }
  26. STDMETHODIMP CAsyncLockBytes::QueryInterface
  27. (REFIID riid, LPVOID FAR* ppvObj)
  28. {
  29. VDATETHIS(this);
  30. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::QueryInterface\n", this));
  31. HRESULT hresult = NOERROR;
  32. if ( IsEqualIID(riid, IID_IUnknown)
  33. || IsEqualIID(riid, IID_ILockBytes)
  34. )
  35. {
  36. *ppvObj = (ILockBytes *)this;
  37. }
  38. else if (IsEqualIID(riid, IID_IFillLockBytes))
  39. {
  40. *ppvObj = (IFillLockBytes *)this;
  41. }
  42. else
  43. {
  44. *ppvObj = NULL;
  45. hresult = E_NOINTERFACE;
  46. }
  47. if (*ppvObj)
  48. {
  49. AddRef();
  50. if (_pLBchain)
  51. _pLBchain->AddRef();
  52. }
  53. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::QueryInterface\n", this));
  54. return hresult;
  55. }
  56. STDMETHODIMP_(ULONG) CAsyncLockBytes::AddRef(void)
  57. {
  58. VDATETHIS(this);
  59. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::AddRef\n", this));
  60. LONG lRet = ++_CRefs;
  61. if (_pLBchain)
  62. _pLBchain->AddRef();
  63. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::AddRef\n", this));
  64. return lRet;
  65. }
  66. STDMETHODIMP_(ULONG) CAsyncLockBytes::Release(void)
  67. {
  68. VDATETHIS(this);
  69. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::Release\n", this));
  70. UrlMkAssert((_CRefs > 0));
  71. LONG lRet = --_CRefs;
  72. if (_pLBchain)
  73. _pLBchain->Release();
  74. if (_CRefs == 0)
  75. {
  76. delete this;
  77. }
  78. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::Release\n", this));
  79. return lRet;
  80. }
  81. HRESULT CAsyncLockBytes::ReadAt(THIS_ ULARGE_INTEGER ulOffset, VOID HUGEP *pv,
  82. ULONG cb, ULONG FAR *pcbRead)
  83. {
  84. HRESULT hresult = E_FAIL;
  85. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::ReadAt\n", this));
  86. if (_pLBchain)
  87. {
  88. #if 0
  89. while (TRUE)
  90. {
  91. #endif
  92. hresult = _pLBchain->ReadAt(ulOffset, pv, cb, pcbRead);
  93. #if 0
  94. if (hresult != NOERROR)
  95. break;
  96. if (*pcbRead == cb || _fFillDone)
  97. break;
  98. hresult = BlockOnIFillLockBytes(this);
  99. if (hresult != S_OK)
  100. break;
  101. }
  102. #endif
  103. }
  104. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::ReadAt\n", this));
  105. return(hresult);
  106. }
  107. HRESULT CAsyncLockBytes::WriteAt(THIS_ ULARGE_INTEGER ulOffset, VOID const HUGEP *pv,
  108. ULONG cb, ULONG FAR *pcbWritten)
  109. {
  110. HRESULT hresult = E_FAIL;
  111. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::WriteAt\n", this));
  112. if (_pLBchain)
  113. hresult = _pLBchain->WriteAt(ulOffset, pv, cb, pcbWritten);
  114. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::WriteAt\n", this));
  115. return(hresult);
  116. }
  117. HRESULT CAsyncLockBytes::Flush()
  118. {
  119. HRESULT hresult = E_FAIL;
  120. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::Flush\n", this));
  121. if (_pLBchain)
  122. hresult = _pLBchain->Flush();
  123. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::Flush\n", this));
  124. return(hresult);
  125. }
  126. HRESULT CAsyncLockBytes::SetSize(THIS_ ULARGE_INTEGER cb)
  127. {
  128. HRESULT hresult = E_FAIL;
  129. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::SetSize\n", this));
  130. if (_pLBchain)
  131. hresult = _pLBchain->SetSize(cb);
  132. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::SetSize\n", this));
  133. return(hresult);
  134. }
  135. HRESULT CAsyncLockBytes::LockRegion(THIS_ ULARGE_INTEGER libOffset,
  136. ULARGE_INTEGER cb, DWORD dwLockType)
  137. {
  138. HRESULT hresult = E_FAIL;
  139. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::LockRegion\n", this));
  140. if (_pLBchain)
  141. hresult = _pLBchain->LockRegion(libOffset, cb, dwLockType);
  142. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::LockRegion\n", this));
  143. return(hresult);
  144. }
  145. HRESULT CAsyncLockBytes::UnlockRegion(THIS_ ULARGE_INTEGER libOffset,
  146. ULARGE_INTEGER cb, DWORD dwLockType)
  147. {
  148. HRESULT hresult = E_FAIL;
  149. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::UnlockRegion\n", this));
  150. if (_pLBchain)
  151. hresult = _pLBchain->UnlockRegion(libOffset, cb, dwLockType);
  152. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::UnlockRegion\n", this));
  153. return(hresult);
  154. }
  155. HRESULT CAsyncLockBytes::Stat(THIS_ STATSTG FAR *pStatStg, DWORD grfStatFlag)
  156. {
  157. HRESULT hresult = E_FAIL;
  158. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::Stat\n", this));
  159. if (_pLBchain)
  160. hresult = _pLBchain->Stat(pStatStg, grfStatFlag);
  161. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::Stat\n", this));
  162. return(hresult);
  163. }
  164. HRESULT CAsyncLockBytes::FillAppend(void const *pv, ULONG cb, ULONG *pcbWritten)
  165. {
  166. HRESULT hresult = E_FAIL;
  167. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::FillAppend\n", this));
  168. if (!_fFillDone)
  169. {
  170. hresult = WriteAt(_cbFillOffset, pv, cb, pcbWritten);
  171. _cbFillOffset.QuadPart += *pcbWritten;
  172. }
  173. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::FillAppend\n", this));
  174. return(hresult);
  175. }
  176. HRESULT CAsyncLockBytes::Terminate(BOOL bCanceled)
  177. {
  178. UrlMkDebugOut((DEB_ILOCKBYTES, "%p IN CAsyncLockBytes::Terminate\n", this));
  179. _fFillDone = TRUE;
  180. UrlMkDebugOut((DEB_ILOCKBYTES, "%p OUT CAsyncLockBytes::Terminate\n", this));
  181. return(NOERROR);
  182. }