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.

321 lines
8.3 KiB

  1. //---------------------------------------------------------------------------
  2. // Stream.cpp : Stream implementation
  3. //
  4. // Copyright (c) 1996 Microsoft Corporation, All Rights Reserved
  5. // Developed by Sheridan Software Systems, Inc.
  6. //---------------------------------------------------------------------------
  7. #include "stdafx.h"
  8. #ifndef VD_DONT_IMPLEMENT_ISTREAM
  9. #include "Notifier.h"
  10. #include "RSColumn.h"
  11. #include "RSSource.h"
  12. #include "CursMain.h"
  13. #include "ColUpdat.h"
  14. #include "CursPos.h"
  15. #include "EntryID.h"
  16. #include "fastguid.h"
  17. #include "Stream.h"
  18. #include "resource.h"
  19. SZTHISFILE
  20. static const GUID IID_IStreamEx = {0xf74e27fc, 0x5a3, 0x11d0, {0x91, 0x95, 0x0, 0xa0, 0x24, 0x7b, 0x73, 0x5b}};
  21. //=--------------------------------------------------------------------------=
  22. // CVDStream - Constructor
  23. //
  24. CVDStream::CVDStream()
  25. {
  26. m_dwRefCount = 1;
  27. m_pEntryIDData = NULL;
  28. m_pStream = NULL;
  29. m_pResourceDLL = NULL;
  30. #ifdef _DEBUG
  31. g_cVDStreamCreated++;
  32. #endif
  33. }
  34. //=--------------------------------------------------------------------------=
  35. // ~CVDStream - Destructor
  36. //
  37. CVDStream::~CVDStream()
  38. {
  39. m_pEntryIDData->Release();
  40. if (m_pStream)
  41. m_pStream->Release();
  42. #ifdef _DEBUG
  43. g_cVDStreamDestroyed++;
  44. #endif
  45. }
  46. //=--------------------------------------------------------------------------=
  47. // Create - Create stream object
  48. //=--------------------------------------------------------------------------=
  49. // This function creates and initializes a new stream object
  50. //
  51. // Parameters:
  52. // pEntryIDData - [in] backwards pointer to CVDEntryIDData object
  53. // pStream - [in] data stream pointer
  54. // ppVDStream - [out] a pointer in which to return pointer to
  55. // viaduct stream object
  56. // pResourceDLL - [in] a pointer which keeps track of resource DLL
  57. //
  58. // Output:
  59. // HRESULT - S_OK if successful
  60. // E_OUTOFMEMORY not enough memory to create object
  61. //
  62. // Notes:
  63. //
  64. HRESULT CVDStream::Create(CVDEntryIDData * pEntryIDData, IStream * pStream, CVDStream ** ppVDStream,
  65. CVDResourceDLL * pResourceDLL)
  66. {
  67. ASSERT_POINTER(pEntryIDData, CVDEntryIDData)
  68. ASSERT_POINTER(pStream, IStream*)
  69. ASSERT_POINTER(ppVDStream, CVDStream*)
  70. if (!pStream || !ppVDStream)
  71. {
  72. VDSetErrorInfo(IDS_ERR_INVALIDARG, IID_IEntryID, pResourceDLL);
  73. return E_INVALIDARG;
  74. }
  75. *ppVDStream = NULL;
  76. CVDStream * pVDStream = new CVDStream();
  77. if (!pStream)
  78. {
  79. VDSetErrorInfo(IDS_ERR_OUTOFMEMORY, IID_IEntryID, pResourceDLL);
  80. return E_OUTOFMEMORY;
  81. }
  82. pEntryIDData->AddRef();
  83. pStream->AddRef();
  84. pVDStream->m_pEntryIDData = pEntryIDData;
  85. pVDStream->m_pStream = pStream;
  86. pVDStream->m_pResourceDLL = pResourceDLL;
  87. *ppVDStream = pVDStream;
  88. return S_OK;
  89. }
  90. //=--------------------------------------------------------------------------=
  91. // IUnknown Methods
  92. //=--------------------------------------------------------------------------=
  93. //=--------------------------------------------------------------------------=
  94. // IUnknown QueryInterface
  95. //
  96. HRESULT CVDStream::QueryInterface(REFIID riid, void **ppvObjOut)
  97. {
  98. ASSERT_POINTER(ppvObjOut, IUnknown*)
  99. if (!ppvObjOut)
  100. return E_INVALIDARG;
  101. *ppvObjOut = NULL;
  102. switch (riid.Data1)
  103. {
  104. QI_INTERFACE_SUPPORTED(this, IUnknown);
  105. QI_INTERFACE_SUPPORTED(this, IStream);
  106. QI_INTERFACE_SUPPORTED(this, IStreamEx);
  107. }
  108. if (NULL == *ppvObjOut)
  109. return E_NOINTERFACE;
  110. AddRef();
  111. return S_OK;
  112. }
  113. //=--------------------------------------------------------------------------=
  114. // IUnknown AddRef
  115. //
  116. ULONG CVDStream::AddRef(void)
  117. {
  118. return ++m_dwRefCount;
  119. }
  120. //=--------------------------------------------------------------------------=
  121. // IUnknown Release
  122. //
  123. ULONG CVDStream::Release(void)
  124. {
  125. if (1 > --m_dwRefCount)
  126. {
  127. delete this;
  128. return 0;
  129. }
  130. return m_dwRefCount;
  131. }
  132. //=--------------------------------------------------------------------------=
  133. // IStream Methods
  134. //=--------------------------------------------------------------------------=
  135. //=--------------------------------------------------------------------------=
  136. // IStream Read
  137. //
  138. HRESULT CVDStream::Read(void *pv, ULONG cb, ULONG *pcbRead)
  139. {
  140. return m_pStream->Read(pv, cb, pcbRead);
  141. }
  142. //=--------------------------------------------------------------------------=
  143. // IStream Write
  144. //
  145. HRESULT CVDStream::Write(const void *pv, ULONG cb, ULONG *pcbWritten)
  146. {
  147. HRESULT hr = m_pStream->Write(pv, cb, pcbWritten);
  148. if (SUCCEEDED(hr))
  149. m_pEntryIDData->SetDirty(TRUE);
  150. return hr;
  151. }
  152. //=--------------------------------------------------------------------------=
  153. // IStream Seek
  154. //
  155. HRESULT CVDStream::Seek(LARGE_INTEGER dlibMove, DWORD dwOrigin, ULARGE_INTEGER *plibNewPosition)
  156. {
  157. return m_pStream->Seek(dlibMove, dwOrigin, plibNewPosition);
  158. }
  159. //=--------------------------------------------------------------------------=
  160. // IStream SetSize
  161. //
  162. HRESULT CVDStream::SetSize(ULARGE_INTEGER libNewSize)
  163. {
  164. return m_pStream->SetSize(libNewSize);
  165. }
  166. //=--------------------------------------------------------------------------=
  167. // IStream CopyTo
  168. //
  169. HRESULT CVDStream::CopyTo(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbRead, ULARGE_INTEGER *pcbWritten)
  170. {
  171. IStreamEx * pStreamEx;
  172. HRESULT hr = pstm->QueryInterface(IID_IStreamEx, (void**)&pStreamEx);
  173. if (SUCCEEDED(hr))
  174. {
  175. hr = pStreamEx->CopyFrom(m_pStream, cb, pcbWritten, pcbRead);
  176. pStreamEx->Release();
  177. }
  178. else
  179. hr = m_pStream->CopyTo(pstm, cb, pcbRead, pcbWritten);
  180. return hr;
  181. }
  182. //=--------------------------------------------------------------------------=
  183. // IStream Commit
  184. //
  185. HRESULT CVDStream::Commit(DWORD grfCommitFlags)
  186. {
  187. return m_pEntryIDData->Commit();
  188. }
  189. //=--------------------------------------------------------------------------=
  190. // IStream Revert
  191. //
  192. HRESULT CVDStream::Revert(void)
  193. {
  194. return m_pStream->Revert();
  195. }
  196. //=--------------------------------------------------------------------------=
  197. // IStream LockRegion
  198. //
  199. HRESULT CVDStream::LockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  200. {
  201. return m_pStream->LockRegion(libOffset, cb, dwLockType);
  202. }
  203. //=--------------------------------------------------------------------------=
  204. // IStream UnlockRegion
  205. //
  206. HRESULT CVDStream::UnlockRegion(ULARGE_INTEGER libOffset, ULARGE_INTEGER cb, DWORD dwLockType)
  207. {
  208. return m_pStream->UnlockRegion(libOffset, cb, dwLockType);
  209. }
  210. //=--------------------------------------------------------------------------=
  211. // IStream Stat
  212. //
  213. HRESULT CVDStream::Stat(STATSTG *pstatstg, DWORD grfStatFlag)
  214. {
  215. return m_pStream->Stat(pstatstg, grfStatFlag);
  216. }
  217. //=--------------------------------------------------------------------------=
  218. // IStream Clone
  219. //
  220. HRESULT CVDStream::Clone(IStream **ppstm)
  221. {
  222. ASSERT_POINTER(ppstm, IStream*)
  223. // check pointer
  224. if (!ppstm)
  225. {
  226. VDSetErrorInfo(IDS_ERR_INVALIDARG, IID_IEntryID, m_pResourceDLL);
  227. return E_INVALIDARG;
  228. }
  229. // init out parameter
  230. *ppstm = NULL;
  231. IStream * pStream;
  232. // clone stream
  233. HRESULT hr = m_pStream->Clone(&pStream);
  234. if (FAILED(hr))
  235. {
  236. VDSetErrorInfo(IDS_ERR_CLONEFAILED, IID_IEntryID, m_pResourceDLL);
  237. return hr;
  238. }
  239. CVDStream * pVDStream;
  240. // create viaduct stream object
  241. hr = CVDStream::Create(m_pEntryIDData, pStream, &pVDStream, m_pResourceDLL);
  242. // release reference on clone
  243. pStream->Release();
  244. if (FAILED(hr))
  245. return hr;
  246. *ppstm = pVDStream;
  247. return S_OK;
  248. }
  249. //=--------------------------------------------------------------------------=
  250. // IStreamEx CopyFrom
  251. //
  252. HRESULT CVDStream::CopyFrom(IStream *pstm, ULARGE_INTEGER cb, ULARGE_INTEGER *pcbWritten, ULARGE_INTEGER *pcbRead)
  253. {
  254. HRESULT hr = pstm->CopyTo(m_pStream, cb, pcbRead, pcbWritten);
  255. if (SUCCEEDED(hr))
  256. m_pEntryIDData->SetDirty(TRUE);
  257. return hr;
  258. }
  259. #endif //VD_DONT_IMPLEMENT_ISTREAM