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.

178 lines
4.5 KiB

  1. //+--------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1992.
  5. //
  6. // File: context.cxx
  7. //
  8. // Contents: CPerContext implementation
  9. //
  10. // History: 14-Aug-92 DrewB Created
  11. //
  12. //---------------------------------------------------------------
  13. #include <exphead.cxx>
  14. #pragma hdrstop
  15. #include <lock.hxx>
  16. //+--------------------------------------------------------------
  17. //
  18. // Member: CPerContext::~CPerContext, public
  19. //
  20. // Synopsis: Releases internal objects
  21. //
  22. // History: 14-Aug-92 DrewB Created
  23. //
  24. //---------------------------------------------------------------
  25. #ifdef CODESEGMENTS
  26. #pragma code_seg(SEG_CPerContext_1CPerContext)
  27. #endif
  28. CPerContext::~CPerContext(void)
  29. {
  30. #ifndef ASYNC
  31. //In the ASYNC case, the Close() happens in the Release method.
  32. if (_plkbBase != NULL)
  33. Close();
  34. #endif
  35. if (_pgc)
  36. {
  37. _pgc->Remove(this);
  38. _pgc->Release();
  39. }
  40. #ifdef ASYNC
  41. if (_hNotificationEvent != INVALID_HANDLE_VALUE)
  42. {
  43. CloseHandle(_hNotificationEvent);
  44. _hNotificationEvent = INVALID_HANDLE_VALUE;
  45. }
  46. #endif
  47. }
  48. //+---------------------------------------------------------------------------
  49. //
  50. // Member: CPerContext::Close, public
  51. //
  52. // Synopsis: Closes the ILockBytes for this context
  53. //
  54. // History: 09-Apr-93 DrewB Created
  55. //
  56. //----------------------------------------------------------------------------
  57. #ifdef CODESEGMENTS
  58. #pragma code_seg(SEG_CPerContext_Close)
  59. #endif
  60. void CPerContext::Close(void)
  61. {
  62. if (_ulOpenLock && _pgc)
  63. ReleaseOpen(_plkbOriginal, _pgc->GetOpenLockFlags(), _ulOpenLock);
  64. _plkbBase->Release();
  65. _pfstDirty->Release();
  66. _plkbOriginal->Release();
  67. _plkbBase = NULL;
  68. _pfstDirty = NULL;
  69. _plkbOriginal = NULL;
  70. #ifdef ASYNC
  71. if (_pfi != NULL)
  72. {
  73. _pfi->Release();
  74. _pfi = NULL;
  75. }
  76. #endif
  77. }
  78. #ifdef MULTIHEAP
  79. //+--------------------------------------------------------------
  80. //
  81. // Method: CSafeMultiHeap::CSafeMultiHeap
  82. //
  83. // Purpose: allows restoration of heap with methods calling "delete this"
  84. //
  85. // History: 29-Nov-95 HenryLee Created
  86. //
  87. //---------------------------------------------------------------
  88. CSafeMultiHeap::CSafeMultiHeap(CPerContext *ppc)
  89. {
  90. _pSmAllocator = &g_smAllocator;
  91. ppc->SetAllocatorState (&_ppcPrev, _pSmAllocator);
  92. }
  93. //+--------------------------------------------------------------
  94. //
  95. // Method: CSafeMultiHeap::~CSafeMultiHeap
  96. //
  97. // Purpose: allows restoration of heap with methods calling "delete this"
  98. //
  99. // History: 29-Nov-95 HenryLee Created
  100. //
  101. //---------------------------------------------------------------
  102. CSafeMultiHeap::~CSafeMultiHeap()
  103. {
  104. if (_ppcPrev != NULL)
  105. _ppcPrev->SetAllocatorState(NULL, _pSmAllocator);
  106. else
  107. _pSmAllocator->SetState(NULL, NULL, 0, NULL, NULL);
  108. }
  109. #endif // MULTIHEAP
  110. #ifdef ASYNC
  111. //+---------------------------------------------------------------------------
  112. //
  113. // Member: CPerContext::InitNotificationEvent, public
  114. //
  115. // Returns: Appropriate status code
  116. //
  117. // History: 17-Apr-96 PhilipLa Created
  118. //
  119. //----------------------------------------------------------------------------
  120. SCODE CPerContext::InitNotificationEvent(ILockBytes *plkbBase)
  121. {
  122. SCODE sc;
  123. TCHAR atcEventName[CONTEXT_MUTEX_NAME_LENGTH];
  124. olAssert(_pgc != NULL);
  125. if (_hNotificationEvent != INVALID_HANDLE_VALUE)
  126. {
  127. //Already initialized, ok to exit with no error.
  128. return S_OK;
  129. }
  130. if (plkbBase != NULL)
  131. {
  132. //We need to check to see if we're _really_ doing async or not.
  133. IFileLockBytes *pfl;
  134. if (SUCCEEDED(sc = plkbBase->QueryInterface(IID_IFileLockBytes,
  135. (void **)&pfl)))
  136. {
  137. pfl->Release();
  138. if (((CFileStream *)plkbBase)->GetContextPointer() == NULL)
  139. {
  140. //We aren't doing async, so we don't need a notification event.
  141. return E_NOINTERFACE;
  142. }
  143. }
  144. else
  145. return sc;
  146. _pgc->GetEventName(atcEventName);
  147. _hNotificationEvent = CreateEventT(NULL, //No security
  148. TRUE,
  149. FALSE,
  150. atcEventName);
  151. if (_hNotificationEvent == NULL)
  152. {
  153. _hNotificationEvent = INVALID_HANDLE_VALUE;
  154. return Win32ErrorToScode(GetLastError());
  155. }
  156. }
  157. return S_OK;
  158. }
  159. #endif