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.

123 lines
2.2 KiB

  1. /*++
  2. Copyright (c) 2000-2001 Microsoft Corporation
  3. Module Name:
  4. WbemObjectSink.cpp
  5. Abstract:
  6. Implementation of:
  7. CWbemObjectSink
  8. Author:
  9. ???
  10. Revision History:
  11. Mohit Srivastava 10-Nov-2000
  12. --*/
  13. #include "WbemObjectSink.h"
  14. #include <dbgutil.h>
  15. CWbemObjectSink::CWbemObjectSink(
  16. IWbemObjectSink* pHandler,
  17. DWORD dwSize)
  18. :m_pSink(NULL), m_ppInst(NULL), m_dwIndex(0)
  19. {
  20. m_pSink = pHandler;
  21. if(m_pSink != NULL)
  22. {
  23. m_pSink->AddRef();
  24. }
  25. m_dwThreshHold = dwSize;
  26. m_ppInst = new IWbemClassObject*[dwSize];
  27. if ( m_ppInst )
  28. {
  29. memset(m_ppInst, 0, sizeof(IWbemClassObject*) * dwSize);
  30. }
  31. }
  32. CWbemObjectSink::~CWbemObjectSink()
  33. {
  34. if(m_ppInst != NULL)
  35. {
  36. if(m_dwIndex >0)
  37. {
  38. m_pSink->Indicate(
  39. m_dwIndex,
  40. m_ppInst);
  41. }
  42. for(DWORD i =0; i<m_dwIndex; i++)
  43. {
  44. if(m_ppInst[i] != NULL)
  45. {
  46. (m_ppInst[i])->Release();
  47. }
  48. }
  49. delete [] m_ppInst;
  50. }
  51. if(m_pSink != NULL)
  52. {
  53. m_pSink->Release();
  54. }
  55. }
  56. void
  57. CWbemObjectSink::Indicate(IWbemClassObject* pInst)
  58. {
  59. if(pInst == NULL)
  60. {
  61. throw (HRESULT)WBEM_E_INVALID_PARAMETER;
  62. }
  63. m_ppInst[m_dwIndex++] = pInst;
  64. DBG_ASSERT(m_dwIndex <= m_dwThreshHold);
  65. pInst->AddRef();
  66. if(m_dwIndex == m_dwThreshHold)
  67. {
  68. SCODE sc = m_pSink->Indicate(
  69. m_dwIndex,
  70. m_ppInst);
  71. //
  72. // reset state
  73. //
  74. for(DWORD i=0; i< m_dwThreshHold; i++)
  75. {
  76. if(m_ppInst[i] != NULL)
  77. {
  78. (m_ppInst[i])->Release();
  79. }
  80. m_ppInst[i] = NULL;
  81. }
  82. m_dwIndex = 0;
  83. if(sc != S_OK)
  84. {
  85. throw (HRESULT)sc;
  86. }
  87. }
  88. return;
  89. }
  90. void
  91. CWbemObjectSink::SetStatus(
  92. LONG lFlags,
  93. HRESULT hr,
  94. const BSTR bstrParam,
  95. IWbemClassObject* pObjParam)
  96. {
  97. m_pSink->SetStatus(
  98. lFlags,
  99. hr,
  100. bstrParam,
  101. pObjParam);
  102. }