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.

341 lines
10 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // sink.h
  6. //
  7. // rogerbo 21-May-98 Created.
  8. //
  9. // Include file for CSWbemSink
  10. //
  11. //***************************************************************************
  12. #ifndef _SINK_H_
  13. #define _SINK_H_
  14. const NUM_CONNECTION_POINTS = 1;
  15. const CCONNMAX = 8;
  16. //***************************************************************************
  17. //
  18. // CLASS NAME:
  19. //
  20. // CSWbemSink
  21. //
  22. // DESCRIPTION:
  23. //
  24. // Implements the ISWbemSink interface.
  25. //
  26. //***************************************************************************
  27. typedef struct _WbemObjectListEntry {
  28. IUnknown *pWbemObjectWrapper;
  29. IWbemServices *pServices;
  30. } WbemObjectListEntry;
  31. class CConnectionPoint;
  32. class CWbemObjectSink;
  33. class CSWbemSink : public ISWbemSink,
  34. public IConnectionPointContainer,
  35. public IProvideClassInfo2,
  36. public IObjectSafety,
  37. public ISupportErrorInfo,
  38. public ISWbemPrivateSinkLocator
  39. {
  40. private:
  41. CDispatchHelp m_Dispatch;
  42. CConnectionPoint* m_rgpConnPt[NUM_CONNECTION_POINTS];
  43. WbemObjectListEntry *m_rgpCWbemObjectSink; // One of these per outstanding operation
  44. int m_nMaxSinks;
  45. int m_nSinks;
  46. /*
  47. * Here we need to do per interface reference counting. If the ref count
  48. * of the enclosing object goes to zero, and the ref count of the enclosed
  49. * object (this one), is non zero, then we have to instigate a cancel, because
  50. * there are still outstanding operations.
  51. */
  52. class CSWbemPrivateSink : public ISWbemPrivateSink {
  53. private:
  54. CSWbemSink *m_pSink;
  55. long m_cRef;
  56. public:
  57. CSWbemPrivateSink(CSWbemSink *pSink) : m_pSink(pSink), m_cRef(0) {}
  58. void Detach() { m_pSink = NULL; }
  59. long GetRef() { return m_cRef; }
  60. // IUnknown methods
  61. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv) {
  62. if (IID_ISWbemPrivateSink==riid || IID_IUnknown==riid)
  63. {
  64. *ppv = (ISWbemPrivateSink *)(this);
  65. InterlockedIncrement(&m_cRef);
  66. return S_OK;
  67. }
  68. else if (IID_ISWbemPrivateSink==riid)
  69. {
  70. *ppv = (ISWbemPrivateSink *)(this);
  71. InterlockedIncrement(&m_cRef);
  72. return S_OK;
  73. }
  74. return ResultFromScode(E_NOINTERFACE);
  75. }
  76. STDMETHODIMP_(ULONG) AddRef(void) {
  77. InterlockedIncrement(&m_cRef);
  78. return m_cRef;
  79. }
  80. STDMETHODIMP_(ULONG) Release(void) {
  81. InterlockedDecrement(&m_cRef);
  82. if(0 == m_cRef)
  83. {
  84. delete this;
  85. return 0;
  86. }
  87. return m_cRef;
  88. }
  89. // ISWbemPrivateSink methods
  90. HRESULT STDMETHODCALLTYPE OnObjectReady(
  91. /* [in] */ IDispatch __RPC_FAR *objObject,
  92. /* [in] */ IDispatch __RPC_FAR *objAsyncContext)
  93. { return m_pSink?m_pSink->OnObjectReady(objObject, objAsyncContext):S_OK; }
  94. HRESULT STDMETHODCALLTYPE OnCompleted(
  95. /* [in] */ HRESULT iHResult,
  96. /* [in] */ IDispatch __RPC_FAR *objPath,
  97. /* [in] */ IDispatch __RPC_FAR *objErrorObject,
  98. /* [in] */ IDispatch __RPC_FAR *objAsyncContext)
  99. { return m_pSink?m_pSink->OnCompleted(iHResult, objPath, objErrorObject, objAsyncContext):S_OK; }
  100. HRESULT STDMETHODCALLTYPE OnProgress(
  101. /* [in] */ long iUpperBound,
  102. /* [in] */ long iCurrent,
  103. /* [in] */ BSTR strMessage,
  104. /* [in] */ IDispatch __RPC_FAR *objAsyncContext)
  105. { return m_pSink?m_pSink->OnProgress(iUpperBound, iCurrent, strMessage, objAsyncContext):S_OK; }
  106. HRESULT STDMETHODCALLTYPE AddObjectSink(
  107. /* [in] */ IUnknown __RPC_FAR *objWbemSink,
  108. /* [in] */ IWbemServices __RPC_FAR *objServices)
  109. { return m_pSink?m_pSink->AddObjectSink(objWbemSink, objServices):S_OK; }
  110. HRESULT STDMETHODCALLTYPE RemoveObjectSink(
  111. /* [in] */ IUnknown __RPC_FAR *objWbemSink)
  112. { return m_pSink?m_pSink->RemoveObjectSink(objWbemSink):S_OK; }
  113. } *m_pPrivateSink;
  114. protected:
  115. long m_cRef; //Object reference count
  116. public:
  117. CSWbemSink();
  118. ~CSWbemSink(void);
  119. //Non-delegating object IUnknown
  120. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  121. STDMETHODIMP_(ULONG) AddRef(void);
  122. STDMETHODIMP_(ULONG) Release(void);
  123. // IDispatch methods
  124. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
  125. {return m_Dispatch.GetTypeInfoCount(pctinfo);}
  126. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  127. {return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  128. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  129. UINT cNames, LCID lcid, DISPID* rgdispid)
  130. {return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  131. lcid,
  132. rgdispid);}
  133. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  134. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  135. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  136. {return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  137. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  138. // ISWbemSink methods
  139. HRESULT STDMETHODCALLTYPE Cancel();
  140. // IConnectionPointContainer methods
  141. HRESULT __stdcall EnumConnectionPoints(IEnumConnectionPoints** ppEnum);
  142. HRESULT __stdcall FindConnectionPoint(REFIID riid, IConnectionPoint** ppCP);
  143. // IProvideClassInfo2 methods
  144. HRESULT __stdcall GetClassInfo(ITypeInfo** pTypeInfo);
  145. HRESULT __stdcall GetGUID(DWORD dwGuidKind, GUID* pGUID);
  146. // ISWbemPrivateSink methods
  147. HRESULT STDMETHODCALLTYPE OnObjectReady(
  148. /* [in] */ IDispatch __RPC_FAR *objObject,
  149. /* [in] */ IDispatch __RPC_FAR *objAsyncContext);
  150. HRESULT STDMETHODCALLTYPE OnCompleted(
  151. /* [in] */ HRESULT iHResult,
  152. /* [in] */ IDispatch __RPC_FAR *objPath,
  153. /* [in] */ IDispatch __RPC_FAR *objErrorObject,
  154. /* [in] */ IDispatch __RPC_FAR *objAsyncContext);
  155. HRESULT STDMETHODCALLTYPE OnProgress(
  156. /* [in] */ long iUpperBound,
  157. /* [in] */ long iCurrent,
  158. /* [in] */ BSTR strMessage,
  159. /* [in] */ IDispatch __RPC_FAR *objAsyncContext);
  160. HRESULT STDMETHODCALLTYPE AddObjectSink(
  161. /* [in] */ IUnknown __RPC_FAR *objWbemSink,
  162. /* [in] */ IWbemServices __RPC_FAR *objServices);
  163. HRESULT STDMETHODCALLTYPE RemoveObjectSink(
  164. /* [in] */ IUnknown __RPC_FAR *objWbemSink);
  165. // ISWbemPrivateSinkLocator methods
  166. HRESULT STDMETHODCALLTYPE GetPrivateSink(
  167. /* [out] */ IUnknown **objWbemPrivateSink);
  168. // IObjectSafety methods
  169. HRESULT STDMETHODCALLTYPE SetInterfaceSafetyOptions
  170. (
  171. /* [in] */ REFIID riid,
  172. /* [in] */ DWORD dwOptionSetMask,
  173. /* [in] */ DWORD dwEnabledOptions
  174. )
  175. {
  176. return (dwOptionSetMask & dwEnabledOptions) ? E_FAIL : S_OK;
  177. }
  178. HRESULT STDMETHODCALLTYPE GetInterfaceSafetyOptions(
  179. /* [in] */ REFIID riid,
  180. /* [out] */ DWORD __RPC_FAR *pdwSupportedOptions,
  181. /* [out] */ DWORD __RPC_FAR *pdwEnabledOptions
  182. )
  183. {
  184. if (pdwSupportedOptions) *pdwSupportedOptions = 0;
  185. if (pdwEnabledOptions) *pdwEnabledOptions = 0;
  186. return S_OK;
  187. }
  188. // ISupportErrorInfo methods
  189. HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo
  190. (
  191. /* [in] */ REFIID riid
  192. );
  193. };
  194. class CEnumConnectionPoints : public IEnumConnectionPoints
  195. {
  196. public:
  197. // IUnknown
  198. ULONG __stdcall AddRef();
  199. ULONG __stdcall Release();
  200. HRESULT __stdcall QueryInterface(REFIID iid, void** ppv);
  201. // IEnumConnectionPoints
  202. HRESULT __stdcall Next(ULONG cConnections, IConnectionPoint** rgpcn, ULONG* pcFetched);
  203. HRESULT __stdcall Skip(ULONG cConnections);
  204. HRESULT __stdcall Reset();
  205. HRESULT __stdcall Clone(IEnumConnectionPoints** ppEnum);
  206. CEnumConnectionPoints(IUnknown* pUnkRef, void** rgpCP);
  207. ~CEnumConnectionPoints();
  208. private:
  209. long m_cRef;
  210. IUnknown* m_pUnkRef; // IUnknown for ref counting
  211. int m_iCur; // Current element
  212. IConnectionPoint* m_rgpCP[NUM_CONNECTION_POINTS]; // Array of connection points
  213. };
  214. class CConnectionPoint : public IConnectionPoint
  215. {
  216. private:
  217. long m_cRef;
  218. CSWbemSink* m_pObj;
  219. IID m_iid;
  220. int m_cConn;
  221. int m_nCookieNext;
  222. int m_nMaxConnections;
  223. unsigned *m_rgnCookies;
  224. IUnknown **m_rgpUnknown;
  225. public:
  226. CConnectionPoint(CSWbemSink* pObj, REFIID refiid);
  227. ~CConnectionPoint();
  228. // IUnknown
  229. ULONG __stdcall AddRef();
  230. ULONG __stdcall Release();
  231. HRESULT __stdcall QueryInterface(REFIID iid, void** ppv);
  232. // IConnectionPoint
  233. HRESULT __stdcall GetConnectionInterface(IID *pIID);
  234. HRESULT __stdcall GetConnectionPointContainer(IConnectionPointContainer** ppCPC);
  235. HRESULT __stdcall Advise(IUnknown* pUnknownSink, DWORD* pdwCookie);
  236. HRESULT __stdcall Unadvise(DWORD dwCookie);
  237. HRESULT __stdcall EnumConnections(IEnumConnections** ppEnum);
  238. // Other methods
  239. void OnObjectReady(
  240. /* [in] */ IDispatch __RPC_FAR *pObject,
  241. /* [in] */ IDispatch __RPC_FAR *pAsyncContext);
  242. void OnCompleted(
  243. /* [in] */ HRESULT hResult,
  244. /* [in] */ IDispatch __RPC_FAR *path,
  245. /* [in] */ IDispatch __RPC_FAR *pErrorObject,
  246. /* [in] */ IDispatch __RPC_FAR *pAsyncContext);
  247. void CConnectionPoint::OnProgress(
  248. /* [in] */ long upperBound,
  249. /* [in] */ long current,
  250. /* [in] */ BSTR message,
  251. /* [in] */ IDispatch __RPC_FAR *pAsyncContext);
  252. void UnadviseAll();
  253. };
  254. class CEnumConnections : public IEnumConnections
  255. {
  256. public:
  257. // IUnknown
  258. ULONG __stdcall AddRef();
  259. ULONG __stdcall Release();
  260. HRESULT __stdcall QueryInterface(REFIID iid, void** ppv);
  261. // IEnumConnections
  262. HRESULT __stdcall Next(ULONG cConnections, CONNECTDATA* rgpcd, ULONG* pcFetched);
  263. HRESULT __stdcall Skip(ULONG cConnections);
  264. HRESULT __stdcall Reset();
  265. HRESULT __stdcall Clone(IEnumConnections** ppEnum);
  266. CEnumConnections(IUnknown* pUnknown, int cConn, CONNECTDATA* pConnData);
  267. ~CEnumConnections();
  268. private:
  269. long m_cRef;
  270. IUnknown* m_pUnkRef; // IUnknown for ref counting
  271. unsigned m_iCur; // Current element
  272. unsigned m_cConn; // Number of connections
  273. CONNECTDATA* m_rgConnData; // Source of connections
  274. };
  275. #endif