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.

106 lines
2.1 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. PROVINIT.CPP
  5. Abstract:
  6. This file implements the provider init sink
  7. History:
  8. --*/
  9. #include "precomp.h"
  10. #include <stdio.h>
  11. #include <wbemcomn.h>
  12. #include <sync.h>
  13. #include <cominit.h>
  14. #include "provinit.h"
  15. ULONG STDMETHODCALLTYPE CProviderInitSink::AddRef()
  16. {
  17. CInCritSec ics(&m_cs);
  18. return ++m_lRef;
  19. }
  20. ULONG STDMETHODCALLTYPE CProviderInitSink::Release()
  21. {
  22. EnterCriticalSection(&m_cs);
  23. --m_lRef;
  24. if(m_lRef == 0)
  25. {
  26. LeaveCriticalSection(&m_cs);
  27. delete this;
  28. }
  29. else LeaveCriticalSection(&m_cs);
  30. return 99;
  31. }
  32. HRESULT STDMETHODCALLTYPE CProviderInitSink::QueryInterface(REFIID riid,
  33. void** ppv)
  34. {
  35. CInCritSec ics(&m_cs);
  36. if(riid == IID_IUnknown || riid == IID_IWbemProviderInitSink)
  37. {
  38. *ppv = (IWbemProviderInitSink*)this;
  39. AddRef();
  40. return S_OK;
  41. }
  42. else return E_NOINTERFACE;
  43. }
  44. HRESULT STDMETHODCALLTYPE CProviderInitSink::SetStatus(long lStatus,
  45. long lFlags)
  46. {
  47. CInCritSec ics(&m_cs);
  48. if(lFlags != 0)
  49. return WBEM_E_INVALID_PARAMETER;
  50. if(SUCCEEDED(lStatus) && lStatus != WBEM_S_INITIALIZED)
  51. {
  52. // Partial initialization is not supported in this version
  53. // =======================================================
  54. return WBEM_S_NO_ERROR;
  55. }
  56. m_lStatus = lStatus;
  57. SetEvent(m_hEvent);
  58. return WBEM_S_NO_ERROR;
  59. }
  60. CProviderInitSink::CProviderInitSink() : m_lRef(0)
  61. {
  62. m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  63. }
  64. CProviderInitSink::~CProviderInitSink()
  65. {
  66. CloseHandle(m_hEvent);
  67. }
  68. HRESULT CProviderInitSink::WaitForCompletion()
  69. {
  70. // Wait
  71. // ====
  72. DWORD dwRes = WbemWaitForSingleObject(m_hEvent, 300000);
  73. if(dwRes != WAIT_OBJECT_0)
  74. {
  75. ERRORTRACE((LOG_WBEMCORE, "Provider initialization phase timed out\n"));
  76. return WBEM_E_PROVIDER_LOAD_FAILURE;
  77. }
  78. return m_lStatus;
  79. }