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.

485 lines
10 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CPINotifyUI.cpp
  7. //
  8. // Description:
  9. // INotifyUI Connection Point implementation.
  10. //
  11. // Maintained By:
  12. // Geoffrey Pease (GPease) 04-AUG-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "pch.h"
  16. #include "CPINotifyUI.h"
  17. #include "EnumCPINotifyUI.h"
  18. DEFINE_THISCLASS("CCPINotifyUI")
  19. // ************************************************************************
  20. //
  21. // Constructor / Destructor
  22. //
  23. // ************************************************************************
  24. //////////////////////////////////////////////////////////////////////////////
  25. //
  26. // HRESULT
  27. // CCPINotifyUI::S_HrCreateInstance(
  28. // IUnknown ** ppunkOut
  29. // )
  30. //
  31. //////////////////////////////////////////////////////////////////////////////
  32. HRESULT
  33. CCPINotifyUI::S_HrCreateInstance(
  34. IUnknown ** ppunkOut
  35. )
  36. {
  37. TraceFunc( "" );
  38. Assert( ppunkOut != NULL );
  39. HRESULT hr;
  40. CCPINotifyUI * lpcc = new CCPINotifyUI( );
  41. if ( lpcc != NULL )
  42. {
  43. hr = THR( lpcc->Init( ) );
  44. if ( SUCCEEDED( hr ) )
  45. {
  46. hr = THR( lpcc->TypeSafeQI( IUnknown, ppunkOut ) );
  47. } // if: success
  48. lpcc->Release( );
  49. } // if: got object
  50. else
  51. {
  52. hr = E_OUTOFMEMORY;
  53. } // else: out of memory
  54. HRETURN( hr );
  55. } // S_HrCreateInstance( )
  56. //
  57. // Constructor
  58. //
  59. CCPINotifyUI::CCPINotifyUI( void )
  60. {
  61. TraceFunc( "" );
  62. InterlockedIncrement( &g_cObjects );
  63. TraceFuncExit();
  64. } // CCPINotifyUI( )
  65. //////////////////////////////////////////////////////////////////////////////
  66. //
  67. // STDMETHODIMP
  68. // CCPINotifyUI::Init( )
  69. //
  70. //////////////////////////////////////////////////////////////////////////////
  71. STDMETHODIMP
  72. CCPINotifyUI::Init( )
  73. {
  74. TraceFunc( "" );
  75. HRESULT hr = S_OK;
  76. // IUnknown stuff
  77. Assert( m_cRef == 0 );
  78. AddRef( ); // Add one count
  79. // IConnectionPoint
  80. Assert( m_penum == NULL );
  81. m_penum = new CEnumCPINotifyUI( );
  82. if ( m_penum == NULL )
  83. goto OutOfMemory;
  84. hr = THR( m_penum->Init( ) );
  85. if ( FAILED( hr ) )
  86. goto Cleanup;
  87. // INotifyUI
  88. Cleanup:
  89. HRETURN( hr );
  90. OutOfMemory:
  91. hr = E_OUTOFMEMORY;
  92. goto Cleanup;
  93. } // Init( )
  94. //////////////////////////////////////////////////////////////////////////////
  95. //
  96. // CCPINotifyUI::~CCPINotifyUI( )
  97. //
  98. //////////////////////////////////////////////////////////////////////////////
  99. CCPINotifyUI::~CCPINotifyUI( )
  100. {
  101. TraceFunc( "" );
  102. if ( m_penum != NULL )
  103. {
  104. m_penum->Release( );
  105. }
  106. InterlockedDecrement( &g_cObjects );
  107. TraceFuncExit();
  108. } // ~CCPINotifyUI( )
  109. // ************************************************************************
  110. //
  111. // IUnknown
  112. //
  113. // ************************************************************************
  114. //////////////////////////////////////////////////////////////////////////////
  115. //
  116. // STDMETHODIMP
  117. // CCPINotifyUI::QueryInterface(
  118. // REFIID riid,
  119. // LPVOID *ppv
  120. // )
  121. //
  122. //////////////////////////////////////////////////////////////////////////////
  123. STDMETHODIMP
  124. CCPINotifyUI::QueryInterface(
  125. REFIID riid,
  126. LPVOID *ppv
  127. )
  128. {
  129. TraceQIFunc( riid, ppv );
  130. HRESULT hr = E_NOINTERFACE;
  131. if ( IsEqualIID( riid, IID_IUnknown ) )
  132. {
  133. *ppv = static_cast< IConnectionPoint * >( this );
  134. hr = S_OK;
  135. } // if: IUnknown
  136. else if ( IsEqualIID( riid, IID_IConnectionPoint ) )
  137. {
  138. *ppv = TraceInterface( __THISCLASS__, IConnectionPoint, this, 0 );
  139. hr = S_OK;
  140. } // else if: IConnectionPoint
  141. else if ( IsEqualIID( riid, IID_INotifyUI ) )
  142. {
  143. *ppv = TraceInterface( __THISCLASS__, INotifyUI, this, 0 );
  144. hr = S_OK;
  145. } // else if: INotifyUI
  146. if ( SUCCEEDED( hr ) )
  147. {
  148. ((IUnknown*) *ppv)->AddRef( );
  149. } // if: success
  150. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  151. } // QueryInterface( )
  152. //////////////////////////////////////////////////////////////////////////////
  153. //
  154. // STDMETHODIMP_(ULONG)
  155. // CCPINotifyUI::AddRef( void )
  156. //
  157. //////////////////////////////////////////////////////////////////////////////
  158. STDMETHODIMP_(ULONG)
  159. CCPINotifyUI::AddRef( void )
  160. {
  161. TraceFunc( "[IUnknown]" );
  162. InterlockedIncrement( &m_cRef );
  163. RETURN( m_cRef );
  164. } // AddRef( )
  165. //////////////////////////////////////////////////////////////////////////////
  166. //
  167. // STDMETHODIMP_(ULONG)
  168. // CCPINotifyUI::Release( void )
  169. //
  170. //////////////////////////////////////////////////////////////////////////////
  171. STDMETHODIMP_(ULONG)
  172. CCPINotifyUI::Release( void )
  173. {
  174. TraceFunc( "[IUnknown]" );
  175. InterlockedDecrement( &m_cRef );
  176. if ( m_cRef )
  177. RETURN( m_cRef );
  178. TraceDo( delete this );
  179. RETURN(0);
  180. } // Release( )
  181. // ************************************************************************
  182. //
  183. // IConnectionPoint
  184. //
  185. // ************************************************************************
  186. //////////////////////////////////////////////////////////////////////////////
  187. //
  188. // STDMETHODIMP
  189. // CCPINotifyUI::GetConnectionInterface(
  190. // IID * pIIDOut
  191. // )
  192. //
  193. //////////////////////////////////////////////////////////////////////////////
  194. STDMETHODIMP
  195. CCPINotifyUI::GetConnectionInterface(
  196. IID * pIIDOut
  197. )
  198. {
  199. TraceFunc( "[IConnectionPoint] pIIDOut" );
  200. HRESULT hr = S_OK;
  201. if ( pIIDOut == NULL )
  202. goto InvalidPointer;
  203. *pIIDOut = IID_INotifyUI;
  204. Cleanup:
  205. HRETURN( hr );
  206. InvalidPointer:
  207. hr = THR( E_POINTER );
  208. goto Cleanup;
  209. } // GetConnectionInterface( )
  210. //////////////////////////////////////////////////////////////////////////////
  211. //
  212. // STDMETHODIMP
  213. // CCPINotifyUI::GetConnectionPointContainer(
  214. // IConnectionPointContainer * * ppcpcOut
  215. // )
  216. //
  217. //////////////////////////////////////////////////////////////////////////////
  218. STDMETHODIMP
  219. CCPINotifyUI::GetConnectionPointContainer(
  220. IConnectionPointContainer * * ppcpcOut
  221. )
  222. {
  223. TraceFunc( "[IConnectionPoint] ppcpcOut" );
  224. HRESULT hr;
  225. IServiceProvider * psp = NULL;
  226. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  227. NULL,
  228. CLSCTX_INPROC_SERVER,
  229. TypeSafeParams( IServiceProvider, &psp )
  230. ) );
  231. if ( FAILED( hr ) )
  232. goto Cleanup;
  233. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager,
  234. IConnectionPointContainer,
  235. ppcpcOut
  236. ) );
  237. if ( FAILED( hr ) )
  238. goto Cleanup;
  239. Cleanup:
  240. if ( psp != NULL )
  241. {
  242. psp->Release( );
  243. }
  244. HRETURN( hr );
  245. } // GetConnectionPointContainer( )
  246. //////////////////////////////////////////////////////////////////////////////
  247. //
  248. // STDMETHODIMP
  249. // CCPINotifyUI::Advise(
  250. // IUnknown * pUnkSinkIn,
  251. // DWORD * pdwCookieOut
  252. // )
  253. //
  254. //////////////////////////////////////////////////////////////////////////////
  255. STDMETHODIMP
  256. CCPINotifyUI::Advise(
  257. IUnknown * pUnkSinkIn,
  258. DWORD * pdwCookieOut
  259. )
  260. {
  261. TraceFunc( "[IConnectionPoint]" );
  262. HRESULT hr;
  263. if ( pdwCookieOut == NULL )
  264. goto InvalidPointer;
  265. if ( pUnkSinkIn == NULL )
  266. goto InvalidArg;
  267. Assert( m_penum != NULL );
  268. hr = THR( m_penum->HrAddConnection( pUnkSinkIn, pdwCookieOut ) );
  269. if ( FAILED( hr ) )
  270. goto Cleanup;
  271. Cleanup:
  272. HRETURN( hr );
  273. InvalidPointer:
  274. hr = THR( E_POINTER );
  275. goto Cleanup;
  276. InvalidArg:
  277. hr = THR( E_INVALIDARG );
  278. goto Cleanup;
  279. } // Advise( )
  280. //////////////////////////////////////////////////////////////////////////////
  281. //
  282. // STDMETHODIMP
  283. // CCPINotifyUI::Unadvise(
  284. // DWORD dwCookieIn
  285. // )
  286. //////////////////////////////////////////////////////////////////////////////
  287. STDMETHODIMP
  288. CCPINotifyUI::Unadvise(
  289. DWORD dwCookieIn
  290. )
  291. {
  292. TraceFunc1( "[IConncetionPoint] dwCookieIn = %#x", dwCookieIn );
  293. HRESULT hr;
  294. Assert( m_penum != NULL );
  295. hr = THR( m_penum->HrRemoveConnection( dwCookieIn ) );
  296. HRETURN( hr );
  297. } // Unadvise( )
  298. //////////////////////////////////////////////////////////////////////////////
  299. //
  300. // STDMETHODIMP
  301. // CCPINotifyUI::EnumConnections(
  302. // IEnumConnections * * ppEnumOut
  303. // )
  304. //
  305. //////////////////////////////////////////////////////////////////////////////
  306. STDMETHODIMP
  307. CCPINotifyUI::EnumConnections(
  308. IEnumConnections * * ppEnumOut
  309. )
  310. {
  311. TraceFunc( "[IConnectionPoint] ppEnumOut" );
  312. HRESULT hr;
  313. if ( ppEnumOut == NULL )
  314. goto InvalidPointer;
  315. hr = THR( m_penum->Clone( ppEnumOut ) );
  316. Cleanup:
  317. HRETURN( hr );
  318. InvalidPointer:
  319. hr = THR( E_POINTER );
  320. goto Cleanup;
  321. } // EnumConnections( )
  322. //****************************************************************************
  323. //
  324. // INotifyUI
  325. //
  326. //****************************************************************************
  327. //////////////////////////////////////////////////////////////////////////////
  328. //
  329. // STDMETHODIMP
  330. // CCPINotifyUI::ObjectChanged(
  331. // OBJECTCOOKIE cookieIn
  332. // )
  333. //
  334. //////////////////////////////////////////////////////////////////////////////
  335. STDMETHODIMP
  336. CCPINotifyUI::ObjectChanged(
  337. OBJECTCOOKIE cookieIn
  338. )
  339. {
  340. TraceFunc1( "[INotifyUI] cookieIn = %#x", cookieIn );
  341. CONNECTDATA cd = { NULL };
  342. HRESULT hr;
  343. INotifyUI * pnui;
  344. hr = THR( m_penum->Reset( ) );
  345. if ( FAILED( hr ) )
  346. goto Cleanup;
  347. for ( ;; )
  348. {
  349. if ( cd.pUnk != NULL )
  350. {
  351. cd.pUnk->Release( );
  352. cd.pUnk = NULL;
  353. }
  354. hr = STHR( m_penum->Next( 1, &cd, NULL ) );
  355. if ( FAILED( hr ) )
  356. break;
  357. if ( hr == S_FALSE )
  358. {
  359. hr = S_OK;
  360. break; // exit condition
  361. }
  362. hr = THR( cd.pUnk->TypeSafeQI( INotifyUI, &pnui ) );
  363. if ( FAILED( hr ) )
  364. continue; // ingore the error and continue
  365. hr = THR( pnui->ObjectChanged( cookieIn ) );
  366. // don't care about the error.
  367. pnui->Release( );
  368. }
  369. hr = S_OK;
  370. Cleanup:
  371. if ( cd.pUnk != NULL )
  372. {
  373. cd.pUnk->Release( );
  374. }
  375. HRETURN( hr );
  376. } // ObjectChanged( )