Source code of Windows XP (NT5)
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.

78 lines
3.7 KiB

  1. // Copyright (c) 1999 Microsoft Corporation. All rights reserved.
  2. //
  3. // Declaration of CSingleThreadedScriptManager.
  4. // Wraps CActiveScriptManager to accept calls from multiple scripts and behind the
  5. // scenes farms them out to a single worker thread that actually talks to the script engine.
  6. //
  7. // The virtual base class ScriptManager can be used to talk to either
  8. // CActiveScriptManager or CSingleThreadedActiveScriptManager.
  9. //
  10. #pragma once
  11. #include "workthread.h"
  12. // forward declaration
  13. class CDirectMusicScript;
  14. class ScriptManager
  15. {
  16. public:
  17. virtual HRESULT Start(DMUS_SCRIPT_ERRORINFO *pErrorInfo) = 0;
  18. virtual HRESULT CallRoutine(const WCHAR *pwszRoutineName, DMUS_SCRIPT_ERRORINFO *pErrorInfo) = 0;
  19. virtual HRESULT ScriptTrackCallRoutine(
  20. const WCHAR *pwszRoutineName,
  21. IDirectMusicSegmentState *pSegSt,
  22. DWORD dwVirtualTrackID,
  23. bool fErrorPMsgsEnabled,
  24. __int64 i64IntendedStartTime,
  25. DWORD dwIntendedStartTimeFlags) = 0;
  26. virtual HRESULT SetVariable(const WCHAR *pwszVariableName, VARIANT varValue, bool fSetRef, DMUS_SCRIPT_ERRORINFO *pErrorInfo) = 0;
  27. virtual HRESULT GetVariable(const WCHAR *pwszVariableName, VARIANT *pvarValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo) = 0;
  28. virtual HRESULT EnumItem(bool fRoutine, DWORD dwIndex, WCHAR *pwszName, int *pcItems) = 0; // fRoutine true to get a routine, false to get a variable. pcItems (if supplied) is set to the total number of items
  29. virtual HRESULT DispGetIDsOfNames(REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId) = 0;
  30. virtual HRESULT DispInvoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr) = 0;
  31. virtual void Close() = 0;
  32. STDMETHOD_(ULONG, Release)() = 0;
  33. };
  34. // VBScript (and likely any other scripting languages besides our custom engine) fails if called from different threads.
  35. // This class wraps such an engine, providing a ScriptManager interface that can be called from multiple threads but marshals
  36. // all the calls to the engine onto a single worker thread.
  37. class CSingleThreadedScriptManager : public ScriptManager
  38. {
  39. public:
  40. // The worker thread needs to be cleaned up using the static member function before the .dll is unloaded.
  41. static void TerminateThread() { ms_Thread.Terminate(true); }
  42. CSingleThreadedScriptManager(
  43. bool fUseOleAut,
  44. const WCHAR *pwszLanguage,
  45. const WCHAR *pwszSource,
  46. CDirectMusicScript *pParentScript,
  47. HRESULT *phr,
  48. DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  49. HRESULT Start(DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  50. HRESULT CallRoutine(const WCHAR *pwszRoutineName, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  51. HRESULT ScriptTrackCallRoutine(
  52. const WCHAR *pwszRoutineName,
  53. IDirectMusicSegmentState *pSegSt,
  54. DWORD dwVirtualTrackID,
  55. bool fErrorPMsgsEnabled,
  56. __int64 i64IntendedStartTime,
  57. DWORD dwIntendedStartTimeFlags);
  58. HRESULT SetVariable(const WCHAR *pwszVariableName, VARIANT varValue, bool fSetRef, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  59. HRESULT GetVariable(const WCHAR *pwszVariableName, VARIANT *pvarValue, DMUS_SCRIPT_ERRORINFO *pErrorInfo);
  60. HRESULT EnumItem(bool fRoutine, DWORD dwIndex, WCHAR *pwszName, int *pcItems);
  61. HRESULT DispGetIDsOfNames(REFIID riid, LPOLESTR __RPC_FAR *rgszNames, UINT cNames, LCID lcid, DISPID __RPC_FAR *rgDispId);
  62. HRESULT DispInvoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS __RPC_FAR *pDispParams, VARIANT __RPC_FAR *pVarResult, EXCEPINFO __RPC_FAR *pExcepInfo, UINT __RPC_FAR *puArgErr);
  63. void Close();
  64. STDMETHOD_(ULONG, Release)();
  65. private:
  66. friend void F_Create(void *pvParams);
  67. static CWorkerThread ms_Thread;
  68. ScriptManager *m_pScriptManager;
  69. };