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.

274 lines
5.7 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name :
  4. txnsup.h
  5. Abstract:
  6. Defines class for implementation of transaction routines SetAbort
  7. and SetComplete.
  8. Author:
  9. Andy Morrison ( andymorr ) April-2001
  10. Revision History:
  11. --*/
  12. #ifndef _TXNSUP_H
  13. #define _TXNSUP_H
  14. #include "asptxn.h"
  15. class CASPObjectContext : public IASPObjectContextImpl, public CFTMImplementation, public ITransactionStatus
  16. {
  17. private:
  18. LONG m_cRefs;
  19. BOOL m_fAborted;
  20. public:
  21. CASPObjectContext() {
  22. m_cRefs = 1;
  23. m_fAborted = FALSE;
  24. CDispatch::Init(IID_IASPObjectContext, Glob(pITypeLibTxn));
  25. };
  26. //Non-delegating object IUnknown
  27. STDMETHODIMP QueryInterface(REFIID, PPVOID);
  28. STDMETHODIMP_(ULONG) AddRef(void);
  29. STDMETHODIMP_(ULONG) Release(void);
  30. // IASPObjectContext
  31. STDMETHOD(SetAbort)();
  32. STDMETHOD(SetComplete)();
  33. // ITransactionStatus
  34. STDMETHODIMP SetTransactionStatus(HRESULT hr);
  35. STDMETHODIMP GetTransactionStatus(HRESULT *pHrStatus);
  36. BOOL FAborted() { return m_fAborted; };
  37. };
  38. inline HRESULT CASPObjectContext::SetAbort()
  39. {
  40. HRESULT hr = E_NOTIMPL;
  41. IObjectContext * pContext = NULL;
  42. hr = GetObjectContext(&pContext);
  43. if( SUCCEEDED(hr) )
  44. {
  45. hr = pContext->SetAbort();
  46. pContext->Release();
  47. m_fAborted = TRUE;
  48. }
  49. return hr;
  50. }
  51. inline HRESULT CASPObjectContext::SetComplete()
  52. {
  53. HRESULT hr = E_NOTIMPL;
  54. IObjectContext * pContext = NULL;
  55. hr = GetObjectContext(&pContext);
  56. if( SUCCEEDED(hr) )
  57. {
  58. hr = pContext->SetComplete();
  59. pContext->Release();
  60. m_fAborted = FALSE;
  61. }
  62. return hr;
  63. }
  64. inline HRESULT CASPObjectContext::SetTransactionStatus(HRESULT hr)
  65. {
  66. // if m_fAborted is already set, this indicates that the
  67. // script set it and we should not reset it.
  68. if (m_fAborted == TRUE);
  69. else if (hr == XACT_E_ABORTED) {
  70. m_fAborted = TRUE;
  71. }
  72. else if (hr == S_OK) {
  73. m_fAborted = FALSE;
  74. }
  75. return S_OK;
  76. }
  77. inline HRESULT CASPObjectContext::GetTransactionStatus(HRESULT *pHrResult)
  78. {
  79. if (m_fAborted == TRUE) {
  80. *pHrResult = XACT_E_ABORTED;
  81. }
  82. else {
  83. *pHrResult = S_OK;
  84. }
  85. return S_OK;
  86. }
  87. /*===================================================================
  88. CASPObjectContext::QueryInterface
  89. CASPObjectContext::AddRef
  90. CASPObjectContext::Release
  91. IUnknown members for CASPObjectContext object.
  92. ===================================================================*/
  93. inline HRESULT CASPObjectContext::QueryInterface
  94. (
  95. REFIID riid,
  96. PPVOID ppv
  97. )
  98. {
  99. *ppv = NULL;
  100. /*
  101. * The only calls for IUnknown are either in a nonaggregated
  102. * case or when created in an aggregation, so in either case
  103. * always return our IUnknown for IID_IUnknown.
  104. */
  105. if (IID_IUnknown == riid
  106. || IID_IDispatch == riid
  107. || IID_IASPObjectContext == riid)
  108. *ppv = static_cast<IASPObjectContext *>(this);
  109. else if (IID_ITransactionStatus == riid)
  110. *ppv = static_cast<ITransactionStatus *>(this);
  111. else if (IID_IMarshal == riid) {
  112. *ppv = static_cast<IMarshal *>(this);
  113. }
  114. //AddRef any interface we'll return.
  115. if (NULL != *ppv) {
  116. ((LPUNKNOWN)*ppv)->AddRef();
  117. return S_OK;
  118. }
  119. return ResultFromScode(E_NOINTERFACE);
  120. }
  121. inline STDMETHODIMP_(ULONG) CASPObjectContext::AddRef(void) {
  122. return InterlockedIncrement(&m_cRefs);
  123. }
  124. inline STDMETHODIMP_(ULONG) CASPObjectContext::Release(void) {
  125. LONG cRefs = InterlockedDecrement(&m_cRefs);
  126. if (cRefs)
  127. return cRefs;
  128. delete this;
  129. return 0;
  130. }
  131. class CASPDummyObjectContext : public IASPObjectContextImpl, public CFTMImplementation
  132. {
  133. private:
  134. LONG m_cRefs;
  135. public:
  136. CASPDummyObjectContext() { m_cRefs = 1; };
  137. //Non-delegating object IUnknown
  138. STDMETHODIMP QueryInterface(REFIID, PPVOID);
  139. STDMETHODIMP_(ULONG) AddRef(void);
  140. STDMETHODIMP_(ULONG) Release(void);
  141. // IASPObjectContext
  142. STDMETHOD(SetAbort)();
  143. STDMETHOD(SetComplete)();
  144. };
  145. /*===================================================================
  146. CASPDummyObjectContext::QueryInterface
  147. CASPDummyObjectContext::AddRef
  148. CASPDummyObjectContext::Release
  149. IUnknown members for CASPDummyObjectContext object.
  150. ===================================================================*/
  151. inline HRESULT CASPDummyObjectContext::QueryInterface
  152. (
  153. REFIID riid,
  154. PPVOID ppv
  155. )
  156. {
  157. *ppv = NULL;
  158. /*
  159. * The only calls for IUnknown are either in a nonaggregated
  160. * case or when created in an aggregation, so in either case
  161. * always return our IUnknown for IID_IUnknown.
  162. */
  163. if (IID_IUnknown == riid
  164. || IID_IDispatch == riid
  165. || IID_IASPObjectContext == riid)
  166. *ppv = static_cast<CASPDummyObjectContext *>(this);
  167. else if (IID_IMarshal == riid) {
  168. *ppv = static_cast<IMarshal *>(this);
  169. }
  170. //AddRef any interface we'll return.
  171. if (NULL != *ppv) {
  172. ((LPUNKNOWN)*ppv)->AddRef();
  173. return S_OK;
  174. }
  175. return ResultFromScode(E_NOINTERFACE);
  176. }
  177. inline STDMETHODIMP_(ULONG) CASPDummyObjectContext::AddRef(void) {
  178. return InterlockedIncrement(&m_cRefs);
  179. }
  180. inline STDMETHODIMP_(ULONG) CASPDummyObjectContext::Release(void) {
  181. LONG cRefs = InterlockedDecrement(&m_cRefs);
  182. if (cRefs)
  183. return cRefs;
  184. delete this;
  185. return 0;
  186. }
  187. inline HRESULT CASPDummyObjectContext::SetAbort()
  188. {
  189. ExceptionId(IID_IASPObjectContext, IDE_OBJECTCONTEXT, IDE_OBJECTCONTEXT_NOT_TRANSACTED);
  190. return E_FAIL;
  191. }
  192. inline HRESULT CASPDummyObjectContext::SetComplete()
  193. {
  194. ExceptionId(IID_IASPObjectContext, IDE_OBJECTCONTEXT, IDE_OBJECTCONTEXT_NOT_TRANSACTED);
  195. return E_FAIL;
  196. }
  197. #endif