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.

476 lines
15 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: wdocfile.hxx
  7. //
  8. // Contents: CWrappedDocFile class header
  9. //
  10. // Classes: CWrappedDocFile
  11. //
  12. // History: 06-Jan-92 DrewB Created
  13. //
  14. //---------------------------------------------------------------
  15. #ifndef __WDOCFILE_HXX__
  16. #define __WDOCFILE_HXX__
  17. #include <dfmsp.hxx>
  18. #include <dfbasis.hxx>
  19. #include <pdocfile.hxx>
  20. #include <ulist.hxx>
  21. #include <entry.hxx>
  22. #include <tset.hxx>
  23. #include <freelist.hxx>
  24. #include <tstream.hxx>
  25. class PDocFileIterator;
  26. class CPubDocFile;
  27. class CDFBasis;
  28. //+--------------------------------------------------------------
  29. //
  30. // Class: CWrappedDocFile
  31. //
  32. // Purpose: Wrapped DocFile object for transactioning
  33. //
  34. // Interface: See below
  35. //
  36. // History: 06-Jan-92 DrewB Created
  37. //
  38. //---------------------------------------------------------------
  39. class CWrappedDocFile : public PDocFile, public PTSetMember,
  40. public CMallocBased
  41. {
  42. public:
  43. inline void *operator new(size_t size, IMalloc * const pMalloc);
  44. inline void *operator new(size_t size,
  45. CDFBasis * const pdfb);
  46. inline void ReturnToReserve(CDFBasis * const pdfb);
  47. inline static SCODE Reserve(UINT cItems, CDFBasis * const pdfb);
  48. inline static void Unreserve(UINT cItems, CDFBasis * const pdfb);
  49. CWrappedDocFile(CDfName const *pdfn,
  50. DFLUID dl,
  51. DFLAGS const df,
  52. CDFBasis *pdfb,
  53. CPubDocFile *ppubdf);
  54. SCODE Init(PDocFile *pdfBase);
  55. #ifdef COORD
  56. SCODE InitPub(CPubDocFile *ppubdf);
  57. #endif
  58. ~CWrappedDocFile(void);
  59. // PDocFile
  60. inline void DecRef(void);
  61. inline void AddRef () { PBasicEntry::AddRef(); };
  62. inline void Release () { PBasicEntry::Release(); };
  63. SCODE DestroyEntry(CDfName const *dfnName,
  64. BOOL fClean);
  65. SCODE RenameEntry(CDfName const *dfnName,
  66. CDfName const *dfnNewName);
  67. SCODE GetClass(CLSID *pclsid);
  68. SCODE SetClass(REFCLSID clsid);
  69. SCODE GetStateBits(DWORD *pgrfStateBits);
  70. SCODE SetStateBits(DWORD grfStateBits, DWORD grfMask);
  71. SCODE CreateDocFile(CDfName const *pdfnName,
  72. DFLAGS const df,
  73. DFLUID luidSet,
  74. PDocFile **ppdfDocFile);
  75. inline SCODE CreateDocFile(CDfName const *pdfnName,
  76. DFLAGS const df,
  77. DFLUID luidSet,
  78. DWORD const dwType,
  79. PDocFile **ppdfDocFile)
  80. { return CreateDocFile(pdfnName, df, luidSet, ppdfDocFile); }
  81. SCODE GetDocFile(CDfName const *pdfnName,
  82. DFLAGS const df,
  83. PDocFile **ppdfDocFile);
  84. inline SCODE GetDocFile(CDfName const *pdfnName,
  85. DFLAGS const df,
  86. DWORD const dwType,
  87. PDocFile **ppdfDocFile)
  88. { return GetDocFile(pdfnName, df, ppdfDocFile); }
  89. inline void ReturnDocFile(CWrappedDocFile *pdf);
  90. SCODE CreateStream(CDfName const *pdfnName,
  91. DFLAGS const df,
  92. DFLUID luidSet,
  93. PSStream **ppsstStream);
  94. inline SCODE CreateStream(CDfName const *pdfnName,
  95. DFLAGS const df,
  96. DFLUID luidSet,
  97. DWORD const dwType,
  98. PSStream **ppsstStream)
  99. { return CreateStream(pdfnName, df, luidSet, ppsstStream); }
  100. SCODE GetStream(CDfName const *pdfnName,
  101. DFLAGS const df,
  102. PSStream **ppsstStream);
  103. inline SCODE GetStream(CDfName const *pdfnName,
  104. DFLAGS const df,
  105. DWORD const dwType,
  106. PSStream **ppsstStream)
  107. { return GetStream(pdfnName, df, ppsstStream); }
  108. inline void ReturnStream(CTransactedStream *pstm);
  109. SCODE FindGreaterEntry(CDfName const *pdfnKey,
  110. SIterBuffer *pib,
  111. STATSTGW *pstat);
  112. SCODE StatEntry(CDfName const *pdfn,
  113. SIterBuffer *pib,
  114. STATSTGW *pstat);
  115. SCODE BeginCommitFromChild(CUpdateList &ulChanged,
  116. DWORD const dwFlags,
  117. CWrappedDocFile *pdfChild);
  118. void EndCommitFromChild(DFLAGS const df,
  119. CWrappedDocFile *pdfChild);
  120. SCODE IsEntry(CDfName const *dfnName,
  121. SEntryBuffer *peb);
  122. SCODE DeleteContents(void);
  123. // PTSetMember
  124. SCODE BeginCommit(DWORD const dwFlags);
  125. void EndCommit(DFLAGS const df);
  126. void Revert(void);
  127. #ifdef LARGE_STREAMS
  128. void GetCommitInfo(ULONGLONG *pulRet1, ULONGLONG *pulRet2);
  129. #else
  130. void GetCommitInfo(ULONG *pulRet1, ULONG *pulRet2);
  131. #endif
  132. // PTimeEntry
  133. SCODE GetTime(WHICHTIME wt, TIME_T *ptm);
  134. SCODE SetTime(WHICHTIME wt, TIME_T tm);
  135. SCODE GetAllTimes(TIME_T *patm, TIME_T *pmtm, TIME_T *pctm);
  136. SCODE SetAllTimes(TIME_T atm, TIME_T mtm, TIME_T ctm);
  137. inline CWrappedDocFile *GetReservedDocfile(CDfName const *pdfn,
  138. DFLUID dl,
  139. DFLAGS const df,
  140. CPubDocFile *ppubdf);
  141. inline CTransactedStream *GetReservedStream(CDfName const *pdfn,
  142. DFLUID dl,
  143. DFLAGS df
  144. );
  145. // Internal
  146. SCODE SetBase(PDocFile *pdf);
  147. inline PDocFile *GetBase(void);
  148. inline CFreeList *GetDocfileFreelist(void);
  149. inline CFreeList *GetStreamFreelist(void);
  150. inline void SetClean(void);
  151. inline void SetDirty(UINT fDirty);
  152. inline UINT GetDirty(void) const;
  153. inline CUpdateList *GetUpdateList(void);
  154. private:
  155. SCODE SetInitialState(PDocFile *pdfBase);
  156. void RevertUpdate(CUpdate *pud);
  157. DFLAGS _df; // Transactioning flags
  158. CBasedDocFilePtr _pdfParent, _pdfBase;
  159. CUpdateList _ulChanged;
  160. CUpdateList _ulChangedHolder;
  161. CUpdateList _ulChangedOld;
  162. CTSSet _tssDeletedHolder;
  163. BOOL _fBeginCommit;
  164. CTransactedTimeEntry _tten;
  165. CBasedPubDocFilePtr _ppubdf;
  166. UINT _fDirty;
  167. CLSID _clsid;
  168. DWORD _grfStateBits;
  169. CBasedDFBasisPtr const _pdfb;
  170. };
  171. //+--------------------------------------------------------------
  172. //
  173. // Member: CWrappedDocFile::operator new, public
  174. //
  175. // Synopsis: Unreserved object allocator
  176. //
  177. // Arguments: [size] -- byte count to allocate
  178. // [pMalloc] -- allocator
  179. //
  180. // History: 25-May-93 AlexT Created
  181. //
  182. //---------------------------------------------------------------
  183. inline void *CWrappedDocFile::operator new(size_t size,
  184. IMalloc * const pMalloc)
  185. {
  186. return(CMallocBased::operator new(size, pMalloc));
  187. }
  188. //+--------------------------------------------------------------
  189. //
  190. // Member: CWrappedDocFile::operator new, public
  191. //
  192. // Synopsis: Reserved object allocator
  193. //
  194. // Arguments: [size] -- byte count to allocate
  195. // [pdfb] -- basis
  196. //
  197. // History: 25-May-93 AlexT Created
  198. //
  199. //---------------------------------------------------------------
  200. inline void *CWrappedDocFile::operator new(size_t size, CDFBasis * const pdfb)
  201. {
  202. olAssert(size == sizeof(CWrappedDocFile));
  203. return pdfb->GetFreeList(CDFB_WRAPPEDDOCFILE)->GetReserved();
  204. }
  205. //+--------------------------------------------------------------
  206. //
  207. // Member: CWrappedDocFile::ReturnToReserve, public
  208. //
  209. // Synopsis: Reserved object return
  210. //
  211. // Arguments: [pdfb] -- basis
  212. //
  213. // History: 25-May-93 AlexT Created
  214. //
  215. //---------------------------------------------------------------
  216. inline void CWrappedDocFile::ReturnToReserve(CDFBasis * const pdfb)
  217. {
  218. CWrappedDocFile::~CWrappedDocFile();
  219. pdfb->GetFreeList(CDFB_WRAPPEDDOCFILE)->ReturnToReserve(this);
  220. }
  221. //+--------------------------------------------------------------
  222. //
  223. // Member: CWrappedDocFile::Reserve, public
  224. //
  225. // Synopsis: Reserve instances
  226. //
  227. // Arguments: [cItems] -- count of items
  228. // [pdfb] -- basis
  229. //
  230. // History: 25-May-93 AlexT Created
  231. //
  232. //---------------------------------------------------------------
  233. inline SCODE CWrappedDocFile::Reserve(UINT cItems, CDFBasis * const pdfb)
  234. {
  235. return pdfb->Reserve(cItems, CDFB_WRAPPEDDOCFILE);
  236. }
  237. //+--------------------------------------------------------------
  238. //
  239. // Member: CWrappedDocFile::Unreserve, public
  240. //
  241. // Synopsis: Unreserve instances
  242. //
  243. // Arguments: [cItems] -- count of items
  244. // [pdfb] -- basis
  245. //
  246. // History: 25-May-93 AlexT Created
  247. //
  248. //---------------------------------------------------------------
  249. inline void CWrappedDocFile::Unreserve(UINT cItems, CDFBasis * const pdfb)
  250. {
  251. pdfb->Unreserve(cItems, CDFB_WRAPPEDDOCFILE);
  252. }
  253. //+--------------------------------------------------------------
  254. //
  255. // Member: CWrappedDocFile::GetBase, public
  256. //
  257. // Synopsis: Returns base; used for debug checks
  258. //
  259. // History: 15-Sep-92 AlexT Created
  260. //
  261. //---------------------------------------------------------------
  262. inline PDocFile *CWrappedDocFile::GetBase(void)
  263. {
  264. return BP_TO_P(PDocFile *, _pdfBase);
  265. }
  266. //+---------------------------------------------------------------------------
  267. //
  268. // Member: CWrappedDocFile::GetReservedDocfile, public
  269. //
  270. // Synopsis: Returns a previously reserved object
  271. //
  272. // History: 09-Nov-92 DrewB Created
  273. //
  274. //----------------------------------------------------------------------------
  275. inline CWrappedDocFile *CWrappedDocFile::GetReservedDocfile(
  276. CDfName const *pdfn,
  277. DFLUID dl,
  278. DFLAGS const df,
  279. CPubDocFile *ppubdf)
  280. {
  281. return new(_pdfb)
  282. CWrappedDocFile(pdfn, dl, df,
  283. _pdfb, ppubdf);
  284. }
  285. //+---------------------------------------------------------------------------
  286. //
  287. // Member: CWrappedDocFile::GetReservedStream, public
  288. //
  289. // Synopsis: Returns a previously reserved object
  290. //
  291. // History: 09-Nov-92 DrewB Created
  292. //
  293. //----------------------------------------------------------------------------
  294. inline CTransactedStream *CWrappedDocFile::GetReservedStream(
  295. CDfName const *pdfn,
  296. DFLUID dl,
  297. DFLAGS df
  298. )
  299. {
  300. CDFBasis * pdfb = BP_TO_P(CDFBasis *, _pdfb);
  301. return new(pdfb)
  302. CTransactedStream(pdfn, dl, df,
  303. #ifdef USE_NOSCRATCH
  304. pdfb->GetBaseMultiStream(),
  305. #endif
  306. pdfb->GetScratch());
  307. }
  308. //+---------------------------------------------------------------------------
  309. //
  310. // Member: CWrappedDocFile::SetClean, public
  311. //
  312. // Synopsis: Resets dirty flags
  313. //
  314. // History: 10-Nov-92 DrewB Created
  315. //
  316. //----------------------------------------------------------------------------
  317. inline void CWrappedDocFile::SetClean(void)
  318. {
  319. _fDirty = 0;
  320. }
  321. //+---------------------------------------------------------------------------
  322. //
  323. // Member: CWrappedDocFile::SetDirty, public
  324. //
  325. // Synopsis: Sets dirty flags
  326. //
  327. // History: 10-Nov-92 DrewB Created
  328. //
  329. //----------------------------------------------------------------------------
  330. inline void CWrappedDocFile::SetDirty(UINT fDirty)
  331. {
  332. _fDirty |= fDirty;
  333. }
  334. //+---------------------------------------------------------------------------
  335. //
  336. // Member: CWrappedDocFile::GetDirty, public
  337. //
  338. // Synopsis: Returns the dirty flags
  339. //
  340. // History: 25-Nov-92 DrewB Created
  341. //
  342. //----------------------------------------------------------------------------
  343. inline UINT CWrappedDocFile::GetDirty(void) const
  344. {
  345. return _fDirty;
  346. }
  347. //+---------------------------------------------------------------------------
  348. //
  349. // Member: CWrappedDocFile::DecRef, public
  350. //
  351. // Synopsis: Decrements the ref count
  352. //
  353. // History: 23-Nov-92 DrewB Created
  354. //
  355. //----------------------------------------------------------------------------
  356. inline void CWrappedDocFile::DecRef(void)
  357. {
  358. AtomicDec(&_cReferences);
  359. }
  360. //+---------------------------------------------------------------------------
  361. //
  362. // Member: CWrappedDocFile::GetUpdateList, public
  363. //
  364. // Synopsis: Returns a pointer to the current update list
  365. //
  366. // History: 12-Apr-93 DrewB Created
  367. //
  368. //----------------------------------------------------------------------------
  369. CUpdateList *CWrappedDocFile::GetUpdateList(void)
  370. {
  371. return &_ulChanged;
  372. }
  373. //+---------------------------------------------------------------------------
  374. //
  375. // Member: CWrappedDocFile::ReturnDocFile, public
  376. //
  377. // Synopsis: Removes a docfile from the XS and returns it to the freelist
  378. //
  379. // Arguments: [pdf] - Docfile
  380. //
  381. // History: 23-Nov-92 DrewB Created
  382. //
  383. //----------------------------------------------------------------------------
  384. inline void CWrappedDocFile::ReturnDocFile(CWrappedDocFile *pdf)
  385. {
  386. olDebugOut((DEB_ITRACE, "In CWrappedDocFile::ReturnDocFile:%p(%p)\n",
  387. this, pdf));
  388. _ppubdf->RemoveXSMember(pdf);
  389. // Force ref count to zero without freeing memory
  390. pdf->DecRef();
  391. pdf->ReturnToReserve(BP_TO_P(CDFBasis *, _pdfb));
  392. olDebugOut((DEB_ITRACE, "Out CWrappedDocFile::ReturnDocFile\n"));
  393. }
  394. //+---------------------------------------------------------------------------
  395. //
  396. // Member: CWrappedDocFile::ReturnStream, public
  397. //
  398. // Synopsis: Removes a stream from the XS and returns it to the freelist
  399. //
  400. // Arguments: [pstm] - Stream
  401. //
  402. // History: 23-Nov-92 DrewB Created
  403. //
  404. //----------------------------------------------------------------------------
  405. inline void CWrappedDocFile::ReturnStream(CTransactedStream *pstm)
  406. {
  407. olDebugOut((DEB_ITRACE, "In CWrappedDocFile::ReturnStream:%p(%p)\n",
  408. this, pstm));
  409. _ppubdf->RemoveXSMember(pstm);
  410. // Force ref count to zero without freeing memory
  411. pstm->DecRef();
  412. pstm->ReturnToReserve(BP_TO_P(CDFBasis *, _pdfb));
  413. olDebugOut((DEB_ITRACE, "Out CWrappedDocFile::ReturnStream\n"));
  414. }
  415. #endif // __WDOCFILE_HXX__