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.

220 lines
4.8 KiB

  1. //******************************************************************************
  2. //
  3. // Copyright (c) 1999-2000, Microsoft Corporation, All rights reserved
  4. //
  5. //*****************************************************************************
  6. #include "precomp.h"
  7. #include <wbemint.h>
  8. #include "delivrec.h"
  9. #include "qsink.h"
  10. #include "nsrep.h"
  11. /*************************************************************************
  12. CDeliveryRecord
  13. **************************************************************************/
  14. CDeliveryRecord::~CDeliveryRecord()
  15. {
  16. if ( m_pNamespace )
  17. {
  18. m_pNamespace->RemoveFromCache( m_dwSize );
  19. }
  20. Clear();
  21. }
  22. void CDeliveryRecord::AddToCache( CEssNamespace * pNamespace, DWORD dwTotalSize, DWORD * pdwSleep )
  23. {
  24. _DBG_ASSERT( pNamespace );
  25. if ( NULL == m_pNamespace )
  26. {
  27. m_pNamespace = pNamespace;
  28. }
  29. m_pNamespace->AddToCache( m_dwSize, dwTotalSize, pdwSleep );
  30. }
  31. HRESULT CDeliveryRecord::Initialize( IWbemClassObject** apEvents,
  32. ULONG cEvents,
  33. IWbemCallSecurity* pCallSec )
  34. {
  35. HRESULT hr;
  36. Clear();
  37. m_pCallSec = pCallSec;
  38. for( ULONG i=0; i < cEvents; i++ )
  39. {
  40. //
  41. // TODO : should clone the object here later.
  42. //
  43. if ( m_Events.Add( apEvents[i] ) < 0 )
  44. {
  45. return WBEM_E_OUT_OF_MEMORY;
  46. }
  47. hr = AdjustTotalSize( apEvents[i] );
  48. if ( FAILED(hr) )
  49. {
  50. return WBEM_E_CRITICAL_ERROR;
  51. }
  52. }
  53. return WBEM_S_NO_ERROR;
  54. }
  55. HRESULT CDeliveryRecord::AdjustTotalSize( IWbemClassObject* pObj )
  56. {
  57. HRESULT hr;
  58. CWbemPtr<_IWmiObject> pEventInt;
  59. hr = pObj->QueryInterface( IID__IWmiObject, (void**)&pEventInt );
  60. if ( FAILED(hr) )
  61. {
  62. return hr;
  63. }
  64. DWORD dwSize;
  65. hr = pEventInt->GetObjectMemory( NULL, 0, &dwSize );
  66. if ( FAILED(hr) && hr != WBEM_E_BUFFER_TOO_SMALL )
  67. {
  68. return hr;
  69. }
  70. m_dwSize += dwSize;
  71. return WBEM_S_NO_ERROR;
  72. }
  73. HRESULT CDeliveryRecord::Persist( IStream* pStrm )
  74. {
  75. HRESULT hr;
  76. DWORD dwNumObjects = m_Events.GetSize();
  77. hr = pStrm->Write( &dwNumObjects, sizeof(DWORD), NULL );
  78. if ( FAILED(hr) )
  79. {
  80. return hr;
  81. }
  82. for( DWORD i=0; i < dwNumObjects; i++ )
  83. {
  84. hr = CoMarshalInterface( pStrm,
  85. IID_IWbemClassObject,
  86. m_Events[i],
  87. MSHCTX_DIFFERENTMACHINE,
  88. NULL,
  89. MSHLFLAGS_NORMAL );
  90. if ( FAILED(hr) )
  91. {
  92. return hr;
  93. }
  94. }
  95. return WBEM_S_NO_ERROR;
  96. }
  97. HRESULT CDeliveryRecord::Unpersist( IStream* pStrm )
  98. {
  99. HRESULT hr;
  100. Clear();
  101. DWORD dwNumObjects;
  102. hr = pStrm->Read( &dwNumObjects, sizeof(DWORD), NULL );
  103. if ( FAILED(hr) )
  104. {
  105. return hr;
  106. }
  107. for( DWORD i=0; i < dwNumObjects; i++ )
  108. {
  109. CWbemPtr<IWbemClassObject> pEvent;
  110. hr = CoUnmarshalInterface( pStrm,
  111. IID_IWbemClassObject,
  112. (void**)&pEvent );
  113. if ( FAILED(hr) )
  114. {
  115. return hr;
  116. }
  117. if ( m_Events.Add( pEvent ) < 0 )
  118. {
  119. return WBEM_E_OUT_OF_MEMORY;
  120. }
  121. hr = AdjustTotalSize( pEvent );
  122. if ( FAILED(hr) )
  123. {
  124. return WBEM_E_CRITICAL_ERROR;
  125. }
  126. }
  127. return WBEM_S_NO_ERROR;
  128. }
  129. /*************************************************************************
  130. CGuaranteedDeliveryRecord
  131. **************************************************************************/
  132. HRESULT CGuaranteedDeliveryRecord::PreDeliverAction( ITransaction* pTxn )
  133. {
  134. return WBEM_S_NO_ERROR;
  135. }
  136. HRESULT CGuaranteedDeliveryRecord::PostDeliverAction( ITransaction* pTxn,
  137. HRESULT hres )
  138. {
  139. #ifdef __WHISTLER_UNCUT
  140. return m_pSink->GuaranteedPostDeliverAction( m_pRcvr );
  141. #else
  142. return WBEM_E_NOT_SUPPORTED;
  143. #endif
  144. }
  145. /*************************************************************************
  146. CExpressDeliveryRecord
  147. **************************************************************************/
  148. HRESULT CExpressDeliveryRecord::PreDeliverAction( ITransaction* pTxn )
  149. {
  150. return WBEM_S_NO_ERROR;
  151. }
  152. HRESULT CExpressDeliveryRecord::PostDeliverAction( ITransaction* pTxn,
  153. HRESULT hres )
  154. {
  155. return WBEM_S_NO_ERROR;
  156. }
  157. CReuseMemoryManager CExpressDeliveryRecord::mstatic_Manager(sizeof CExpressDeliveryRecord);
  158. void *CExpressDeliveryRecord::operator new(size_t nBlock)
  159. {
  160. return mstatic_Manager.Allocate();
  161. }
  162. void CExpressDeliveryRecord::operator delete(void* p)
  163. {
  164. mstatic_Manager.Free(p);
  165. }