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.

204 lines
5.8 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // ScriptResource.h
  7. //
  8. // Description:
  9. // CScriptResource class header file.
  10. //
  11. // Maintained By:
  12. // ozano 15-NOV-2002
  13. // gpease 14-DEC-1999
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. #pragma once
  17. //
  18. // Forward declarations
  19. //
  20. class CScriptResource;
  21. //
  22. // Message types.
  23. //
  24. typedef enum _EMESSAGE
  25. {
  26. msgUNKNOWN = 0
  27. , msgOPEN
  28. , msgCLOSE
  29. , msgONLINE
  30. , msgOFFLINE
  31. , msgTERMINATE
  32. , msgLOOKSALIVE
  33. , msgISALIVE
  34. , msgSETPRIVATEPROPERTIES
  35. , msgDIE
  36. , msgMAX
  37. } EMESSAGE;
  38. //
  39. // Mapping of message types to strings. Ordering is based on the order of the
  40. // EMESSAGE enumeration.
  41. //
  42. static WCHAR * g_rgpszScriptEntryPointNames[] =
  43. {
  44. L"<unknown>"
  45. , L"Open"
  46. , L"Close"
  47. , L"Online"
  48. , L"Offline"
  49. , L"Terminate"
  50. , L"LooksAlive"
  51. , L"IsAlive"
  52. , L"SetPrivateProperties"
  53. , L"<unknown>"
  54. , L"<unknown>"
  55. };
  56. //
  57. // CreateInstance
  58. //
  59. CScriptResource *
  60. CScriptResource_CreateInstance(
  61. LPCWSTR pszNameIn,
  62. HKEY hkeyIn,
  63. RESOURCE_HANDLE hResourceIn
  64. );
  65. //
  66. // Class CScriptResource
  67. //
  68. class
  69. CScriptResource :
  70. public IUnknown
  71. {
  72. private: // data
  73. LONG m_cRef;
  74. LPWSTR m_pszName;
  75. LPWSTR m_pszScriptFilePath;
  76. LPWSTR m_pszScriptEngine;
  77. LPWSTR m_pszHangEntryPoint;
  78. HKEY m_hkeyParams;
  79. HKEY m_hkeyResource;
  80. IActiveScriptSite * m_pass;
  81. IDispatch * m_pidm;
  82. IActiveScriptParse * m_pasp;
  83. IActiveScript * m_pas;
  84. HANDLE m_hThread;
  85. DWORD m_dwThreadId;
  86. HANDLE m_hEventWait;
  87. HANDLE m_hEventDone;
  88. LONG m_lockSerialize;
  89. HANDLE m_hScriptFile;
  90. DWORD m_dwPendingTimeout;
  91. BOOL m_fPendingTimeoutChanged;
  92. EMESSAGE m_msg; // Task to do.
  93. EMESSAGE m_msgLastExecuted; // Last executed entry point; used in telling us where the potential hang is in the script.
  94. PGENSCRIPT_PROPS m_pProps; // Property table for generic script resource.
  95. HRESULT m_hr; // Result of doing m_msg.
  96. // the following don't need to be freed, closed or released.
  97. RESOURCE_HANDLE m_hResource;
  98. DISPID m_dispidOpen;
  99. DISPID m_dispidClose;
  100. DISPID m_dispidOnline;
  101. DISPID m_dispidOffline;
  102. DISPID m_dispidTerminate;
  103. DISPID m_dispidLooksAlive;
  104. DISPID m_dispidIsAlive;
  105. BOOL m_fLastLooksAlive;
  106. BOOL m_fHangDetected;
  107. private: // methods
  108. CScriptResource( void );
  109. ~CScriptResource( void );
  110. HRESULT HrInit(
  111. LPCWSTR pszNameIn
  112. , HKEY hkeyIn
  113. , RESOURCE_HANDLE hResourceIn
  114. );
  115. HRESULT HrMakeScriptEngineAssociation( void );
  116. HRESULT HrGetScriptFilePath( void );
  117. HRESULT HrGetDispIDs( void );
  118. HRESULT HrProcessResult( VARIANT varResultIn, EMESSAGE msgIn );
  119. HRESULT HrSetHangEntryPoint( void );
  120. HRESULT HrInvoke( DISPID dispidIn, EMESSAGE msgIn, VARIANT * pvarInout = NULL, BOOL fRequiredIn = FALSE );
  121. DWORD ScTranslateVariantReturnValue( VARIANT varResultIn, VARTYPE vTypeIn );
  122. DWORD DwGetResourcePendingTimeout( void );
  123. HRESULT HrLoadScriptFile( void );
  124. HRESULT HrLoadScriptEngine( void );
  125. void UnloadScriptFile( void );
  126. void UnloadScriptEngine( void );
  127. void LogHangMode( EMESSAGE msgIn );
  128. static DWORD WINAPI S_ThreadProc( LPVOID pParam );
  129. STDMETHOD(LogError)( HRESULT hrIn, LPCWSTR pszPrefixIn );
  130. STDMETHOD(LogScriptError)( EXCEPINFO ei );
  131. HRESULT OnOpen( void );
  132. HRESULT OnClose( void );
  133. HRESULT OnOnline( void );
  134. HRESULT OnOffline( void );
  135. HRESULT OnTerminate( void );
  136. HRESULT OnLooksAlive( void );
  137. HRESULT OnIsAlive( void );
  138. DWORD OnSetPrivateProperties( PGENSCRIPT_PROPS pProps );
  139. HRESULT WaitForMessageToComplete(
  140. EMESSAGE msgIn
  141. , PGENSCRIPT_PROPS pProps = NULL
  142. );
  143. public: // methods
  144. friend CScriptResource *
  145. CScriptResource_CreateInstance( LPCWSTR pszNameIn,
  146. HKEY hkeyIn,
  147. RESOURCE_HANDLE hResourceIn
  148. );
  149. // IUnknown
  150. STDMETHOD(QueryInterface)( REFIID riid, LPVOID *ppv );
  151. STDMETHOD_(ULONG, AddRef)( void );
  152. STDMETHOD_(ULONG, Release)( void );
  153. // Publics
  154. STDMETHOD(Open)( void );
  155. STDMETHOD(Close)( void );
  156. STDMETHOD(Online)( void );
  157. STDMETHOD(Offline)( void );
  158. STDMETHOD(Terminate)( void );
  159. STDMETHOD(LooksAlive)( void );
  160. STDMETHOD(IsAlive)( void );
  161. DWORD SetPrivateProperties( PGENSCRIPT_PROPS pProps );
  162. HKEY GetRegistryParametersKey( void )
  163. {
  164. return m_hkeyParams;
  165. } //*** CScriptResource::GetRegistryParametersKey
  166. RESOURCE_HANDLE GetResourceHandle( void )
  167. {
  168. return m_hResource;
  169. } //*** CScriptResource::SetResourcePendingTimeout
  170. void SetResourcePendingTimeoutChanged( BOOL fChanged )
  171. {
  172. m_fPendingTimeoutChanged = fChanged;
  173. } //*** CScriptResource::SetResourcePendingTimeout
  174. }; //*** class CScriptResource