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.

408 lines
11 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. sink.cxx
  5. Abstract:
  6. IIS DCOM Admin connection point container code for sinks
  7. Author:
  8. Sophia Chung 12-Jan-97
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. #include <iadm.h>
  13. #include "coiadm.hxx"
  14. /*---------------------------------------------------------------------------
  15. CADMCOM's nested implementation of the COM standard
  16. IConnectionPointContainer interface including Constructor, Destructor,
  17. QueryInterface, AddRef, Release, FindConnectionPoint, and
  18. EnumConnectionPoints.
  19. ---------------------------------------------------------------------------*/
  20. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  21. Method: CADMCOMW::CImpIConnectionPointContainer
  22. ::CImpIConnectionPointContainer
  23. Summary: Constructor for the CImpIConnectionPointContainer interface
  24. instantiation.
  25. Args: CADMCOMW* pBackObj,
  26. Back pointer to the parent outer object.
  27. IUnknown* pUnkOuter
  28. Pointer to the outer Unknown. For delegation.
  29. Modifies: m_pBackObj, m_pUnkOuter.
  30. Returns: void
  31. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  32. CADMCOMW::CImpIConnectionPointContainer::CImpIConnectionPointContainer()
  33. {
  34. // Init the Back Object Pointer to point to the parent object.
  35. //m_pBackObj = pBackObj;
  36. //m_pUnkOuter = pBackObj;
  37. return;
  38. }
  39. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  40. Method: CADMCOMW::CImpIConnectionPointContainer
  41. ::~CImpIConnectionPointContainer
  42. Summary: Destructor for the CImpIConnectionPointContainer interface
  43. instantiation.
  44. Args: void
  45. Modifies: .
  46. Returns: void
  47. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  48. CADMCOMW::CImpIConnectionPointContainer::~CImpIConnectionPointContainer(void)
  49. {
  50. return;
  51. }
  52. VOID CADMCOMW::CImpIConnectionPointContainer::Init(CADMCOMW *pBackObj)
  53. {
  54. // Init the Back Object Pointer to point to the parent object.
  55. m_pBackObj = pBackObj;
  56. m_pUnkOuter = (IUnknown*)pBackObj;
  57. return;
  58. }
  59. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  60. Method: CADMCOMW::CImpIConnectionPointContainer::QueryInterface
  61. Summary: The QueryInterface IUnknown member of this IPaper interface
  62. implementation that delegates to m_pUnkOuter, whatever it is.
  63. Args: REFIID riid,
  64. [in] GUID of the Interface being requested.
  65. PPVOID ppv)
  66. [out] Address of the caller's pointer variable that will
  67. receive the requested interface pointer.
  68. Modifies: .
  69. Returns: HRESULT
  70. Standard OLE result code. NOERROR for success.
  71. Returned by the delegated outer QueryInterface call.
  72. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  73. STDMETHODIMP CADMCOMW::CImpIConnectionPointContainer::QueryInterface(
  74. REFIID riid,
  75. PPVOID ppv)
  76. {
  77. // Delegate this call to the outer object's QueryInterface.
  78. return m_pUnkOuter->QueryInterface(riid, ppv);
  79. }
  80. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  81. Method: CADMCOMW::CImpIConnectionPointContainer::AddRef
  82. Summary: The AddRef IUnknown member of this IPaper interface
  83. implementation that delegates to m_pUnkOuter, whatever it is.
  84. Args: void
  85. Modifies: .
  86. Returns: ULONG
  87. Returned by the delegated outer AddRef call.
  88. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  89. STDMETHODIMP_(ULONG) CADMCOMW::CImpIConnectionPointContainer::AddRef(void)
  90. {
  91. // Delegate this call to the outer object's AddRef.
  92. return m_pUnkOuter->AddRef();
  93. }
  94. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  95. Method: CADMCOMW::CImpIConnectionPointContainer::Release
  96. Summary: The Release IUnknown member of this IPaper interface
  97. implementation that delegates to m_pUnkOuter, whatever it is.
  98. Args: void
  99. Modifies: .
  100. Returns: ULONG
  101. Returned by the delegated outer Release call.
  102. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  103. STDMETHODIMP_(ULONG) CADMCOMW::CImpIConnectionPointContainer::Release(void)
  104. {
  105. // Delegate this call to the outer object's Release.
  106. return m_pUnkOuter->Release();
  107. }
  108. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  109. Method: CADMCOMW::CImpIConnectionPointContainer::FindConnectionPoint
  110. Summary: Given an IID for a connection point sink find and return the
  111. interface pointer for that connection point sink.
  112. Args: REFIID riid
  113. Reference to an IID
  114. IConnectionPoint** ppConnPt
  115. Address of the caller's IConnectionPoint interface pointer
  116. variable that will receive the requested interface pointer.
  117. Modifies: .
  118. Returns: HRESULT
  119. Standard OLE result code. NOERROR for success.
  120. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  121. STDMETHODIMP CADMCOMW::CImpIConnectionPointContainer::FindConnectionPoint(
  122. REFIID riid,
  123. IConnectionPoint** ppConnPt)
  124. {
  125. HRESULT hr = E_NOINTERFACE;
  126. IConnectionPoint* pIConnPt;
  127. if (ppConnPt == NULL)
  128. {
  129. hr = E_INVALIDARG;
  130. goto exit;
  131. }
  132. // NULL the output variable.
  133. *ppConnPt = NULL;
  134. // This connectable CADMCOMW object currently has only the Paper Sink
  135. // connection point. If the associated interface is requested,
  136. // use QI to get the Connection Point interface and perform the
  137. // needed AddRef.
  138. if (IID_IMSAdminBaseSink_W == riid)
  139. {
  140. pIConnPt = static_cast<IConnectionPoint*>(&m_pBackObj->m_ConnectionPoint);
  141. hr = pIConnPt->QueryInterface(
  142. IID_IConnectionPoint,
  143. (PPVOID)ppConnPt);
  144. }
  145. else
  146. {
  147. hr=CONNECT_E_NOCONNECTION;
  148. }
  149. exit:
  150. return hr;
  151. }
  152. /*M+M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M+++M
  153. Method: CADMCOMW::CImpIConnectionPointContainer::EnumConnectionPoints
  154. Summary: Return Enumerator for the connectable object's contained
  155. connection points.
  156. Args: IEnumConnectionPoints** ppIEnum
  157. Address of the caller's Enumerator interface pointer
  158. variable. An output variable that will receive a pointer to
  159. the connection point enumerator COM object.
  160. Modifies: .
  161. Returns: HRESULT
  162. Standard OLE result code. NOERROR for success.
  163. M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M---M-M*/
  164. STDMETHODIMP CADMCOMW::CImpIConnectionPointContainer::EnumConnectionPoints(
  165. IEnumConnectionPoints** ppIEnum)
  166. {
  167. HRESULT hr = NOERROR;
  168. IConnectionPoint* aConnPts[1];
  169. COEnumConnectionPoints* pCOEnum;
  170. if (ppIEnum == NULL)
  171. {
  172. hr = E_INVALIDARG;
  173. goto exit;
  174. }
  175. // Zero the output interface pointer.
  176. *ppIEnum = NULL;
  177. // Make a copy on the stack of the array of connection point
  178. // interfaces. The copy is used below in the creation of the new
  179. // Enumerator object.
  180. aConnPts[0] = static_cast<IConnectionPoint*>(&m_pBackObj->m_ConnectionPoint);
  181. // Create a Connection Point enumerator COM object for the connection
  182. // points offered by this CADMCOMW object. Pass 'this' to be used to
  183. // hook the lifetime of the host object to the life time of this
  184. // enumerator object.
  185. pCOEnum = new COEnumConnectionPoints(this);
  186. if (NULL != pCOEnum)
  187. {
  188. // Use the array copy to Init the new Enumerator COM object.
  189. // Set the initial Enumerator index to 0.
  190. hr = pCOEnum->Init(1, aConnPts, 0);
  191. if (SUCCEEDED(hr))
  192. {
  193. // QueryInterface to return the requested interface pointer.
  194. // An AddRef will be conveniently done by the QI.
  195. if (SUCCEEDED(hr))
  196. {
  197. hr = pCOEnum->QueryInterface(
  198. IID_IEnumConnectionPoints,
  199. (PPVOID)ppIEnum);
  200. }
  201. }
  202. }
  203. else
  204. {
  205. hr = E_OUTOFMEMORY;
  206. }
  207. exit:
  208. return hr;
  209. }
  210. CImpIMDCOMSINKW::CImpIMDCOMSINKW(
  211. IMSAdminBaseW *pAdm
  212. )
  213. {
  214. m_dwRefCount=0;
  215. m_pAdmObj = pAdm;
  216. }
  217. CImpIMDCOMSINKW::~CImpIMDCOMSINKW()
  218. {
  219. }
  220. STDMETHODIMP
  221. CImpIMDCOMSINKW::QueryInterface(
  222. REFIID riid,
  223. VOID **ppObject)
  224. {
  225. HRESULT hr = S_OK;
  226. if ( ppObject == NULL )
  227. {
  228. hr = E_INVALIDARG;
  229. goto exit;
  230. }
  231. *ppObject = NULL;
  232. if ( riid==IID_IUnknown || riid==IID_IMDCOMSINK_W )
  233. {
  234. *ppObject = (IMDCOMSINK *) this;
  235. AddRef();
  236. }
  237. else
  238. {
  239. hr = E_NOINTERFACE;
  240. }
  241. exit:
  242. return hr;
  243. }
  244. STDMETHODIMP_(ULONG)
  245. CImpIMDCOMSINKW::AddRef()
  246. {
  247. DWORD dwRefCount;
  248. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  249. return dwRefCount;
  250. }
  251. STDMETHODIMP_(ULONG)
  252. CImpIMDCOMSINKW::Release()
  253. {
  254. DWORD dwRefCount;
  255. dwRefCount = (DWORD)InterlockedDecrement((long *)&m_dwRefCount);
  256. if ( dwRefCount == 0 )
  257. {
  258. delete this;
  259. }
  260. return dwRefCount;
  261. }
  262. STDMETHODIMP
  263. CImpIMDCOMSINKW::ComMDSinkNotify(
  264. METADATA_HANDLE hMDHandle,
  265. DWORD dwMDNumElements,
  266. MD_CHANGE_OBJECT_W __RPC_FAR pcoChangeList[])
  267. {
  268. HRESULT hr = S_OK;
  269. m_Lock.ReadLock();
  270. if ( m_pAdmObj != NULL )
  271. {
  272. hr = ((CADMCOMW *)m_pAdmObj)->NotifySinks( hMDHandle, dwMDNumElements, pcoChangeList, TRUE );
  273. }
  274. m_Lock.ReadUnlock();
  275. return hr;
  276. }
  277. STDMETHODIMP
  278. CImpIMDCOMSINKW::ComMDShutdownNotify()
  279. {
  280. HRESULT hr = S_OK;
  281. m_Lock.ReadLock();
  282. if ( m_pAdmObj != NULL )
  283. {
  284. hr = ((CADMCOMW *)m_pAdmObj)->NotifySinks( 0, 0, NULL, FALSE );
  285. }
  286. m_Lock.ReadUnlock();
  287. DetachAdminObject();
  288. return hr;
  289. }
  290. STDMETHODIMP
  291. CImpIMDCOMSINKW::ComMDEventNotify(
  292. DWORD dwMDEvent)
  293. {
  294. HRESULT hr = S_OK;
  295. if ( dwMDEvent == MD_EVENT_MID_RESTORE )
  296. {
  297. m_Lock.ReadLock();
  298. if ( m_pAdmObj != NULL )
  299. {
  300. ((CADMCOMW *)m_pAdmObj)->DisableAllHandles();
  301. }
  302. m_Lock.ReadUnlock();
  303. }
  304. return hr;
  305. }
  306. STDMETHODIMP
  307. CImpIMDCOMSINKW::DetachAdminObject()
  308. {
  309. HRESULT hr = S_OK;
  310. m_Lock.WriteLock();
  311. m_pAdmObj = NULL;
  312. m_Lock.WriteUnlock();
  313. return hr;
  314. }