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.

354 lines
8.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: tstream.hxx
  7. //
  8. // Contents: Transacted stream class definition
  9. //
  10. // Classes: CTransactedStream - Transacted stream object
  11. // CDeltaList - Delta list object
  12. //
  13. // History: 23-Jan-92 PhilipLa Created.
  14. //
  15. //--------------------------------------------------------------------------
  16. #ifndef __TSTREAM_HXX__
  17. #define __TSTREAM_HXX__
  18. #include <msf.hxx>
  19. #include <tset.hxx>
  20. #include <psstream.hxx>
  21. #include <dfbasis.hxx>
  22. #include <freelist.hxx>
  23. #include <dl.hxx>
  24. //+-------------------------------------------------------------------------
  25. //
  26. // Class: CTransactedStream (ts)
  27. //
  28. // Purpose: Transacted stream object
  29. //
  30. // Interface:
  31. //
  32. // History: 21-Jan-92 PhilipLa Created.
  33. //
  34. // Notes:
  35. //
  36. //--------------------------------------------------------------------------
  37. class CTransactedStream : public PSStream, public PTSetMember,
  38. public CMallocBased
  39. {
  40. public:
  41. inline void *operator new(size_t size, IMalloc * const pMalloc);
  42. inline void *operator new(size_t size, CDFBasis * const pdfb);
  43. inline void ReturnToReserve(CDFBasis * const pdfb);
  44. inline static SCODE Reserve(UINT cItems, CDFBasis * const pdfb);
  45. inline static void Unreserve(UINT cItems, CDFBasis * const pdfb);
  46. CTransactedStream(CDfName const *pdfn,
  47. DFLUID dl,
  48. DFLAGS df,
  49. #ifdef USE_NOSCRATCH
  50. CMStream *pms,
  51. #endif
  52. CMStream *pmsScratch);
  53. SCODE Init(PSStream *pssBase);
  54. ~CTransactedStream();
  55. inline void DecRef(VOID);
  56. inline void AddRef () { PBasicEntry::AddRef(); };
  57. inline void Release () { PBasicEntry::Release(); };
  58. SCODE ReadAt(
  59. #ifdef LARGE_STREAMS
  60. ULONGLONG ulOffset,
  61. #else
  62. ULONG ulOffset,
  63. #endif
  64. VOID *pBuffer,
  65. ULONG ulCount,
  66. ULONG STACKBASED *pulRetval);
  67. SCODE WriteAt(
  68. #ifdef LARGE_STREAMS
  69. ULONGLONG ulOffset,
  70. #else
  71. ULONG ulOffset,
  72. #endif
  73. VOID const *pBuffer,
  74. ULONG ulCount,
  75. ULONG STACKBASED *pulRetval);
  76. #ifdef LARGE_STREAMS
  77. SCODE SetSize(ULONGLONG ulNewSize);
  78. void GetSize(ULONGLONG *pulSize);
  79. #else
  80. SCODE SetSize(ULONG ulNewSize);
  81. void GetSize(ULONG *pulSize);
  82. #endif
  83. SCODE BeginCommitFromChild(
  84. #ifdef LARGE_STREAMS
  85. ULONGLONG ulSize,
  86. #else
  87. ULONG ulSize,
  88. #endif
  89. CDeltaList *pDelta,
  90. CTransactedStream *pstChild);
  91. void EndCommitFromChild(DFLAGS df,
  92. CTransactedStream *pstChild);
  93. CDeltaList * GetDeltaList(void);
  94. //Inherited from PTSetMember:
  95. SCODE BeginCommit(DWORD const dwFlags);
  96. void EndCommit(DFLAGS const df);
  97. void Revert(void);
  98. #ifdef LARGE_STREAMS
  99. void GetCommitInfo(ULONGLONG *pulRet1, ULONGLONG *pulRet2);
  100. #else
  101. void GetCommitInfo(ULONG *pulRet1, ULONG *pulRet2);
  102. #endif
  103. inline void EmptyCache ();
  104. // PBasicEntry
  105. SCODE SetBase(PSStream *psst);
  106. inline PSStream* GetBase();
  107. inline void SetClean(void);
  108. inline void SetDirty(UINT fDirty);
  109. inline UINT GetDirty(void) const;
  110. private:
  111. SCODE PartialWrite(
  112. ULONG ulBasePos,
  113. ULONG ulDirtyPos,
  114. BYTE const HUGEP *pb,
  115. USHORT offset,
  116. USHORT uLen);
  117. SCODE SetInitialState(PSStream *pssBase);
  118. #ifdef LARGE_STREAMS
  119. ULONGLONG _ulSize;
  120. #else
  121. ULONG _ulSize;
  122. #endif
  123. CBasedSStreamPtr _pssBase;
  124. SECT _sectLastUsed;
  125. CDeltaList _dl;
  126. DFLAGS _df;
  127. UINT _fDirty;
  128. BOOL _fBeginCommit;
  129. CBasedDeltaListPtr _pdlOld;
  130. #ifdef LARGE_STREAMS
  131. ULONGLONG _ulOldSize;
  132. #else
  133. ULONG _ulOldSize;
  134. #endif
  135. #ifdef INDINST
  136. DFSIGNATURE _sigOldBase;
  137. DFSIGNATURE _sigOldSelf;
  138. #endif
  139. };
  140. //+--------------------------------------------------------------
  141. //
  142. // Member: CTransactedStream::operator new, public
  143. //
  144. // Synopsis: Unreserved object allocator
  145. //
  146. // Arguments: [size] -- byte count to allocate
  147. // [pMalloc] -- allocator
  148. //
  149. // History: 25-May-93 AlexT Created
  150. //
  151. //---------------------------------------------------------------
  152. inline void *CTransactedStream::operator new(size_t size,
  153. IMalloc * const pMalloc)
  154. {
  155. return(CMallocBased::operator new(size, pMalloc));
  156. }
  157. //+--------------------------------------------------------------
  158. //
  159. // Member: CTransactedStream::operator new, public
  160. //
  161. // Synopsis: Reserved object allocator
  162. //
  163. // Arguments: [size] -- byte count to allocate
  164. // [pdfb] -- basis
  165. //
  166. // History: 25-May-93 AlexT Created
  167. //
  168. //---------------------------------------------------------------
  169. inline void *CTransactedStream::operator new(size_t size, CDFBasis * const pdfb)
  170. {
  171. olAssert(size == sizeof(CTransactedStream));
  172. return pdfb->GetFreeList(CDFB_TRANSACTEDSTREAM)->GetReserved();
  173. }
  174. //+--------------------------------------------------------------
  175. //
  176. // Member: CTransactedStream::ReturnToReserve, public
  177. //
  178. // Synopsis: Reserved object return
  179. //
  180. // Arguments: [pdfb] -- basis
  181. //
  182. // History: 25-May-93 AlexT Created
  183. //
  184. //---------------------------------------------------------------
  185. inline void CTransactedStream::ReturnToReserve(CDFBasis * const pdfb)
  186. {
  187. CTransactedStream::~CTransactedStream();
  188. pdfb->GetFreeList(CDFB_TRANSACTEDSTREAM)->ReturnToReserve(this);
  189. }
  190. //+--------------------------------------------------------------
  191. //
  192. // Member: CTransactedStream::Reserve, public
  193. //
  194. // Synopsis: Reserve instances
  195. //
  196. // Arguments: [cItems] -- count of items
  197. // [pdfb] -- basis
  198. //
  199. // History: 25-May-93 AlexT Created
  200. //
  201. //---------------------------------------------------------------
  202. inline SCODE CTransactedStream::Reserve(UINT cItems, CDFBasis * const pdfb)
  203. {
  204. return pdfb->Reserve(cItems, CDFB_TRANSACTEDSTREAM);
  205. }
  206. //+--------------------------------------------------------------
  207. //
  208. // Member: CTransactedStream::Unreserve, public
  209. //
  210. // Synopsis: Unreserve instances
  211. //
  212. // Arguments: [cItems] -- count of items
  213. // [pdfb] -- basis
  214. //
  215. // History: 25-May-93 AlexT Created
  216. //
  217. //---------------------------------------------------------------
  218. inline void CTransactedStream::Unreserve(UINT cItems, CDFBasis * const pdfb)
  219. {
  220. pdfb->Unreserve(cItems, CDFB_TRANSACTEDSTREAM);
  221. }
  222. //+--------------------------------------------------------------
  223. //
  224. // Member: CTransactedStream::GetBase, public
  225. //
  226. // Synopsis: Returns base; used for debug checks
  227. //
  228. // History: 15-Sep-92 AlexT Created
  229. //
  230. //---------------------------------------------------------------
  231. inline PSStream *CTransactedStream::GetBase()
  232. {
  233. return BP_TO_P(PSStream *, _pssBase);
  234. }
  235. //+---------------------------------------------------------------------------
  236. //
  237. // Member: CTransactedStream::SetClean, public
  238. //
  239. // Synopsis: Resets dirty flags
  240. //
  241. // History: 11-Nov-92 DrewB Created
  242. //
  243. //----------------------------------------------------------------------------
  244. inline void CTransactedStream::SetClean(void)
  245. {
  246. _fDirty = 0;
  247. }
  248. //+---------------------------------------------------------------------------
  249. //
  250. // Member: CTransactedStream::SetDirty, public
  251. //
  252. // Synopsis: Sets dirty flags
  253. //
  254. // History: 11-Nov-92 DrewB Created
  255. //
  256. //----------------------------------------------------------------------------
  257. inline void CTransactedStream::SetDirty(UINT fDirty)
  258. {
  259. _fDirty |= fDirty;
  260. }
  261. //+---------------------------------------------------------------------------
  262. //
  263. // Member: CTransactedStream::DecRef, public
  264. //
  265. // Synopsis: Decrements the ref count
  266. //
  267. // History: 25-Nov-92 DrewB Created
  268. //
  269. //----------------------------------------------------------------------------
  270. inline void CTransactedStream::DecRef(void)
  271. {
  272. AtomicDec(&_cReferences);
  273. }
  274. //+---------------------------------------------------------------------------
  275. //
  276. // Member: CTransactedStream::GetDirty, public
  277. //
  278. // Synopsis: Returns the dirty flags
  279. //
  280. // History: 17-Dec-92 DrewB Created
  281. //
  282. //----------------------------------------------------------------------------
  283. inline UINT CTransactedStream::GetDirty(void) const
  284. {
  285. return _fDirty;
  286. }
  287. //+---------------------------------------------------------------------------
  288. //
  289. // Member: CTransactedStream::EmptyCache, public
  290. //
  291. // Synopsis: Empties the stream cache
  292. //
  293. // History: 27-Jul-1999 HenryLee Created
  294. //
  295. //----------------------------------------------------------------------------
  296. inline void CTransactedStream::EmptyCache (void)
  297. {
  298. PSStream * const pssBase = _pssBase;
  299. if (pssBase != NULL)
  300. pssBase->EmptyCache();
  301. }
  302. #endif //__TSTREAM_HXX__