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.

167 lines
5.3 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: dfxact.cxx
  7. //
  8. // Contents: CDocFile transactioning methods
  9. //
  10. // History: 22-Jan-92 DrewB Created
  11. //
  12. //---------------------------------------------------------------
  13. #include <dfhead.cxx>
  14. #pragma hdrstop
  15. //+--------------------------------------------------------------
  16. //
  17. // Member: CDocFile::BeginCommitFromChild, public
  18. //
  19. // Synopsis: Start two-phase commit, requested by child
  20. //
  21. // Arguments: [ulChanged] - Update list
  22. // [dwFlags] - Flags controlling commit
  23. // [pdfChild] - Child object
  24. //
  25. // Returns: Appropriate status code
  26. //
  27. // History: 04-Nov-91 DrewB Created
  28. //
  29. //---------------------------------------------------------------
  30. SCODE CDocFile::BeginCommitFromChild(CUpdateList &ulChanged,
  31. DWORD const dwFlags,
  32. CWrappedDocFile *pdfChild)
  33. {
  34. SCODE sc;
  35. TIME_T tm;
  36. olDebugOut((DEB_ITRACE, "In CDocFile::BeginCommitFromChild:%p("
  37. "%p, %lX, %p)\n", this, ulChanged.GetHead(), dwFlags,
  38. pdfChild));
  39. UNREFERENCED_PARM(dwFlags);
  40. // Copy-on-write will back these changes out if they fail
  41. if (pdfChild->GetDirty() & DIRTY_CREATETIME)
  42. {
  43. olVerSucc(pdfChild->GetTime(WT_CREATION, &tm));
  44. olChk(SetTime(WT_CREATION, tm));
  45. }
  46. if (pdfChild->GetDirty() & DIRTY_MODIFYTIME)
  47. {
  48. olVerSucc(pdfChild->GetTime(WT_MODIFICATION, &tm));
  49. olChk(SetTime(WT_MODIFICATION, tm));
  50. }
  51. if (pdfChild->GetDirty() & DIRTY_ACCESSTIME)
  52. {
  53. olVerSucc(pdfChild->GetTime(WT_ACCESS, &tm));
  54. olChk(SetTime(WT_ACCESS, tm));
  55. }
  56. if (pdfChild->GetDirty() & DIRTY_CLASS)
  57. {
  58. CLSID clsid;
  59. olVerSucc(pdfChild->GetClass(&clsid));
  60. olChk(SetClass(clsid));
  61. }
  62. if (pdfChild->GetDirty() & DIRTY_STATEBITS)
  63. {
  64. DWORD grfStateBits;
  65. olVerSucc(pdfChild->GetStateBits(&grfStateBits));
  66. olChk(SetStateBits(grfStateBits, 0xffffffff));
  67. }
  68. _ulChangedHolder = ulChanged;
  69. sc = ApplyChanges(ulChanged);
  70. olDebugOut((DEB_ITRACE, "Out CDocFile::BeginCommitFromChild\n"));
  71. EH_Err:
  72. return sc;
  73. }
  74. //+--------------------------------------------------------------
  75. //
  76. // Member: CDocFile::EndCommitFromChild
  77. //
  78. // Synopsis: Ends two-phase commit, requested by child
  79. //
  80. // Arguments: [df] - COMMIT/ABORT
  81. // [pdfChild] - Child object
  82. //
  83. // History: 07-Nov-91 DrewB Created
  84. //
  85. //---------------------------------------------------------------
  86. void CDocFile::EndCommitFromChild(DFLAGS const df,
  87. CWrappedDocFile *pdfChild)
  88. {
  89. CUpdate *pud;
  90. olDebugOut((DEB_ITRACE, "In CDocFile::EndCommitFromChild:%p(%X, %p)\n",
  91. this, df, pdfChild));
  92. UNREFERENCED_PARM(pdfChild);
  93. if (P_COMMIT(df))
  94. {
  95. // Finalize updates
  96. for (pud = _ulChangedHolder.GetHead(); pud; pud = pud->GetNext())
  97. if (pud->IsCreate())
  98. // Remove reference to child's XSM so that list destruction
  99. // won't free it
  100. pud->SetXSM(NULL);
  101. _ulChangedHolder.Empty();
  102. }
  103. else
  104. {
  105. for (pud = _ulChangedHolder.GetTail(); pud; pud = pud->GetPrev())
  106. if (pud->IsCreate())
  107. {
  108. // We need to do two things:
  109. //
  110. // Break any SetBase links that might have been created
  111. //
  112. // Return newly created objects to the creators so
  113. // that they can be returned to the preallocation
  114. // pool
  115. if ((pud->GetFlags() & (ULF_TYPEFLAGS & STGTY_REAL)) ==
  116. STGTY_STORAGE)
  117. {
  118. CWrappedDocFile *pwdf = (CWrappedDocFile *)pud->GetXSM();
  119. CDocFile *pddf;
  120. if (pwdf != NULL &&
  121. (pddf = (CDocFile *)pwdf->GetBase()) != NULL)
  122. {
  123. // AddRef so SetBase won't free memory
  124. pddf->AddRef();
  125. pwdf->SetBase(NULL);
  126. ReturnDocFile(pddf);
  127. }
  128. }
  129. else
  130. {
  131. CTransactedStream *pwstm = (CTransactedStream *)pud->
  132. GetXSM();
  133. CDirectStream *pdstm;
  134. olAssert((pud->GetFlags() & (ULF_TYPEFLAGS & STGTY_REAL))
  135. == STGTY_STREAM);
  136. if (pwstm != NULL &&
  137. (pdstm = (CDirectStream *)pwstm->GetBase()) != NULL)
  138. {
  139. // AddRef so SetBase won't free memory
  140. pdstm->AddRef();
  141. pwstm->SetBase(NULL);
  142. ReturnStream(pdstm);
  143. }
  144. }
  145. }
  146. _ulChangedHolder.Unlink();
  147. }
  148. olDebugOut((DEB_ITRACE, "Out CDocFile::EndCommitFromChild\n"));
  149. }