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.

258 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name :
  4. mbsink.cxx
  5. Abstract:
  6. This module implements the metabase notification support
  7. Author:
  8. Johnl 01-Nov-1996
  9. Project:
  10. Internet Services Common DLL
  11. Functions Exported:
  12. Revision History:
  13. --*/
  14. #include <tcpdllp.hxx>
  15. #include <objbase.h>
  16. #include <initguid.h>
  17. #include <ole2.h>
  18. #include <imd.h>
  19. #include <iistypes.hxx>
  20. #include <issched.hxx>
  21. //
  22. // Constants
  23. //
  24. //
  25. // Derived metadata sink object
  26. //
  27. class CImpIMDCOMSINK : public IMDCOMSINK {
  28. public:
  29. CImpIMDCOMSINK();
  30. ~CImpIMDCOMSINK();
  31. HRESULT _stdcall
  32. QueryInterface(REFIID riid, void **ppObject);
  33. ULONG _stdcall
  34. AddRef();
  35. ULONG _stdcall
  36. Release();
  37. HRESULT STDMETHODCALLTYPE ComMDSinkNotify(
  38. /* [in] */ METADATA_HANDLE hMDHandle,
  39. /* [in] */ DWORD dwMDNumElements,
  40. /* [size_is][in] */ MD_CHANGE_OBJECT __RPC_FAR pcoChangeList[ ]);
  41. HRESULT STDMETHODCALLTYPE ComMDShutdownNotify()
  42. {
  43. return RETURNCODETOHRESULT(ERROR_NOT_SUPPORTED);
  44. }
  45. private:
  46. ULONG m_dwRefCount;
  47. };
  48. //
  49. // Globals
  50. //
  51. DWORD g_dwSinkCookie = 0;
  52. CImpIMDCOMSINK * g_pEventSink = NULL;
  53. IConnectionPoint * g_pConnPoint = NULL;
  54. //
  55. // Functions
  56. //
  57. BOOL
  58. InitializeMetabaseSink(
  59. IUnknown * pmb
  60. )
  61. {
  62. IConnectionPointContainer * pConnPointContainer = NULL;
  63. HRESULT hRes;
  64. BOOL fSinkConnected = FALSE;
  65. g_pEventSink = new CImpIMDCOMSINK();
  66. if ( !g_pEventSink )
  67. {
  68. return FALSE;
  69. }
  70. //
  71. // First query the object for its Connection Point Container. This
  72. // essentially asks the object in the server if it is connectable.
  73. //
  74. hRes = pmb->QueryInterface( IID_IConnectionPointContainer,
  75. (PVOID *)&pConnPointContainer);
  76. if SUCCEEDED(hRes)
  77. {
  78. // Find the requested Connection Point. This AddRef's the
  79. // returned pointer.
  80. hRes = pConnPointContainer->FindConnectionPoint( IID_IMDCOMSINK,
  81. &g_pConnPoint);
  82. if (SUCCEEDED(hRes))
  83. {
  84. hRes = g_pConnPoint->Advise( (IUnknown *)g_pEventSink,
  85. &g_dwSinkCookie);
  86. if (SUCCEEDED(hRes))
  87. {
  88. fSinkConnected = TRUE;
  89. }
  90. }
  91. if ( pConnPointContainer )
  92. {
  93. pConnPointContainer->Release();
  94. pConnPointContainer = NULL;
  95. }
  96. }
  97. if ( !fSinkConnected )
  98. {
  99. delete g_pEventSink;
  100. g_pEventSink = NULL;
  101. }
  102. return fSinkConnected;
  103. }
  104. VOID
  105. TerminateMetabaseSink(
  106. VOID
  107. )
  108. {
  109. HRESULT hRes;
  110. DBGPRINTF(( DBG_CONTEXT,
  111. "[TerminateMetabaseSink] Cleaning up sinc notification\n" ));
  112. if ( g_dwSinkCookie )
  113. {
  114. hRes = g_pConnPoint->Unadvise( g_dwSinkCookie );
  115. }
  116. g_pEventSink = NULL;
  117. }
  118. CImpIMDCOMSINK::CImpIMDCOMSINK()
  119. {
  120. m_dwRefCount=0;
  121. }
  122. CImpIMDCOMSINK::~CImpIMDCOMSINK()
  123. {
  124. }
  125. HRESULT
  126. CImpIMDCOMSINK::QueryInterface(REFIID riid, void **ppObject) {
  127. if (riid==IID_IUnknown || riid==IID_IMDCOMSINK) {
  128. *ppObject = (IMDCOMSINK *) this;
  129. }
  130. else {
  131. return E_NOINTERFACE;
  132. }
  133. AddRef();
  134. return NO_ERROR;
  135. }
  136. ULONG
  137. CImpIMDCOMSINK::AddRef()
  138. {
  139. DWORD dwRefCount;
  140. dwRefCount = InterlockedIncrement((long *)&m_dwRefCount);
  141. return dwRefCount;
  142. }
  143. ULONG
  144. CImpIMDCOMSINK::Release()
  145. {
  146. DWORD dwRefCount;
  147. dwRefCount = InterlockedDecrement((long *)&m_dwRefCount);
  148. if (dwRefCount == 0) {
  149. delete this;
  150. }
  151. return dwRefCount;
  152. }
  153. HRESULT STDMETHODCALLTYPE
  154. CImpIMDCOMSINK::ComMDSinkNotify(
  155. /* [in] */ METADATA_HANDLE hMDHandle,
  156. /* [in] */ DWORD dwMDNumElements,
  157. /* [size_is][in] */ MD_CHANGE_OBJECT __RPC_FAR pcoChangeList[ ])
  158. {
  159. DWORD i, j;
  160. IIS_SERVICE::MDChangeNotify( dwMDNumElements,
  161. pcoChangeList );
  162. #if 0
  163. DBGPRINTF(( DBG_CONTEXT,
  164. "Recieved callback for handle 0x%08x, NumElements = %d\n",
  165. hMDHandle,
  166. dwMDNumElements ));
  167. for (i = 0; i < dwMDNumElements; i++)
  168. {
  169. DBGPRINTF(( DBG_CONTEXT,
  170. "Change Type = %X, Path = %s, NumIDs = %d\n",
  171. pcoChangeList[i].dwMDChangeType,
  172. pcoChangeList[i].pszMDPath,
  173. pcoChangeList[i].dwMDNumDataIDs ));
  174. for ( j = 0; j < pcoChangeList[i].dwMDNumDataIDs; j++ )
  175. {
  176. DBGPRINTF(( DBG_CONTEXT,
  177. "\tid[j] = %6d ",
  178. pcoChangeList[i].pdwMDDataIDs[j] ));
  179. }
  180. DBGPRINTF(( DBG_CONTEXT,
  181. "\n" ));
  182. }
  183. #endif
  184. return (0);
  185. }