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.

132 lines
3.7 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // BVTSink.CPP
  4. //
  5. //
  6. // Copyright (c)2000 Microsoft Corporation, All Rights Reserved
  7. //
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  9. #include "bvt.h"
  10. #include <time.h>
  11. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  12. //*****************************************************************************************************************
  13. //
  14. //
  15. //
  16. //*****************************************************************************************************************
  17. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  18. HRESULT CSinkEx::QueryInterface( REFIID riid, LPVOID * ppvObj )
  19. {
  20. if (riid == IID_IUnknown)
  21. {
  22. *ppvObj = (IUnknown *)this;
  23. }
  24. else if (riid == IID_IWbemObjectSink)
  25. {
  26. *ppvObj = (IWbemObjectSink *)this;
  27. }
  28. else if (riid == IID_IWbemObjectSinkEx)
  29. {
  30. *ppvObj = (IWbemObjectSinkEx *)this;
  31. }
  32. else
  33. {
  34. *ppvObj = NULL;
  35. return E_NOINTERFACE;
  36. }
  37. AddRef();
  38. return NOERROR;
  39. }
  40. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  41. ULONG CSinkEx::AddRef()
  42. {
  43. return (ULONG)InterlockedIncrement(&m_lRefCount);
  44. }
  45. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  46. ULONG CSinkEx::Release()
  47. {
  48. Lock();
  49. if(m_lRefCount <= 0)
  50. {
  51. delete this;
  52. return 0;
  53. }
  54. if (InterlockedDecrement(&m_lRefCount))
  55. {
  56. Unlock();
  57. return 1;
  58. }
  59. Unlock();
  60. delete this;
  61. return 0;
  62. }
  63. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  64. HRESULT CSinkEx::Indicate( long lObjectCount, IWbemClassObject ** pObjArray )
  65. {
  66. if(lObjectCount == 0)
  67. return WBEM_NO_ERROR;
  68. Lock();
  69. for (int i = 0; i < lObjectCount; i++)
  70. {
  71. IWbemClassObject *pObj = pObjArray[i];
  72. pObj->AddRef();
  73. m_aObjects.Add(pObj);
  74. }
  75. Unlock();
  76. return WBEM_NO_ERROR;
  77. }
  78. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  79. HRESULT CSinkEx::Set( long lFlags, REFIID riid, void *pComObject)
  80. {
  81. Lock();
  82. m_pInterfaceID=riid;
  83. m_pInterface=(IUnknown *)pComObject;
  84. Unlock();
  85. return WBEM_NO_ERROR;
  86. }
  87. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  88. STDMETHODIMP CSinkEx::SetStatus(long lFlags, HRESULT hResult, BSTR strParam, IWbemClassObject* pObjParam)
  89. {
  90. m_hres = hResult;
  91. if(lFlags & WBEM_STATUS_PROGRESS)
  92. {
  93. return WBEM_NO_ERROR;
  94. }
  95. m_pErrorObj = pObjParam;
  96. if(pObjParam)
  97. pObjParam->AddRef();
  98. SetEvent(m_hEvent);
  99. return WBEM_NO_ERROR;
  100. }
  101. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  102. CSinkEx::CSinkEx(LONG lStartingRefCount)
  103. {
  104. m_hres = 0;
  105. InitializeCriticalSection(&m_cs);
  106. m_lRefCount = lStartingRefCount;
  107. m_hEvent = CreateEvent(0, FALSE, FALSE, 0);
  108. m_pErrorObj = NULL;
  109. }
  110. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  111. CSinkEx::~CSinkEx()
  112. {
  113. DeleteCriticalSection(&m_cs);
  114. CloseHandle(m_hEvent);
  115. for (int i = 0; i < m_aObjects.Size(); i++)
  116. ((IWbemClassObject *) m_aObjects[i])->Release();
  117. if(m_pErrorObj) m_pErrorObj->Release();
  118. }