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.

159 lines
4.2 KiB

  1. /******************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. DataCollection_Wait.cpp
  5. Abstract:
  6. This file contains the implementation of the DIID_DSAFDataCollectionEvents interface,
  7. which is used in the ExecuteSync method to receive event from a data collection.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 07/22/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. CSAFDataCollectionEvents::CSAFDataCollectionEvents()
  14. {
  15. __HCP_FUNC_ENTRY( "CSAFDataCollectionEvents::CSAFDataCollectionEvents" );
  16. }
  17. HRESULT CSAFDataCollectionEvents::FinalConstruct()
  18. {
  19. __HCP_FUNC_ENTRY( "CSAFDataCollectionEvents::FinalConstruct" );
  20. HRESULT hr;
  21. m_hcpdc = NULL; // ISAFDataCollection* m_hcpdc;
  22. m_dwCookie = 0; // DWORD m_dwCookie;
  23. m_hEvent = NULL; // HANDLE m_hEvent;
  24. //
  25. // Create the event used to signal the completion of the transfer.
  26. //
  27. __MPC_EXIT_IF_CALL_RETURNS_NULL(hr, (m_hEvent = CreateEvent( NULL, false, false, NULL )));
  28. hr = S_OK;
  29. __HCP_FUNC_CLEANUP;
  30. __HCP_FUNC_EXIT(hr);
  31. }
  32. void CSAFDataCollectionEvents::FinalRelease()
  33. {
  34. __HCP_FUNC_ENTRY( "CSAFDataCollectionEvents::FinalRelease" );
  35. UnregisterForEvents();
  36. if(m_hEvent)
  37. {
  38. CloseHandle( m_hEvent ); m_hEvent = NULL;
  39. }
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. HRESULT CSAFDataCollectionEvents::RegisterForEvents( /*[in]*/ ISAFDataCollection* hcpdc )
  43. {
  44. __HCP_FUNC_ENTRY( "CSAFDataCollectionEvents::RegisterForEvents" );
  45. HRESULT hr;
  46. CComPtr<DSAFDataCollectionEvents> pCallback;
  47. m_hcpdc = hcpdc; m_hcpdc->AddRef();
  48. __MPC_EXIT_IF_METHOD_FAILS(hr, QueryInterface( DIID_DSAFDataCollectionEvents, (void**)&pCallback ));
  49. __MPC_EXIT_IF_METHOD_FAILS(hr, AtlAdvise( m_hcpdc, pCallback, DIID_DSAFDataCollectionEvents, &m_dwCookie ));
  50. hr = S_OK;
  51. __HCP_FUNC_CLEANUP;
  52. __HCP_FUNC_EXIT(hr);
  53. }
  54. void CSAFDataCollectionEvents::UnregisterForEvents()
  55. {
  56. __HCP_FUNC_ENTRY( "CSAFDataCollectionEvents::UnregisterForEvents" );
  57. if(m_dwCookie)
  58. {
  59. if(AtlUnadvise( m_hcpdc, DIID_DSAFDataCollectionEvents, m_dwCookie ) == S_OK)
  60. {
  61. m_dwCookie = 0;
  62. }
  63. }
  64. if(m_hcpdc)
  65. {
  66. m_hcpdc->Release(); m_hcpdc = NULL;
  67. }
  68. }
  69. HRESULT CSAFDataCollectionEvents::WaitForCompletion( /*[in]*/ ISAFDataCollection* hcpdc )
  70. {
  71. __HCP_FUNC_ENTRY( "CSAFDataCollectionEvents::WaitForCompletion" );
  72. _ASSERT(m_hcpdc == NULL && hcpdc != NULL);
  73. HRESULT hr;
  74. DC_STATUS dsStatus;
  75. MPC::SmartLock<_ThreadModel> lock( this );
  76. __MPC_EXIT_IF_METHOD_FAILS(hr, RegisterForEvents( hcpdc ));
  77. __MPC_EXIT_IF_METHOD_FAILS(hr, hcpdc->ExecuteAsync());
  78. lock = NULL; // Release the lock while waiting.
  79. ::WaitForSingleObject( m_hEvent, INFINITE );
  80. lock = this; // Reacquire the lock.
  81. hr = S_OK;
  82. __HCP_FUNC_CLEANUP;
  83. UnregisterForEvents();
  84. __HCP_FUNC_EXIT(hr);
  85. }
  86. /////////////////////////////////////////////////////////////////////////////
  87. HRESULT CSAFDataCollectionEvents::Invoke( /*[in] */ DISPID dispIdMember,
  88. /*[in] */ REFIID riid ,
  89. /*[in] */ LCID lcid ,
  90. /*[in] */ WORD wFlags ,
  91. /*[in/out]*/ DISPPARAMS *pDispParams ,
  92. /*[out] */ VARIANT *pVarResult ,
  93. /*[out] */ EXCEPINFO *pExcepInfo ,
  94. /*[out] */ UINT *puArgErr )
  95. {
  96. __HCP_FUNC_ENTRY( "CSAFDataCollectionEvents::Invoke" );
  97. if(dispIdMember == DISPID_SAF_DCE__ONCOMPLETE)
  98. {
  99. Lock();
  100. SetEvent( m_hEvent );
  101. Unlock();
  102. }
  103. __HCP_FUNC_EXIT(S_OK);
  104. }