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.

341 lines
7.4 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // UINotification.cpp
  7. //
  8. // Description:
  9. // UINotification implementation.
  10. //
  11. // Maintained By:
  12. // David Potter (DavidP) 14-JUN-2001
  13. // Geoffrey Pease (GPease) 22-NOV-1999
  14. //
  15. // Notes:
  16. // The object implements a lightweight marshalling of data from the
  17. // free-threaded lower layers to the single-threaded, apartment model
  18. // UI layer.
  19. //
  20. //////////////////////////////////////////////////////////////////////////////
  21. #include "Pch.h"
  22. #include "UINotification.h"
  23. DEFINE_THISCLASS("CUINotification")
  24. extern BOOL g_fWait;
  25. extern IServiceProvider * g_psp;
  26. // ************************************************************************
  27. //
  28. // Constructor / Destructor
  29. //
  30. // ************************************************************************
  31. //////////////////////////////////////////////////////////////////////////////
  32. //
  33. // HRESULT
  34. // CUINotification::S_HrCreateInstance(
  35. // IUnknown ** ppunkOut
  36. // )
  37. //
  38. //////////////////////////////////////////////////////////////////////////////
  39. HRESULT
  40. CUINotification::S_HrCreateInstance(
  41. IUnknown ** ppunkOut
  42. )
  43. {
  44. TraceFunc( "" );
  45. HRESULT hr = S_OK;
  46. CUINotification * puin = NULL;
  47. Assert( ppunkOut != NULL );
  48. if ( ppunkOut == NULL )
  49. {
  50. hr = THR( E_POINTER );
  51. goto Cleanup;
  52. }
  53. puin = new CUINotification();
  54. if ( puin == NULL )
  55. {
  56. hr = THR( E_OUTOFMEMORY );
  57. goto Cleanup;
  58. }
  59. hr = THR( puin->HrInit() );
  60. if ( FAILED( hr ) )
  61. {
  62. goto Cleanup;
  63. }
  64. hr = THR( puin->TypeSafeQI( IUnknown, ppunkOut ) );
  65. if ( FAILED( hr ) )
  66. {
  67. goto Cleanup;
  68. }
  69. Cleanup:
  70. if ( puin != NULL )
  71. {
  72. puin->Release();
  73. }
  74. HRETURN( hr );
  75. } //*** CUINotification::S_HrCreateInstance
  76. //////////////////////////////////////////////////////////////////////////////
  77. //
  78. // Constructor
  79. //
  80. //////////////////////////////////////////////////////////////////////////////
  81. CUINotification::CUINotification( void )
  82. : m_cRef( 1 )
  83. {
  84. TraceFunc( "" );
  85. InterlockedIncrement( &g_cObjects );
  86. TraceFuncExit();
  87. } //*** CUINotification::CUINotification
  88. //////////////////////////////////////////////////////////////////////////////
  89. //
  90. // STDMETHODIMP
  91. // CUINotification::HrInit
  92. //
  93. //////////////////////////////////////////////////////////////////////////////
  94. STDMETHODIMP
  95. CUINotification::HrInit( void )
  96. {
  97. TraceFunc( "" );
  98. HRESULT hr = S_OK;
  99. // IUnknown
  100. Assert( m_cRef == 1 );
  101. HRETURN( hr );
  102. } //*** CUINotification::HrInit
  103. //////////////////////////////////////////////////////////////////////////////
  104. //
  105. // Destructor
  106. //
  107. //////////////////////////////////////////////////////////////////////////////
  108. CUINotification::~CUINotification( void )
  109. {
  110. TraceFunc( "" );
  111. HRESULT hr;
  112. IConnectionPoint * pcp = NULL;
  113. // IUnknown stuff
  114. Assert( m_cRef == 0 );
  115. AddRef(); // Add one count
  116. InterlockedDecrement( &g_cObjects );
  117. TraceFuncExit();
  118. } //*** CUINotification::~CUINotification
  119. // ************************************************************************
  120. //
  121. // IUnknown
  122. //
  123. // ************************************************************************
  124. //////////////////////////////////////////////////////////////////////////////
  125. //++
  126. //
  127. // CUINotification::QueryInterface
  128. //
  129. // Description:
  130. // Query this object for the passed in interface.
  131. //
  132. // Arguments:
  133. // riidIn
  134. // Id of interface requested.
  135. //
  136. // ppvOut
  137. // Pointer to the requested interface.
  138. //
  139. // Return Value:
  140. // S_OK
  141. // If the interface is available on this object.
  142. //
  143. // E_NOINTERFACE
  144. // If the interface is not available.
  145. //
  146. // E_POINTER
  147. // ppvOut was NULL.
  148. //
  149. // Remarks:
  150. // None.
  151. //
  152. //--
  153. //////////////////////////////////////////////////////////////////////////////
  154. STDMETHODIMP
  155. CUINotification::QueryInterface(
  156. REFIID riidIn
  157. , LPVOID * ppvOut
  158. )
  159. {
  160. TraceQIFunc( riidIn, ppvOut );
  161. HRESULT hr = S_OK;
  162. //
  163. // Validate arguments.
  164. //
  165. Assert( ppvOut != NULL );
  166. if ( ppvOut == NULL )
  167. {
  168. hr = THR( E_POINTER );
  169. goto Cleanup;
  170. }
  171. //
  172. // Handle known interfaces.
  173. //
  174. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  175. {
  176. *ppvOut = static_cast< IUnknown * >( this );
  177. } // if: IUnknown
  178. else if ( IsEqualIID( riidIn, IID_INotifyUI ) )
  179. {
  180. *ppvOut = TraceInterface( __THISCLASS__, INotifyUI, this, 0 );
  181. } // else if: INotifyUI
  182. else
  183. {
  184. *ppvOut = NULL;
  185. hr = E_NOINTERFACE;
  186. }
  187. //
  188. // Add a reference to the interface if successful.
  189. //
  190. if ( SUCCEEDED( hr ) )
  191. {
  192. ((IUnknown *) *ppvOut)->AddRef();
  193. } // if: success
  194. Cleanup:
  195. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  196. } //*** CUINotification::QueryInterface
  197. //////////////////////////////////////////////////////////////////////////////
  198. //
  199. // STDMETHODIMP_(ULONG)
  200. // CUINotification::AddRef
  201. //
  202. //////////////////////////////////////////////////////////////////////////////
  203. STDMETHODIMP_( ULONG )
  204. CUINotification::AddRef( void )
  205. {
  206. TraceFunc( "[IUnknown]" );
  207. InterlockedIncrement( &m_cRef );
  208. CRETURN( m_cRef );
  209. } //*** CUINotification::AddRef
  210. //////////////////////////////////////////////////////////////////////////////
  211. //
  212. // STDMETHODIMP_(ULONG)
  213. // CUINotification::Release
  214. //
  215. //////////////////////////////////////////////////////////////////////////////
  216. STDMETHODIMP_( ULONG )
  217. CUINotification::Release( void )
  218. {
  219. TraceFunc( "[IUnknown]" );
  220. LONG cRef;
  221. cRef = InterlockedDecrement( &m_cRef );
  222. if ( cRef == 0 )
  223. {
  224. TraceDo( delete this );
  225. }
  226. CRETURN( cRef );
  227. } //*** CUINotification::Release
  228. // ************************************************************************
  229. //
  230. // INotifyUI
  231. //
  232. // ************************************************************************
  233. //////////////////////////////////////////////////////////////////////////////
  234. //
  235. // STDMETHODIMP
  236. // CUINotification::ObjectChanged(
  237. // DWORD cookieIn
  238. // )
  239. //
  240. //////////////////////////////////////////////////////////////////////////////
  241. STDMETHODIMP
  242. CUINotification::ObjectChanged(
  243. LPVOID cookieIn
  244. )
  245. {
  246. TraceFunc1( "[INotifyUI] cookieIn = 0x%08x", cookieIn );
  247. HRESULT hr = S_OK;
  248. DebugMsg( "UINOTIFICATION: cookie %#x has changed.", cookieIn );
  249. if ( m_cookie == cookieIn )
  250. {
  251. //
  252. // Done waiting...
  253. //
  254. g_fWait = FALSE;
  255. }
  256. HRETURN( hr );
  257. } //*** CUINotification::ObjectChanged
  258. //****************************************************************************
  259. //
  260. // Semi-Public
  261. //
  262. //****************************************************************************
  263. HRESULT
  264. CUINotification::HrSetCompletionCookie(
  265. OBJECTCOOKIE cookieIn
  266. )
  267. {
  268. TraceFunc1( "cookieIn = %p", cookieIn );
  269. m_cookie = cookieIn;
  270. HRETURN( S_OK );
  271. } //*** CUINotification::HrSetCompletionCookie