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.

249 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995
  5. //
  6. // File: localobj.h
  7. //
  8. // Contents: Contains class definitions of objects used in the remoteable
  9. // object proxy object.
  10. //
  11. //----------------------------------------------------------------------------
  12. class CLocalMTProxy;
  13. //+---------------------------------------------------------------------------
  14. //
  15. // Class: CMTLocalFactory
  16. //
  17. // Purpose: Standard implementation of a class factory. This is meant
  18. // to be created as a global object and therefore does not
  19. // destroy itself when its refcount goes to zero.
  20. //
  21. //----------------------------------------------------------------------------
  22. class CMTLocalFactory : public IClassFactory
  23. {
  24. public:
  25. CMTLocalFactory();
  26. ~CMTLocalFactory() {};
  27. // IUnknown methods
  28. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv);
  29. STDMETHOD_(ULONG, AddRef) (void)
  30. {
  31. return InterlockedIncrement((long*)&_ulRefs);
  32. }
  33. STDMETHOD_(ULONG, Release) (void)
  34. {
  35. if (InterlockedDecrement((long*)&_ulRefs) == 0)
  36. {
  37. return 0;
  38. }
  39. return _ulRefs;
  40. }
  41. // IClassFactory methods
  42. STDMETHOD(CreateInstance)(IUnknown *pUnkOuter, REFIID riid, void ** ppvObject);
  43. STDMETHOD(LockServer)(BOOL fLock);
  44. private:
  45. ULONG _ulRefs;
  46. };
  47. //+---------------------------------------------------------------------------
  48. //
  49. // Class: CMTEventSink (ces)
  50. //
  51. // Purpose: Class which sinks events from the remote object
  52. //
  53. //----------------------------------------------------------------------------
  54. class CMTEventSink : public IDispatch
  55. {
  56. public:
  57. DECLARE_MEMCLEAR_NEW_DELETE();
  58. CMTEventSink() { }
  59. ~CMTEventSink() { }
  60. // IUnknown methods
  61. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv);
  62. STDMETHOD_(ULONG, AddRef) (void);
  63. STDMETHOD_(ULONG, Release) (void);
  64. // IDispatch interface
  65. STDMETHOD(GetTypeInfoCount)(UINT FAR* pctinfo);
  66. STDMETHOD(GetTypeInfo)(
  67. UINT itinfo,
  68. LCID lcid,
  69. ITypeInfo FAR* FAR* pptinfo);
  70. STDMETHOD(GetIDsOfNames)(
  71. REFIID riid,
  72. OLECHAR FAR* FAR* rgszNames,
  73. UINT cNames,
  74. LCID lcid,
  75. DISPID FAR* rgdispid);
  76. STDMETHOD(Invoke)(
  77. DISPID dispidMember,
  78. REFIID riid,
  79. LCID lcid,
  80. WORD wFlags,
  81. DISPPARAMS FAR* pdispparams,
  82. VARIANT FAR* pvarResult,
  83. EXCEPINFO FAR* pexcepinfo,
  84. UINT FAR* puArgErr);
  85. private:
  86. CLocalMTProxy* Proxy();
  87. };
  88. //+---------------------------------------------------------------------------
  89. //
  90. // Class: CLocalMTProxy (cm)
  91. //
  92. // Purpose: Contains all useful info about a machine and what it's
  93. // doing.
  94. //
  95. // Notes: This class is manipulated from multiple threads. All
  96. // member functions must be thread safe!
  97. //
  98. // This is the class that is created by the class factory and
  99. // handed out as a remote object to other machines. It has no
  100. // real code in itself but merely provides a way to talk to the
  101. // already running script engines.
  102. //
  103. //----------------------------------------------------------------------------
  104. class CLocalMTProxy : public IRemoteMTScriptProxy,
  105. public IConnectionPointContainer,
  106. public IProvideClassInfo
  107. {
  108. friend class CLocalProxyCP;
  109. friend class CMTEventSink;
  110. public:
  111. DECLARE_MEMCLEAR_NEW_DELETE();
  112. CLocalMTProxy();
  113. ~CLocalMTProxy();
  114. // IUnknown methods. Because we have a refcounted sub-object (our event
  115. // sink) we must do more complicated object lifetime stuff here.
  116. STDMETHOD(QueryInterface) (REFIID riid, LPVOID * ppv);
  117. STDMETHOD_(ULONG, AddRef) (void);
  118. STDMETHOD_(ULONG, Release) (void);
  119. ULONG SubAddRef (void);
  120. ULONG SubRelease (void);
  121. void Passivate(void);
  122. // IDispatch interface
  123. STDMETHOD(GetTypeInfoCount)(UINT FAR* pctinfo);
  124. STDMETHOD(GetTypeInfo)(
  125. UINT itinfo,
  126. LCID lcid,
  127. ITypeInfo FAR* FAR* pptinfo);
  128. STDMETHOD(GetIDsOfNames)(
  129. REFIID riid,
  130. OLECHAR FAR* FAR* rgszNames,
  131. UINT cNames,
  132. LCID lcid,
  133. DISPID FAR* rgdispid);
  134. STDMETHOD(Invoke)(
  135. DISPID dispidMember,
  136. REFIID riid,
  137. LCID lcid,
  138. WORD wFlags,
  139. DISPPARAMS FAR* pdispparams,
  140. VARIANT FAR* pvarResult,
  141. EXCEPINFO FAR* pexcepinfo,
  142. UINT FAR* puArgErr);
  143. // IConnectionPointContainer methods
  144. STDMETHOD(EnumConnectionPoints)(LPENUMCONNECTIONPOINTS*);
  145. STDMETHOD(FindConnectionPoint)(REFIID, LPCONNECTIONPOINT*);
  146. // IProvideClassInfo methods
  147. STDMETHOD(GetClassInfo)(ITypeInfo **pTI);
  148. // IRemoteMTScriptProxy interface
  149. STDMETHOD(Connect)(BSTR bstrMachine);
  150. STDMETHOD(Disconnect)();
  151. STDMETHOD(DownloadFile)(BSTR bstrURL, BSTR *bstrFile);
  152. HRESULT LoadTypeLibs();
  153. private:
  154. DWORD _ulAllRefs;
  155. DWORD _ulRefs;
  156. ITypeLib * _pTypeLibDLL;
  157. ITypeInfo * _pTypeInfoInterface;
  158. ITypeInfo * _pTypeInfoCM;
  159. IDispatch * _pDispRemote;
  160. DWORD _dwSinkCookie;
  161. CMTEventSink _cesSink;
  162. IDispatch* _pDispSink;
  163. };
  164. inline CLocalMTProxy * CMTEventSink::Proxy()
  165. {
  166. return CONTAINING_RECORD(this, CLocalMTProxy, _cesSink);
  167. }
  168. inline STDMETHODIMP_(ULONG)
  169. CMTEventSink::AddRef(void)
  170. {
  171. return Proxy()->SubAddRef();
  172. }
  173. inline STDMETHODIMP_(ULONG)
  174. CMTEventSink::Release(void)
  175. {
  176. return Proxy()->SubRelease();
  177. }
  178. //+---------------------------------------------------------------------------
  179. //
  180. // Class: CLocalProxyCP (mcp)
  181. //
  182. // Purpose: Implements IConnectionPoint for CLocalMTProxy
  183. //
  184. //----------------------------------------------------------------------------
  185. class CLocalProxyCP : public IConnectionPoint
  186. {
  187. public:
  188. CLocalProxyCP(CLocalMTProxy *pMTP);
  189. ~CLocalProxyCP();
  190. DECLARE_STANDARD_IUNKNOWN(CLocalProxyCP);
  191. STDMETHOD(GetConnectionInterface)(IID * pIID);
  192. STDMETHOD(GetConnectionPointContainer)(IConnectionPointContainer ** ppCPC);
  193. STDMETHOD(Advise)(LPUNKNOWN pUnkSink, DWORD * pdwCookie);
  194. STDMETHOD(Unadvise)(DWORD dwCookie);
  195. STDMETHOD(EnumConnections)(LPENUMCONNECTIONS * ppEnum);
  196. CLocalMTProxy *_pMTProxy;
  197. };
  198. extern HINSTANCE g_hInstDll;
  199. extern long g_lObjectCount;