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.

114 lines
2.0 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. NOTSINK.CPP
  5. Abstract:
  6. History:
  7. --*/
  8. #include "precomp.h"
  9. #include "notsink.h"
  10. #include <stdio.h>
  11. #include "wbemntfy.h"
  12. extern CStatusMonitor gStatus;
  13. // Notification Query Sink
  14. SCODE CNotSink::QueryInterface(
  15. REFIID riid,
  16. LPVOID * ppvObj
  17. )
  18. {
  19. if (riid == IID_IUnknown)
  20. {
  21. *ppvObj = this;
  22. }
  23. else if (riid == IID_IWbemObjectSink)
  24. *ppvObj = this;
  25. else
  26. {
  27. *ppvObj = NULL;
  28. return E_NOINTERFACE;
  29. }
  30. AddRef();
  31. return NOERROR;
  32. }
  33. ULONG CNotSink::AddRef()
  34. {
  35. InterlockedIncrement(&m_lRefCount);
  36. return (ULONG) m_lRefCount;
  37. }
  38. ULONG CNotSink::Release()
  39. {
  40. InterlockedDecrement(&m_lRefCount);
  41. if (0 != m_lRefCount)
  42. {
  43. return 1;
  44. }
  45. delete this;
  46. return 0;
  47. }
  48. SCODE CNotSink::Indicate(
  49. long lObjectCount,
  50. IWbemClassObject ** pObjArray
  51. )
  52. {
  53. if(lObjectCount == 0) return WBEM_NO_ERROR;
  54. if(m_pViewer == NULL) return WBEM_NO_ERROR;
  55. // Use critical section to prevent re-entrancy
  56. // from additional Indicate's into this code.
  57. EnterCriticalSection(&m_cs);
  58. for (int i = 0; i < lObjectCount; i++)
  59. {
  60. IWbemClassObject *pObj = pObjArray[i];
  61. m_pViewer->PostObject(pObj);
  62. }
  63. m_pViewer->PostCount(lObjectCount);
  64. LeaveCriticalSection(&m_cs);
  65. return WBEM_NO_ERROR;
  66. }
  67. STDMETHODIMP CNotSink::SetStatus(long lFlags, long lParam, BSTR strParam,
  68. IWbemClassObject* pObjParam)
  69. {
  70. if(lFlags & WBEM_STATUS_PROGRESS)
  71. {
  72. gStatus.Add(lFlags, lParam, strParam);
  73. return WBEM_NO_ERROR;
  74. }
  75. EnterCriticalSection(&m_cs);
  76. if(m_pViewer)
  77. m_pViewer->PostComplete(lParam, strParam, pObjParam);
  78. LeaveCriticalSection(&m_cs);
  79. return WBEM_S_NO_ERROR;
  80. }
  81. CNotSink::CNotSink(CQueryResultDlg* pViewer)
  82. {
  83. m_lRefCount = 1;
  84. m_pViewer = pViewer;
  85. InitializeCriticalSection(&m_cs);
  86. }
  87. CNotSink::~CNotSink()
  88. {
  89. DeleteCriticalSection(&m_cs);
  90. }