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.

186 lines
4.7 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. MPCUploadEvents.cpp
  5. Abstract:
  6. This file contains the implementation of the DMPCUploadEvents interface,
  7. which is used in the ActiveSync method to receive event from a job.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 04/30/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. CMPCUploadEvents::CMPCUploadEvents()
  14. {
  15. __ULT_FUNC_ENTRY( "CMPCUploadEvents::CMPCUploadEvents" );
  16. // CComPtr<IMPCUploadJob> m_mpcujJob;
  17. m_dwUploadEventsCookie = 0; // DWORD m_dwUploadEventsCookie;
  18. m_hEvent = NULL; // HANDLE m_hEvent;
  19. }
  20. HRESULT CMPCUploadEvents::FinalConstruct()
  21. {
  22. __ULT_FUNC_ENTRY( "CMPCUpload::FinalConstruct" );
  23. HRESULT hr;
  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. __ULT_FUNC_CLEANUP;
  30. __ULT_FUNC_EXIT(hr);
  31. }
  32. void CMPCUploadEvents::FinalRelease()
  33. {
  34. __ULT_FUNC_ENTRY( "CMPCUploadEvents::FinalRelease" );
  35. UnregisterForEvents();
  36. if(m_hEvent)
  37. {
  38. ::CloseHandle( m_hEvent ); m_hEvent = NULL;
  39. }
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. bool CMPCUploadEvents::IsCompleted( /*[in]*/ UL_STATUS usStatus )
  43. {
  44. __ULT_FUNC_ENTRY( "CMPCUploadEvents::IsCompleted" );
  45. bool res = false;
  46. switch(usStatus)
  47. {
  48. case UL_FAILED:
  49. case UL_COMPLETED:
  50. case UL_DELETED:
  51. res = true;
  52. break;
  53. }
  54. __ULT_FUNC_EXIT(res);
  55. }
  56. HRESULT CMPCUploadEvents::RegisterForEvents( /*[in]*/ IMPCUploadJob* mpcujJob )
  57. {
  58. __ULT_FUNC_ENTRY( "CMPCUploadEvents::RegisterForEvents" );
  59. HRESULT hr;
  60. CComPtr<DMPCUploadEvents> pCallback;
  61. m_mpcujJob = mpcujJob;
  62. __MPC_EXIT_IF_METHOD_FAILS(hr, QueryInterface( DIID_DMPCUploadEvents, (void**)&pCallback ));
  63. __MPC_EXIT_IF_METHOD_FAILS(hr, AtlAdvise( m_mpcujJob, pCallback, DIID_DMPCUploadEvents, &m_dwUploadEventsCookie ));
  64. hr = S_OK;
  65. __ULT_FUNC_CLEANUP;
  66. __ULT_FUNC_EXIT(hr);
  67. }
  68. void CMPCUploadEvents::UnregisterForEvents()
  69. {
  70. __ULT_FUNC_ENTRY( "CMPCUploadEvents::UnregisterForEvents" );
  71. if(m_dwUploadEventsCookie)
  72. {
  73. if(AtlUnadvise( m_mpcujJob, DIID_DMPCUploadEvents, m_dwUploadEventsCookie ) == S_OK)
  74. {
  75. m_dwUploadEventsCookie = 0;
  76. }
  77. }
  78. m_mpcujJob.Release();
  79. }
  80. HRESULT CMPCUploadEvents::WaitForCompletion( /*[in]*/ IMPCUploadJob* mpcujJob )
  81. {
  82. __ULT_FUNC_ENTRY( "CMPCUploadEvents::WaitForCompletion" );
  83. _ASSERT(m_mpcujJob == NULL && mpcujJob != NULL);
  84. HRESULT hr;
  85. UL_STATUS usStatus;
  86. MPC::SmartLock<_ThreadModel> lock( this );
  87. __MPC_EXIT_IF_METHOD_FAILS(hr, RegisterForEvents( mpcujJob ));
  88. (void)mpcujJob->get_Status( &usStatus );
  89. if(IsCompleted( usStatus ) == false)
  90. {
  91. lock = NULL; // Release the lock while waiting.
  92. WaitForSingleObject( m_hEvent, INFINITE );
  93. lock = this; // Reget the lock.
  94. }
  95. hr = S_OK;
  96. __ULT_FUNC_CLEANUP;
  97. UnregisterForEvents();
  98. __ULT_FUNC_EXIT(hr);
  99. }
  100. /////////////////////////////////////////////////////////////////////////////
  101. HRESULT CMPCUploadEvents::Invoke( /*[in] */ DISPID dispIdMember,
  102. /*[in] */ REFIID riid ,
  103. /*[in] */ LCID lcid ,
  104. /*[in] */ WORD wFlags ,
  105. /*[in/out]*/ DISPPARAMS *pDispParams ,
  106. /*[out] */ VARIANT *pVarResult ,
  107. /*[out] */ EXCEPINFO *pExcepInfo ,
  108. /*[out] */ UINT *puArgErr )
  109. {
  110. __ULT_FUNC_ENTRY( "CMPCUploadEvents::Invoke" );
  111. if(dispIdMember == DISPID_UL_UPLOADEVENTS_ONSTATUSCHANGE)
  112. {
  113. CComVariant argJob = pDispParams->rgvarg[1];
  114. CComVariant argStatus = pDispParams->rgvarg[0];
  115. CComQIPtr<IMPCUploadJob, &IID_IMPCUploadJob> mpcujJob = argJob.punkVal;
  116. Lock();
  117. if(mpcujJob.p == m_mpcujJob && IsCompleted( (UL_STATUS)argStatus.lVal ))
  118. {
  119. SetEvent( m_hEvent );
  120. }
  121. Unlock();
  122. }
  123. __ULT_FUNC_EXIT(S_OK);
  124. }