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.

443 lines
9.6 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // NotificationMgr.cpp
  7. //
  8. // Description:
  9. // Notification Manager implementation.
  10. //
  11. // Documentation:
  12. // Yes.
  13. //
  14. // Maintained By:
  15. // Geoffrey Pease (GPease) 22-NOV-1999
  16. //
  17. //////////////////////////////////////////////////////////////////////////////
  18. #include "pch.h"
  19. #include "ConnPointEnum.h"
  20. #include "NotificationManager.h"
  21. #include "CPINotifyUI.h"
  22. #include "CPIClusCfgCallback.h"
  23. DEFINE_THISCLASS("CNotificationManager")
  24. // ************************************************************************
  25. //
  26. // Constructor / Destructor
  27. //
  28. // ************************************************************************
  29. //////////////////////////////////////////////////////////////////////////////
  30. //
  31. // HRESULT
  32. // CNotificationManager::S_HrCreateInstance(
  33. // IUnknown ** ppunkOut
  34. // )
  35. //
  36. //////////////////////////////////////////////////////////////////////////////
  37. HRESULT
  38. CNotificationManager::S_HrCreateInstance(
  39. IUnknown ** ppunkOut
  40. )
  41. {
  42. TraceFunc( "" );
  43. Assert( ppunkOut != NULL );
  44. HRESULT hr;
  45. IServiceProvider * psp;
  46. // Don't wrap - this can fail with E_POINTER.
  47. hr = CServiceManager::S_HrGetManagerPointer( &psp );
  48. if ( SUCCEEDED( hr ) )
  49. {
  50. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager,
  51. IUnknown,
  52. ppunkOut
  53. ) );
  54. psp->Release( );
  55. } // if: service manager
  56. else if ( hr == E_POINTER )
  57. {
  58. //
  59. // This happens when the Service Manager is first started.
  60. //
  61. CNotificationManager * lpcc = new CNotificationManager( );
  62. if ( lpcc != NULL )
  63. {
  64. hr = THR( lpcc->Init( ) );
  65. if ( SUCCEEDED( hr ) )
  66. {
  67. hr = THR( lpcc->TypeSafeQI( IUnknown, ppunkOut ) );
  68. } // if: success
  69. lpcc->Release( );
  70. } // if: got object
  71. else
  72. {
  73. hr = E_OUTOFMEMORY;
  74. }
  75. } // if: service manager doesn't exist
  76. else
  77. {
  78. THR( hr );
  79. } // else:
  80. HRETURN( hr );
  81. } // S_HrCreateInstance( )
  82. //
  83. // Constructor
  84. //
  85. CNotificationManager::CNotificationManager( void )
  86. {
  87. TraceFunc( "" );
  88. InterlockedIncrement( &g_cObjects );
  89. TraceFuncExit();
  90. } // CNotificationManager( )
  91. //////////////////////////////////////////////////////////////////////////////
  92. //
  93. // STDMETHODIMP
  94. // CNotificationManager::Init( )
  95. //
  96. //////////////////////////////////////////////////////////////////////////////
  97. STDMETHODIMP
  98. CNotificationManager::Init( )
  99. {
  100. TraceFunc( "" );
  101. HRESULT hr = S_OK;
  102. IUnknown * punk = NULL;
  103. // IUnknown stuff
  104. Assert( m_cRef == 0 );
  105. AddRef( ); // Add one count
  106. // IConnectionPointContainer
  107. Assert( m_penumcp == NULL );
  108. m_penumcp = new CConnPointEnum( );
  109. if ( m_penumcp == NULL )
  110. goto OutOfMemory;
  111. hr = THR( m_penumcp->Init( ) );
  112. if ( FAILED( hr ) )
  113. goto Cleanup;
  114. hr = THR( CCPINotifyUI::S_HrCreateInstance( &punk ) );
  115. if ( FAILED( hr ) )
  116. goto Cleanup;
  117. hr = THR( m_penumcp->HrAddConnection( IID_INotifyUI, punk ) );
  118. if ( FAILED( hr ) )
  119. goto Cleanup;
  120. punk->Release( );
  121. punk = NULL;
  122. hr = THR( CCPIClusCfgCallback::S_HrCreateInstance( &punk ) );
  123. if ( FAILED( hr ) )
  124. goto Cleanup;
  125. hr = THR( m_penumcp->HrAddConnection( IID_IClusCfgCallback, punk ) );
  126. if ( FAILED( hr ) )
  127. goto Cleanup;
  128. Cleanup:
  129. if ( punk != NULL )
  130. {
  131. punk->Release( );
  132. }
  133. HRETURN( hr );
  134. OutOfMemory:
  135. hr = E_OUTOFMEMORY;
  136. goto Cleanup;
  137. } // Init( )
  138. //////////////////////////////////////////////////////////////////////////////
  139. //
  140. // CNotificationManager::~CNotificationManager( )
  141. //
  142. //////////////////////////////////////////////////////////////////////////////
  143. CNotificationManager::~CNotificationManager( )
  144. {
  145. TraceFunc( "" );
  146. if ( m_penumcp != NULL )
  147. {
  148. m_penumcp->Release( );
  149. }
  150. InterlockedDecrement( &g_cObjects );
  151. TraceFuncExit();
  152. } // ~CNotificationManager( )
  153. // ************************************************************************
  154. //
  155. // IUnknown
  156. //
  157. // ************************************************************************
  158. //////////////////////////////////////////////////////////////////////////////
  159. //
  160. // STDMETHODIMP
  161. // CNotificationManager::QueryInterface(
  162. // REFIID riid,
  163. // LPVOID *ppv
  164. // )
  165. //
  166. //////////////////////////////////////////////////////////////////////////////
  167. STDMETHODIMP
  168. CNotificationManager::QueryInterface(
  169. REFIID riid,
  170. LPVOID *ppv
  171. )
  172. {
  173. TraceQIFunc( riid, ppv );
  174. HRESULT hr = E_NOINTERFACE;
  175. if ( IsEqualIID( riid, IID_IUnknown ) )
  176. {
  177. *ppv = static_cast< INotificationManager * >( this );
  178. hr = S_OK;
  179. } // if: IUnknown
  180. else if ( IsEqualIID( riid, IID_INotificationManager ) )
  181. {
  182. *ppv = TraceInterface( __THISCLASS__, INotificationManager, this, 0 );
  183. hr = S_OK;
  184. } // else if: INotificationManager
  185. else if ( IsEqualIID( riid, IID_IConnectionPointContainer ) )
  186. {
  187. *ppv = TraceInterface( __THISCLASS__, IConnectionPointContainer, this, 0 );
  188. hr = S_OK;
  189. } // else if: IConnectionPointContainer
  190. if ( SUCCEEDED( hr ) )
  191. {
  192. ((IUnknown*) *ppv)->AddRef( );
  193. } // if: success
  194. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  195. } // QueryInterface( )
  196. //////////////////////////////////////////////////////////////////////////////
  197. //
  198. // STDMETHODIMP_(ULONG)
  199. // CNotificationManager::AddRef( void )
  200. //
  201. //////////////////////////////////////////////////////////////////////////////
  202. STDMETHODIMP_(ULONG)
  203. CNotificationManager::AddRef( void )
  204. {
  205. TraceFunc( "[IUnknown]" );
  206. InterlockedIncrement( &m_cRef );
  207. RETURN( m_cRef );
  208. } // AddRef( )
  209. //////////////////////////////////////////////////////////////////////////////
  210. //
  211. // STDMETHODIMP_(ULONG)
  212. // CNotificationManager::Release( void )
  213. //
  214. //////////////////////////////////////////////////////////////////////////////
  215. STDMETHODIMP_(ULONG)
  216. CNotificationManager::Release( void )
  217. {
  218. TraceFunc( "[IUnknown]" );
  219. InterlockedDecrement( &m_cRef );
  220. if ( m_cRef )
  221. RETURN( m_cRef );
  222. TraceDo( delete this );
  223. RETURN(0);
  224. } // Release( )
  225. // ************************************************************************
  226. //
  227. // INotificationManager
  228. //
  229. // ************************************************************************
  230. //////////////////////////////////////////////////////////////////////////////
  231. //
  232. // STDMETHODIMP
  233. // CNotificationManager::AddConnectionPoint(
  234. // REFIID riidIn,
  235. // IConnectionPoint * pcpIn
  236. // )
  237. //
  238. //////////////////////////////////////////////////////////////////////////////
  239. STDMETHODIMP
  240. CNotificationManager::AddConnectionPoint(
  241. REFIID riidIn,
  242. IConnectionPoint * pcpIn
  243. )
  244. {
  245. TraceFunc( "[INotificationManager]" );
  246. HRESULT hr;
  247. hr = THR( m_penumcp->HrAddConnection( riidIn, pcpIn ) );
  248. HRETURN( hr );
  249. } // AddConnectionPoint( )
  250. // ************************************************************************
  251. //
  252. // IConnectionPointContainer
  253. //
  254. // ************************************************************************
  255. //////////////////////////////////////////////////////////////////////////////
  256. //
  257. // STDMETHODIMP
  258. // CNotificationManager::EnumConnectionPoints(
  259. // IEnumConnectionPoints **ppEnumOut
  260. // )
  261. //
  262. //////////////////////////////////////////////////////////////////////////////
  263. STDMETHODIMP
  264. CNotificationManager::EnumConnectionPoints(
  265. IEnumConnectionPoints **ppEnumOut
  266. )
  267. {
  268. TraceFunc( "[IConnectionPointContainer]" );
  269. HRESULT hr = E_UNEXPECTED;
  270. if ( ppEnumOut == NULL )
  271. goto InvalidPointer;
  272. if ( m_penumcp != NULL )
  273. {
  274. hr = THR( m_penumcp->Clone( ppEnumOut ) );
  275. if ( FAILED( hr ) )
  276. goto Cleanup;
  277. }
  278. Cleanup:
  279. HRETURN( hr );
  280. InvalidPointer:
  281. hr = THR( E_POINTER );
  282. goto Cleanup;
  283. } // EnumConnectionPoints( )
  284. //////////////////////////////////////////////////////////////////////////////
  285. //
  286. // STDMETHODIMP
  287. // CNotificationManager::FindConnectionPoint(
  288. // REFIID riidIn,
  289. // IConnectionPoint **ppCPOut
  290. // )
  291. //
  292. //////////////////////////////////////////////////////////////////////////////
  293. STDMETHODIMP
  294. CNotificationManager::FindConnectionPoint(
  295. REFIID riidIn,
  296. IConnectionPoint **ppCPOut
  297. )
  298. {
  299. TraceFunc( "[IConnectionPointContainer]" );
  300. IID iid;
  301. HRESULT hr = E_UNEXPECTED;
  302. IConnectionPoint * pcp = NULL;
  303. if ( ppCPOut == NULL )
  304. goto InvalidPointer;
  305. hr = THR( m_penumcp->Reset( ) );
  306. if ( FAILED( hr ) )
  307. goto Cleanup;
  308. for ( ; ; ) // ever
  309. {
  310. if ( pcp != NULL )
  311. {
  312. pcp->Release( );
  313. pcp = NULL;
  314. }
  315. hr = STHR( m_penumcp->Next( 1, &pcp, NULL ) );
  316. if ( FAILED( hr ) )
  317. goto Cleanup;
  318. if ( hr == S_FALSE )
  319. {
  320. hr = THR( CONNECT_E_NOCONNECTION );
  321. break; // exit condition
  322. }
  323. hr = THR( pcp->GetConnectionInterface( &iid ) );
  324. if ( FAILED( hr ) )
  325. continue; // ignore it
  326. if ( iid != riidIn )
  327. continue; // not the right interface
  328. //
  329. // Found it. Give up ownership and exit loop.
  330. //
  331. *ppCPOut = pcp;
  332. pcp = NULL;
  333. hr = S_OK;
  334. break;
  335. }
  336. Cleanup:
  337. if ( pcp != NULL )
  338. {
  339. pcp->Release( );
  340. }
  341. HRETURN( hr );
  342. InvalidPointer:
  343. hr = THR( E_POINTER );
  344. goto Cleanup;
  345. } // FindConnectionPoint( )