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.

253 lines
5.9 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. PrintEngine.cpp
  5. Abstract:
  6. This file contains the implementation of the CPCHPrintEngine class,
  7. which implements the multi-topic printing.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 05/08/2000
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. /////////////////////////////////////////////////////////////////////////////
  14. #define CHECK_MODIFY() __MPC_EXIT_IF_METHOD_FAILS(hr, CanModifyProperties())
  15. /////////////////////////////////////////////////////////////////////////////
  16. CPCHPrintEngine::CPCHPrintEngine()
  17. {
  18. __HCP_FUNC_ENTRY( "CPCHPrintEngine::CPCHPrintEngine" );
  19. // Printing::Print m_engine;
  20. //
  21. // MPC::CComPtrThreadNeutral<IDispatch> m_sink_onProgress;
  22. // MPC::CComPtrThreadNeutral<IDispatch> m_sink_onComplete;
  23. }
  24. void CPCHPrintEngine::FinalRelease()
  25. {
  26. __HCP_FUNC_ENTRY( "CPCHPrintEngine::FinalRelease" );
  27. (void)Abort();
  28. Thread_Wait();
  29. }
  30. /////////////////////////////////////////////////////////////////////////////
  31. /////////////////////////////////////////////////////////////////////////////
  32. HRESULT CPCHPrintEngine::Run()
  33. {
  34. __HCP_FUNC_ENTRY( "CPCHPrintEngine::Run" );
  35. HRESULT hr;
  36. ::SetThreadPriority( ::GetCurrentThread(), THREAD_PRIORITY_LOWEST );
  37. __MPC_TRY_BEGIN();
  38. __MPC_EXIT_IF_METHOD_FAILS(hr, m_engine.Initialize( CPCHHelpCenterExternal::s_GLOBAL->Window() ));
  39. __MPC_EXIT_IF_METHOD_FAILS(hr, m_engine.PrintAll( this ));
  40. hr = S_OK;
  41. __HCP_FUNC_CLEANUP;
  42. __MPC_TRY_CATCHALL(hr);
  43. //
  44. // Close everything.
  45. //
  46. m_engine.Terminate();
  47. //
  48. // Keep this outside any critical section, otherwise a deadlock could occur.
  49. //
  50. Fire_onComplete( this, hr );
  51. Thread_Abort(); // To tell the MPC:Thread object to close the worker thread...
  52. __HCP_FUNC_EXIT(hr);
  53. }
  54. /////////////////////////////////////////////////////////////////////////////
  55. ////////////////
  56. // //
  57. // Properties //
  58. // //
  59. ////////////////
  60. STDMETHODIMP CPCHPrintEngine::put_onProgress( /*[in]*/ IDispatch* function )
  61. {
  62. __HCP_BEGIN_PROPERTY_PUT("CPCHPrintEngine::put_onProgress",hr);
  63. CHECK_MODIFY();
  64. m_sink_onProgress = function;
  65. __HCP_END_PROPERTY(hr);
  66. }
  67. STDMETHODIMP CPCHPrintEngine::put_onComplete( /*[in]*/ IDispatch* function )
  68. {
  69. __HCP_BEGIN_PROPERTY_PUT("CPCHPrintEngine::put_onComplete",hr);
  70. CHECK_MODIFY();
  71. m_sink_onComplete = function;
  72. __HCP_END_PROPERTY(hr);
  73. }
  74. /////////////////////////////////////////////////////////////////////////////
  75. /////////////////////////////////////////////////////////////////////////////
  76. STDMETHODIMP CPCHPrintEngine::AddTopic( /*[in]*/ BSTR bstrURL )
  77. {
  78. __HCP_FUNC_ENTRY( "CPCHPrintEngine::AddTopic" );
  79. HRESULT hr;
  80. MPC::SmartLock<_ThreadModel> lock( this );
  81. __MPC_PARAMCHECK_BEGIN(hr)
  82. __MPC_PARAMCHECK_STRING_NOT_EMPTY(bstrURL);
  83. __MPC_PARAMCHECK_END();
  84. CHECK_MODIFY();
  85. __MPC_EXIT_IF_METHOD_FAILS(hr, m_engine.AddUrl( bstrURL ));
  86. hr = S_OK;
  87. __HCP_FUNC_CLEANUP;
  88. __HCP_FUNC_EXIT(hr);
  89. }
  90. STDMETHODIMP CPCHPrintEngine::Start()
  91. {
  92. __HCP_FUNC_ENTRY( "CPCHPrintEngine::Start" );
  93. HRESULT hr;
  94. MPC::SmartLock<_ThreadModel> lock( this );
  95. CHECK_MODIFY();
  96. //
  97. // Release the lock on current object, otherwise a deadlock could occur.
  98. //
  99. lock = NULL;
  100. __MPC_EXIT_IF_METHOD_FAILS(hr, Thread_Start( this, Run, this ));
  101. hr = S_OK;
  102. __HCP_FUNC_CLEANUP;
  103. __HCP_FUNC_EXIT(hr);
  104. }
  105. STDMETHODIMP CPCHPrintEngine::Abort()
  106. {
  107. __HCP_FUNC_ENTRY( "CPCHPrintEngine::Abort" );
  108. Thread_Abort(); // To tell the MPC:Thread object to close the worker thread...
  109. __HCP_FUNC_EXIT(S_OK);
  110. }
  111. /////////////////////////////////////////////////////////////////////////////
  112. /////////////////////////////////////////////////////////////////////////////
  113. //////////////////////////
  114. // //
  115. // Event Firing Methods //
  116. // //
  117. //////////////////////////
  118. HRESULT CPCHPrintEngine::Fire_onProgress( IPCHPrintEngine* hcppe, BSTR bstrURL, long lDone, long lTotal )
  119. {
  120. CComVariant pvars[4];
  121. pvars[3] = hcppe;
  122. pvars[2] = bstrURL;
  123. pvars[1] = lDone;
  124. pvars[0] = lTotal;
  125. return FireAsync_Generic( DISPID_PCH_PEE__ONPROGRESS, pvars, ARRAYSIZE( pvars ), m_sink_onProgress );
  126. }
  127. HRESULT CPCHPrintEngine::Fire_onComplete( IPCHPrintEngine* hcppe, HRESULT hrRes )
  128. {
  129. CComVariant pvars[2];
  130. pvars[1] = hcppe;
  131. pvars[0] = hrRes;
  132. return FireAsync_Generic( DISPID_PCH_PEE__ONCOMPLETE, pvars, ARRAYSIZE( pvars ), m_sink_onComplete );
  133. }
  134. //////////////////////
  135. // //
  136. // Callback Methods //
  137. // //
  138. //////////////////////
  139. HRESULT CPCHPrintEngine::Progress( /*[in]*/ LPCWSTR szURL, /*[in]*/ int iDone, /*[in]*/ int iTotal )
  140. {
  141. __HCP_FUNC_ENTRY( "CPCHPrintEngine::Progress" );
  142. HRESULT hr;
  143. if(Thread_IsAborted())
  144. {
  145. __MPC_SET_ERROR_AND_EXIT(hr, E_ABORT);
  146. }
  147. __MPC_EXIT_IF_METHOD_FAILS(hr, Fire_onProgress( this, CComBSTR( szURL ), iDone, iTotal ));
  148. hr = S_OK;
  149. __HCP_FUNC_CLEANUP;
  150. __HCP_FUNC_EXIT(hr);
  151. }
  152. /////////////////////////////////////////////////////////////////////////////
  153. /////////////////////////////////////////////////////////////////////////////
  154. /////////////////////
  155. // //
  156. // Utility Methods //
  157. // //
  158. /////////////////////
  159. HRESULT CPCHPrintEngine::CanModifyProperties()
  160. {
  161. __HCP_FUNC_ENTRY( "CPCHPrintEngine::CanModifyProperties" );
  162. HRESULT hr = Thread_IsRunning() ? E_ACCESSDENIED : S_OK;
  163. __HCP_FUNC_EXIT(hr);
  164. }