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.

596 lines
13 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CPINotifyUI.cpp
  7. //
  8. // Description:
  9. // INotifyUI Connection Point implementation.
  10. //
  11. // Maintained By:
  12. // David Potter (DavidP) 14-JUN-2001
  13. // Geoffrey Pease (GPease) 04-AUG-2000
  14. //
  15. //////////////////////////////////////////////////////////////////////////////
  16. #include "Pch.h"
  17. #include "CPINotifyUI.h"
  18. #include "EnumCPINotifyUI.h"
  19. DEFINE_THISCLASS("CCPINotifyUI")
  20. // ************************************************************************
  21. //
  22. // Constructor / Destructor
  23. //
  24. // ************************************************************************
  25. //////////////////////////////////////////////////////////////////////////////
  26. //
  27. // HRESULT
  28. // CCPINotifyUI::S_HrCreateInstance(
  29. // IUnknown ** ppunkOut
  30. // )
  31. //
  32. //////////////////////////////////////////////////////////////////////////////
  33. HRESULT
  34. CCPINotifyUI::S_HrCreateInstance(
  35. IUnknown ** ppunkOut
  36. )
  37. {
  38. TraceFunc( "" );
  39. HRESULT hr = S_OK;
  40. CCPINotifyUI * pcc = NULL;
  41. Assert( ppunkOut != NULL );
  42. if ( ppunkOut == NULL )
  43. {
  44. hr = THR( E_POINTER );
  45. goto Cleanup;
  46. }
  47. pcc = new CCPINotifyUI();
  48. if ( pcc == NULL )
  49. {
  50. hr = THR( E_OUTOFMEMORY );
  51. goto Cleanup;
  52. }
  53. hr = THR( pcc->HrInit() );
  54. if ( FAILED( hr ) )
  55. {
  56. goto Cleanup;
  57. }
  58. hr = THR( pcc->TypeSafeQI( IUnknown, ppunkOut ) );
  59. if ( FAILED( hr ) )
  60. {
  61. goto Cleanup;
  62. }
  63. Cleanup:
  64. if ( pcc != NULL )
  65. {
  66. pcc->Release();
  67. }
  68. HRETURN( hr );
  69. } //*** CCPINotifyUI::S_HrCreateInstance
  70. //////////////////////////////////////////////////////////////////////////////
  71. //++
  72. //
  73. // CCPINotifyUI::CCPINotifyUI
  74. //
  75. // Description:
  76. // Default constructor.
  77. //
  78. // Arguments:
  79. // None.
  80. //
  81. // Return Values:
  82. // None.
  83. //
  84. //--
  85. //////////////////////////////////////////////////////////////////////////////
  86. CCPINotifyUI::CCPINotifyUI( void )
  87. : m_cRef( 1 )
  88. {
  89. TraceFunc( "" );
  90. InterlockedIncrement( &g_cObjects );
  91. TraceFuncExit();
  92. } //*** CCPINotifyUI::CCPINotifyUI
  93. //////////////////////////////////////////////////////////////////////////////
  94. //
  95. // STDMETHODIMP
  96. // CCPINotifyUI::HrInit
  97. //
  98. //////////////////////////////////////////////////////////////////////////////
  99. STDMETHODIMP
  100. CCPINotifyUI::HrInit( void )
  101. {
  102. TraceFunc( "" );
  103. HRESULT hr = S_OK;
  104. // IUnknown stuff
  105. Assert( m_cRef == 1 );
  106. // IConnectionPoint
  107. Assert( m_penum == NULL );
  108. m_penum = new CEnumCPINotifyUI();
  109. if ( m_penum == NULL )
  110. {
  111. hr = THR( E_OUTOFMEMORY );
  112. goto Cleanup;
  113. } // if:
  114. hr = THR( m_penum->HrInit() );
  115. if ( FAILED( hr ) )
  116. {
  117. goto Cleanup;
  118. } // if:
  119. // INotifyUI
  120. Cleanup:
  121. HRETURN( hr );
  122. } //*** CCPINotifyUI::HrInit
  123. //////////////////////////////////////////////////////////////////////////////
  124. //
  125. // CCPINotifyUI::~CCPINotifyUI
  126. //
  127. //////////////////////////////////////////////////////////////////////////////
  128. CCPINotifyUI::~CCPINotifyUI( void )
  129. {
  130. TraceFunc( "" );
  131. if ( m_penum != NULL )
  132. {
  133. m_penum->Release();
  134. } // if:
  135. InterlockedDecrement( &g_cObjects );
  136. TraceFuncExit();
  137. } //*** CCPINotifyUI::~CCPINotifyUI
  138. // ************************************************************************
  139. //
  140. // IUnknown
  141. //
  142. // ************************************************************************
  143. //////////////////////////////////////////////////////////////////////////////
  144. //++
  145. //
  146. // CCPINotifyUI::QueryInterface
  147. //
  148. // Description:
  149. // Query this object for the passed in interface.
  150. //
  151. // Arguments:
  152. // riidIn
  153. // Id of interface requested.
  154. //
  155. // ppvOut
  156. // Pointer to the requested interface.
  157. //
  158. // Return Value:
  159. // S_OK
  160. // If the interface is available on this object.
  161. //
  162. // E_NOINTERFACE
  163. // If the interface is not available.
  164. //
  165. // E_POINTER
  166. // ppvOut was NULL.
  167. //
  168. // Remarks:
  169. // None.
  170. //
  171. //--
  172. //////////////////////////////////////////////////////////////////////////////
  173. STDMETHODIMP
  174. CCPINotifyUI::QueryInterface(
  175. REFIID riidIn
  176. , LPVOID * ppvOut
  177. )
  178. {
  179. TraceQIFunc( riidIn, ppvOut );
  180. HRESULT hr = S_OK;
  181. //
  182. // Validate arguments.
  183. //
  184. Assert( ppvOut != NULL );
  185. if ( ppvOut == NULL )
  186. {
  187. hr = THR( E_POINTER );
  188. goto Cleanup;
  189. }
  190. //
  191. // Handle known interfaces.
  192. //
  193. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  194. {
  195. *ppvOut = static_cast< IConnectionPoint * >( this );
  196. } // if: IUnknown
  197. else if ( IsEqualIID( riidIn, IID_IConnectionPoint ) )
  198. {
  199. *ppvOut = TraceInterface( __THISCLASS__, IConnectionPoint, this, 0 );
  200. } // else if: IConnectionPoint
  201. else if ( IsEqualIID( riidIn, IID_INotifyUI ) )
  202. {
  203. *ppvOut = TraceInterface( __THISCLASS__, INotifyUI, this, 0 );
  204. } // else if: INotifyUI
  205. else
  206. {
  207. *ppvOut = NULL;
  208. hr = E_NOINTERFACE;
  209. } // else
  210. //
  211. // Add a reference to the interface if successful.
  212. //
  213. if ( SUCCEEDED( hr ) )
  214. {
  215. ((IUnknown*) *ppvOut)->AddRef();
  216. } // if: success
  217. Cleanup:
  218. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  219. } //*** CCPINotifyUI::QueryInterface
  220. //////////////////////////////////////////////////////////////////////////////
  221. //
  222. // STDMETHODIMP_(ULONG)
  223. // CCPINotifyUI::AddRef
  224. //
  225. //////////////////////////////////////////////////////////////////////////////
  226. STDMETHODIMP_( ULONG )
  227. CCPINotifyUI::AddRef( void )
  228. {
  229. TraceFunc( "[IUnknown]" );
  230. InterlockedIncrement( &m_cRef );
  231. CRETURN( m_cRef );
  232. } //*** CCPINotifyUI::AddRef
  233. //////////////////////////////////////////////////////////////////////////////
  234. //
  235. // STDMETHODIMP_(ULONG)
  236. // CCPINotifyUI::Release
  237. //
  238. //////////////////////////////////////////////////////////////////////////////
  239. STDMETHODIMP_( ULONG )
  240. CCPINotifyUI::Release( void )
  241. {
  242. TraceFunc( "[IUnknown]" );
  243. LONG cRef;
  244. cRef = InterlockedDecrement( &m_cRef );
  245. if ( cRef == 0 )
  246. {
  247. TraceDo( delete this );
  248. }
  249. CRETURN( cRef );
  250. } //*** CCPINotifyUI::Release
  251. // ************************************************************************
  252. //
  253. // IConnectionPoint
  254. //
  255. // ************************************************************************
  256. //////////////////////////////////////////////////////////////////////////////
  257. //
  258. // STDMETHODIMP
  259. // CCPINotifyUI::GetConnectionInterface(
  260. // IID * pIIDOut
  261. // )
  262. //
  263. //////////////////////////////////////////////////////////////////////////////
  264. STDMETHODIMP
  265. CCPINotifyUI::GetConnectionInterface(
  266. IID * pIIDOut
  267. )
  268. {
  269. TraceFunc( "[IConnectionPoint] pIIDOut" );
  270. HRESULT hr = S_OK;
  271. if ( pIIDOut == NULL )
  272. goto InvalidPointer;
  273. *pIIDOut = IID_INotifyUI;
  274. Cleanup:
  275. HRETURN( hr );
  276. InvalidPointer:
  277. hr = THR( E_POINTER );
  278. goto Cleanup;
  279. } //*** CCPINotifyUI::GetConnectionInterface
  280. //////////////////////////////////////////////////////////////////////////////
  281. //
  282. // STDMETHODIMP
  283. // CCPINotifyUI::GetConnectionPointContainer(
  284. // IConnectionPointContainer * * ppcpcOut
  285. // )
  286. //
  287. //////////////////////////////////////////////////////////////////////////////
  288. STDMETHODIMP
  289. CCPINotifyUI::GetConnectionPointContainer(
  290. IConnectionPointContainer * * ppcpcOut
  291. )
  292. {
  293. TraceFunc( "[IConnectionPoint] ppcpcOut" );
  294. HRESULT hr;
  295. IServiceProvider * psp = NULL;
  296. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  297. NULL,
  298. CLSCTX_INPROC_SERVER,
  299. TypeSafeParams( IServiceProvider, &psp )
  300. ) );
  301. if ( FAILED( hr ) )
  302. goto Cleanup;
  303. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager,
  304. IConnectionPointContainer,
  305. ppcpcOut
  306. ) );
  307. if ( FAILED( hr ) )
  308. goto Cleanup;
  309. Cleanup:
  310. if ( psp != NULL )
  311. {
  312. psp->Release();
  313. }
  314. HRETURN( hr );
  315. } //*** CCPINotifyUI::GetConnectionPointContainer
  316. //////////////////////////////////////////////////////////////////////////////
  317. //
  318. // STDMETHODIMP
  319. // CCPINotifyUI::Advise(
  320. // IUnknown * pUnkSinkIn,
  321. // DWORD * pdwCookieOut
  322. // )
  323. //
  324. //////////////////////////////////////////////////////////////////////////////
  325. STDMETHODIMP
  326. CCPINotifyUI::Advise(
  327. IUnknown * pUnkSinkIn,
  328. DWORD * pdwCookieOut
  329. )
  330. {
  331. TraceFunc( "[IConnectionPoint]" );
  332. HRESULT hr;
  333. if ( pdwCookieOut == NULL )
  334. goto InvalidPointer;
  335. if ( pUnkSinkIn == NULL )
  336. goto InvalidArg;
  337. Assert( m_penum != NULL );
  338. hr = THR( m_penum->HrAddConnection( pUnkSinkIn, pdwCookieOut ) );
  339. if ( FAILED( hr ) )
  340. {
  341. goto Cleanup;
  342. } // if:
  343. Cleanup:
  344. HRETURN( hr );
  345. InvalidPointer:
  346. hr = THR( E_POINTER );
  347. goto Cleanup;
  348. InvalidArg:
  349. hr = THR( E_INVALIDARG );
  350. goto Cleanup;
  351. } //*** CCPINotifyUI::Advise
  352. //////////////////////////////////////////////////////////////////////////////
  353. //
  354. // STDMETHODIMP
  355. // CCPINotifyUI::Unadvise(
  356. // DWORD dwCookieIn
  357. // )
  358. //////////////////////////////////////////////////////////////////////////////
  359. STDMETHODIMP
  360. CCPINotifyUI::Unadvise(
  361. DWORD dwCookieIn
  362. )
  363. {
  364. TraceFunc1( "[IConncetionPoint] dwCookieIn = %#x", dwCookieIn );
  365. HRESULT hr;
  366. Assert( m_penum != NULL );
  367. hr = THR( m_penum->HrRemoveConnection( dwCookieIn ) );
  368. HRETURN( hr );
  369. } //*** CCPINotifyUI::Unadvise
  370. //////////////////////////////////////////////////////////////////////////////
  371. //
  372. // STDMETHODIMP
  373. // CCPINotifyUI::EnumConnections(
  374. // IEnumConnections * * ppEnumOut
  375. // )
  376. //
  377. //////////////////////////////////////////////////////////////////////////////
  378. STDMETHODIMP
  379. CCPINotifyUI::EnumConnections(
  380. IEnumConnections * * ppEnumOut
  381. )
  382. {
  383. TraceFunc( "[IConnectionPoint] ppEnumOut" );
  384. HRESULT hr;
  385. if ( ppEnumOut == NULL )
  386. {
  387. hr = THR( E_POINTER );
  388. goto Cleanup;
  389. } // if:
  390. hr = THR( m_penum->Clone( ppEnumOut ) );
  391. Cleanup:
  392. HRETURN( hr );
  393. } //*** CCPINotifyUI::EnumConnections
  394. //****************************************************************************
  395. //
  396. // INotifyUI
  397. //
  398. //****************************************************************************
  399. //////////////////////////////////////////////////////////////////////////////
  400. //
  401. // STDMETHODIMP
  402. // CCPINotifyUI::ObjectChanged(
  403. // OBJECTCOOKIE cookieIn
  404. // )
  405. //
  406. //////////////////////////////////////////////////////////////////////////////
  407. STDMETHODIMP
  408. CCPINotifyUI::ObjectChanged(
  409. OBJECTCOOKIE cookieIn
  410. )
  411. {
  412. TraceFunc1( "[INotifyUI] cookieIn = %ld", cookieIn );
  413. CONNECTDATA cd = { NULL };
  414. HRESULT hr;
  415. INotifyUI * pnui;
  416. IEnumConnections * pec = NULL;
  417. hr = THR( m_penum->Clone( &pec ) );
  418. if ( FAILED( hr ) )
  419. {
  420. LogMsg( L"[INotifyUI] Error cloning connection point enum. Cookie %ld. (hr=%#08x)", cookieIn, hr );
  421. goto Cleanup;
  422. } // if:
  423. hr = THR( pec->Reset() );
  424. if ( FAILED( hr ) )
  425. {
  426. LogMsg( L"[INotifyUI] Error reseting connection point enum. Cookie %ld. (hr=%#08x)", cookieIn, hr );
  427. goto Cleanup;
  428. } // if:
  429. for ( ;; )
  430. {
  431. if ( cd.pUnk != NULL )
  432. {
  433. cd.pUnk->Release();
  434. cd.pUnk = NULL;
  435. } // if
  436. hr = STHR( pec->Next( 1, &cd, NULL ) );
  437. if ( FAILED( hr ) )
  438. {
  439. LogMsg( L"[INotifyUI] Error calling Next() on the enumerator. Cookie %ld. (hr=%#08x)", cookieIn, hr );
  440. goto Cleanup;
  441. } // if:
  442. if ( hr == S_FALSE )
  443. {
  444. hr = S_OK;
  445. break; // exit condition
  446. } // if:
  447. hr = THR( cd.pUnk->TypeSafeQI( INotifyUI, &pnui ) );
  448. if ( FAILED( hr ) )
  449. {
  450. //
  451. // Don't stop on error.
  452. //
  453. LogMsg( L"[INotifyUI] Error QI'ing for the INotifyUI interface. Cookie %ld. (hr=%#08x)", cookieIn, hr );
  454. continue;
  455. } // if:
  456. hr = THR( pnui->ObjectChanged( cookieIn ) );
  457. if ( FAILED( hr ) )
  458. {
  459. LogMsg( L"[INotifyUI] Error delivery object changed message for cookie %ld to connection point. (hr=%#08x)", cookieIn, hr );
  460. } // if:
  461. //
  462. // Don't stop on error.
  463. //
  464. pnui->Release();
  465. } // for:
  466. hr = S_OK;
  467. Cleanup:
  468. if ( cd.pUnk != NULL )
  469. {
  470. cd.pUnk->Release();
  471. } // if:
  472. if ( pec != NULL )
  473. {
  474. pec->Release();
  475. } // if:
  476. HRETURN( hr );
  477. } //*** CCPINotifyUI::ObjectChanged