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.

139 lines
3.2 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. ScriptWrapper_ClientSide.cpp
  5. Abstract:
  6. File for implementation of CPCHScriptLauncher class,
  7. a generic wrapper for remoting scripting engines.
  8. Revision History:
  9. Davide Massarenti created 04/02/2001
  10. ********************************************************************/
  11. #include "stdafx.h"
  12. //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  13. CPCHScriptWrapper_Launcher::CPCHScriptWrapper_Launcher()
  14. {
  15. // MPC::CComPtrThreadNeutral<IUnknown> m_engine;
  16. m_pCLSID = NULL; // const CLSID* m_pCLSID;
  17. // CComBSTR m_bstrURL;
  18. }
  19. CPCHScriptWrapper_Launcher::~CPCHScriptWrapper_Launcher()
  20. {
  21. Thread_Abort();
  22. }
  23. HRESULT CPCHScriptWrapper_Launcher::Run()
  24. {
  25. __HCP_FUNC_ENTRY( "CPCHScriptWrapper_Launcher::Run" );
  26. HRESULT hr;
  27. MPC::SmartLock<_ThreadModel> lock( this );
  28. while(Thread_IsAborted() == false)
  29. {
  30. if(m_pCLSID)
  31. {
  32. (void)CreateEngine();
  33. m_pCLSID = NULL;
  34. Thread_SignalMain();
  35. }
  36. else
  37. {
  38. lock = NULL;
  39. MPC::WaitForSingleObject( Thread_GetSignalEvent(), INFINITE );
  40. lock = this;
  41. }
  42. }
  43. hr = S_OK;
  44. Thread_Abort(); // To tell the MPC:Thread object to close the worker thread...
  45. __HCP_FUNC_EXIT(hr);
  46. }
  47. HRESULT CPCHScriptWrapper_Launcher::CreateEngine()
  48. {
  49. __HCP_FUNC_ENTRY( "CPCHScriptWrapper_Launcher::CreateEngine" );
  50. HRESULT hr;
  51. CComPtr<CPCHScriptWrapper_ServerSide> obj;
  52. CComPtr<IUnknown> unk;
  53. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &obj ));
  54. __MPC_EXIT_IF_METHOD_FAILS(hr, obj->FinalConstructInner( m_pCLSID, m_bstrURL ));
  55. __MPC_EXIT_IF_METHOD_FAILS(hr, obj.QueryInterface( &unk ));
  56. m_engine = unk;
  57. hr = S_OK;
  58. __HCP_FUNC_CLEANUP;
  59. m_hr = hr;
  60. __HCP_FUNC_EXIT(hr);
  61. }
  62. HRESULT CPCHScriptWrapper_Launcher::CreateScriptWrapper( /*[in ]*/ REFCLSID rclsid ,
  63. /*[in ]*/ BSTR bstrCode ,
  64. /*[in ]*/ BSTR bstrURL ,
  65. /*[out]*/ IUnknown* *ppObj )
  66. {
  67. __HCP_FUNC_ENTRY( "CPCHScriptWrapper_Launcher::CreateScriptWrapper" );
  68. HRESULT hr;
  69. MPC::SmartLock<_ThreadModel> lock( this );
  70. __MPC_PARAMCHECK_BEGIN(hr)
  71. __MPC_PARAMCHECK_POINTER_AND_SET(ppObj,NULL);
  72. __MPC_PARAMCHECK_END();
  73. if(Thread_IsRunning() == false &&
  74. Thread_IsAborted() == false )
  75. {
  76. __MPC_EXIT_IF_METHOD_FAILS(hr, Thread_Start( this, Run, NULL ));
  77. }
  78. if(Thread_IsRunning())
  79. {
  80. CComPtr<IUnknown> unk;
  81. m_pCLSID = &rclsid;
  82. m_bstrURL = bstrURL;
  83. Thread_Signal();
  84. lock = NULL;
  85. Thread_WaitNotificationFromWorker( INFINITE, /*fNoMessagePump*/true );
  86. lock = this;
  87. __MPC_EXIT_IF_METHOD_FAILS(hr, m_hr); // The real error code.
  88. unk = m_engine; m_engine.Release();
  89. *ppObj = unk.Detach();
  90. }
  91. hr = S_OK;
  92. __HCP_FUNC_CLEANUP;
  93. __HCP_FUNC_EXIT(hr);
  94. }