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.

212 lines
5.5 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Service.cpp
  5. Abstract:
  6. This file contains the implementation of the client-side proxy for IPCHService.
  7. Revision History:
  8. Davide Massarenti (Dmassare) 07/17/2000
  9. created
  10. ******************************************************************************/
  11. #include "stdafx.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. CPCHProxy_IPCHService::CPCHProxy_IPCHService()
  14. {
  15. // CPCHSecurityHandle m_SecurityHandle;
  16. m_parent = NULL; // CPCHHelpCenterExternal* m_parent;
  17. //
  18. // MPC::CComSafeAutoCriticalSection m_DirectLock;
  19. // MPC::CComPtrThreadNeutral<IPCHService> m_Direct_Service;
  20. m_fContentStoreTested = false; // bool m_fContentStoreTested;
  21. //
  22. m_Utility = NULL; // CPCHProxy_IPCHUtility* m_Utility;
  23. }
  24. CPCHProxy_IPCHService::~CPCHProxy_IPCHService()
  25. {
  26. Passivate();
  27. }
  28. ////////////////////
  29. HRESULT CPCHProxy_IPCHService::ConnectToParent( /*[in]*/ CPCHHelpCenterExternal* parent )
  30. {
  31. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHService::ConnectToParent" );
  32. HRESULT hr;
  33. __MPC_PARAMCHECK_BEGIN(hr)
  34. __MPC_PARAMCHECK_NOTNULL(parent);
  35. __MPC_PARAMCHECK_END();
  36. m_parent = parent;
  37. m_SecurityHandle.Initialize( parent, (IPCHService*)this );
  38. //
  39. // If the service is already running, it will respond to CLSID_PCHServiceReal, so let's try to connect through it, but ignore failure.
  40. //
  41. {
  42. CComPtr<IClassFactory> fact;
  43. CComQIPtr<IPCHService> svc;
  44. (void)::CoGetClassObject( CLSID_PCHService, CLSCTX_ALL, NULL, IID_IClassFactory, (void**)&fact );
  45. if((svc = fact))
  46. {
  47. CComPtr<IPCHService> svcReal;
  48. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureDirectConnection( svcReal, false ));
  49. }
  50. }
  51. hr = S_OK;
  52. __HCP_FUNC_CLEANUP;
  53. __HCP_FUNC_EXIT(hr);
  54. }
  55. void CPCHProxy_IPCHService::Passivate()
  56. {
  57. MPC::SmartLock<_ThreadModel> lock( this );
  58. if(m_Utility)
  59. {
  60. m_Utility->Passivate();
  61. MPC::Release2<IPCHUtility>( m_Utility );
  62. }
  63. m_Direct_Service.Release();
  64. m_SecurityHandle.Passivate();
  65. m_parent = NULL;
  66. }
  67. HRESULT CPCHProxy_IPCHService::EnsureDirectConnection( /*[out]*/ CComPtr<IPCHService>& svc, /*[in]*/ bool fRefresh )
  68. {
  69. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHService::EnsureDirectConnection" );
  70. HRESULT hr;
  71. ProxySmartLock lock( &m_DirectLock );
  72. if(fRefresh) m_Direct_Service.Release();
  73. svc.Release(); __MPC_EXIT_IF_METHOD_FAILS(hr, m_Direct_Service.Access( &svc ));
  74. if(!svc)
  75. {
  76. DEBUG_AppendPerf( DEBUG_PERF_PROXIES, "CPCHProxy_IPCHService::EnsureDirectConnection - IN" );
  77. if(FAILED(hr = ::CoCreateInstance( CLSID_PCHService, NULL, CLSCTX_ALL, IID_IPCHService, (void**)&svc )))
  78. {
  79. MPC::RegKey rk;
  80. rk.SetRoot ( HKEY_CLASSES_ROOT, KEY_ALL_ACCESS );
  81. rk.Attach ( L"CLSID\\{00020420-0000-0000-C000-000000000046}\\InprocServer32" );
  82. rk.del_Value( L"InprocServer32" );
  83. __MPC_EXIT_IF_METHOD_FAILS(hr, ::CoCreateInstance( CLSID_PCHService, NULL, CLSCTX_ALL, IID_IPCHService, (void**)&svc ));
  84. }
  85. m_Direct_Service = svc;
  86. DEBUG_AppendPerf( DEBUG_PERF_PROXIES, "CPCHProxy_IPCHService::EnsureDirectConnection - OUT" );
  87. if(!svc)
  88. {
  89. __MPC_SET_ERROR_AND_EXIT(hr, E_HANDLE);
  90. }
  91. }
  92. hr = S_OK;
  93. __HCP_FUNC_CLEANUP;
  94. __HCP_FUNC_EXIT(hr);
  95. }
  96. HRESULT CPCHProxy_IPCHService::EnsureContentStore()
  97. {
  98. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHService::EnsureContentStore" );
  99. HRESULT hr;
  100. ProxySmartLock lock( &m_DirectLock );
  101. if(m_fContentStoreTested == false)
  102. {
  103. CComPtr<IPCHService> svc;
  104. VARIANT_BOOL fTrusted;
  105. lock = NULL;
  106. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureDirectConnection( svc ));
  107. lock = &m_DirectLock;
  108. __MPC_EXIT_IF_METHOD_FAILS(hr, svc->IsTrusted( CComBSTR( L"hcp://system" ), &fTrusted ));
  109. m_fContentStoreTested = true;
  110. }
  111. hr = S_OK;
  112. __HCP_FUNC_CLEANUP;
  113. __HCP_FUNC_EXIT(hr);
  114. }
  115. HRESULT CPCHProxy_IPCHService::GetUtility( /*[out]*/ CPCHProxy_IPCHUtility* *pVal )
  116. {
  117. __HCP_FUNC_ENTRY( "CPCHProxy_IPCHService::GetUtility" );
  118. HRESULT hr;
  119. MPC::SmartLock<_ThreadModel> lock( this );
  120. if(m_Utility == NULL)
  121. {
  122. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &m_Utility ));
  123. __MPC_EXIT_IF_METHOD_FAILS(hr, m_Utility->ConnectToParent( this, m_SecurityHandle ));
  124. }
  125. hr = S_OK;
  126. __HCP_FUNC_CLEANUP;
  127. if(FAILED(hr)) MPC::Release2<IPCHUtility>( m_Utility );
  128. (void)MPC::CopyTo2<IPCHUtility>( m_Utility, pVal );
  129. __HCP_FUNC_EXIT(hr);
  130. }
  131. ////////////////////////////////////////////////////////////////////////////////
  132. STDMETHODIMP CPCHProxy_IPCHService::CreateScriptWrapper( /*[in]*/ REFCLSID rclsid ,
  133. /*[in]*/ BSTR bstrCode ,
  134. /*[in]*/ BSTR bstrURL ,
  135. /*[out]*/ IUnknown* *ppObj )
  136. {
  137. __HCP_BEGIN_PROPERTY_GET("CPCHProxy_IPCHService::CreateScriptWrapper",hr,ppObj);
  138. CComPtr<IPCHService> svc;
  139. __MPC_EXIT_IF_METHOD_FAILS(hr, EnsureDirectConnection( svc ));
  140. __MPC_EXIT_IF_METHOD_FAILS(hr, svc->CreateScriptWrapper( rclsid, bstrCode, bstrURL, ppObj ));
  141. __HCP_END_PROPERTY(hr);
  142. }