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.

477 lines
11 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // LogManager.cpp
  7. //
  8. // Description:
  9. // Log Manager implementation.
  10. //
  11. // Maintained By:
  12. // David Potter (DavidP) 07-DEC-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "pch.h"
  16. #include "Logger.h"
  17. #include "LogManager.h"
  18. DEFINE_THISCLASS("CLogManager")
  19. //****************************************************************************
  20. //
  21. // Constructor / Destructor
  22. //
  23. //****************************************************************************
  24. //////////////////////////////////////////////////////////////////////////////
  25. //++
  26. //
  27. // HRESULT
  28. // CLogManager::S_HrCreateInstance(
  29. // IUnknown ** ppunkOut
  30. // )
  31. //
  32. //--
  33. //////////////////////////////////////////////////////////////////////////////
  34. HRESULT
  35. CLogManager::S_HrCreateInstance(
  36. IUnknown ** ppunkOut
  37. )
  38. {
  39. TraceFunc( "" );
  40. Assert( ppunkOut != NULL );
  41. HRESULT hr;
  42. IServiceProvider * psp;
  43. // Don't wrap - this can fail with E_POINTER.
  44. hr = CServiceManager::S_HrGetManagerPointer( &psp );
  45. if ( SUCCEEDED( hr ) )
  46. {
  47. hr = THR( psp->TypeSafeQS(
  48. CLSID_LogManager
  49. , IUnknown
  50. , ppunkOut
  51. ) );
  52. psp->Release( );
  53. } // if: service manager
  54. else if ( hr == E_POINTER )
  55. {
  56. //
  57. // This happens when the Service Manager is first started.
  58. //
  59. CLogManager * plm = new CLogManager( );
  60. if ( plm != NULL )
  61. {
  62. hr = THR( plm->HrInit( ) );
  63. if ( SUCCEEDED( hr ) )
  64. {
  65. hr = THR( plm->TypeSafeQI( IUnknown, ppunkOut ) );
  66. } // if: success
  67. plm->Release( );
  68. } // if: got object
  69. else
  70. {
  71. hr = E_OUTOFMEMORY;
  72. }
  73. } // if: service manager doesn't exist
  74. else
  75. {
  76. THR( hr );
  77. } // else:
  78. HRETURN( hr );
  79. } //*** CLogManager::S_HrCreateInstance( )
  80. //////////////////////////////////////////////////////////////////////////////
  81. //++
  82. //
  83. // CLogManager::CLogManager( void )
  84. //
  85. //--
  86. //////////////////////////////////////////////////////////////////////////////
  87. CLogManager::CLogManager( void )
  88. : m_cRef( 1 )
  89. {
  90. TraceFunc( "" );
  91. InterlockedIncrement( &g_cObjects );
  92. Assert( m_plLogger == NULL );
  93. Assert( m_cookieCompletion == 0 );
  94. Assert( m_hrResult == S_OK );
  95. Assert( m_bstrLogMsg == NULL );
  96. Assert( m_pcpcb == NULL );
  97. Assert( m_dwCookieCallback == NULL );
  98. TraceFuncExit();
  99. } //*** CLogManager::CLogManager( )
  100. //////////////////////////////////////////////////////////////////////////////
  101. //
  102. // STDMETHODIMP
  103. // CLogManager::HrInit( )
  104. //
  105. //////////////////////////////////////////////////////////////////////////////
  106. STDMETHODIMP
  107. CLogManager::HrInit( void )
  108. {
  109. TraceFunc( "" );
  110. HRESULT hr = S_OK;
  111. // IUnknown stuff
  112. Assert( m_cRef == 1 );
  113. HRETURN( hr );
  114. } //*** CLogManager::HrInit( )
  115. //////////////////////////////////////////////////////////////////////////////
  116. //++
  117. //
  118. // CLogManager::~CLogManager( void )
  119. //
  120. //--
  121. //////////////////////////////////////////////////////////////////////////////
  122. CLogManager::~CLogManager( void )
  123. {
  124. TraceFunc( "" );
  125. HRESULT hr;
  126. Assert( m_cRef == 0 );
  127. // Unadvise the IConnectionPoint interface.
  128. if ( m_dwCookieCallback != 0 )
  129. {
  130. Assert( m_pcpcb != NULL );
  131. hr = THR( m_pcpcb->Unadvise( m_dwCookieCallback ) );
  132. if ( FAILED( hr ) )
  133. {
  134. //goto Cleanup;
  135. }
  136. m_dwCookieCallback = 0;
  137. }
  138. // Release the IConnectionPoint interface.
  139. if ( m_pcpcb != NULL )
  140. {
  141. Assert( m_dwCookieCallback == 0 );
  142. m_pcpcb->Release();
  143. m_pcpcb = NULL;
  144. }
  145. // Release the ILogger interface.
  146. if ( m_plLogger != NULL )
  147. {
  148. m_plLogger->Release();
  149. m_plLogger = NULL;
  150. }
  151. // Decrement the global count of objects.
  152. InterlockedDecrement( &g_cObjects );
  153. TraceFuncExit();
  154. } //*** CLogManager::~CLogManager( )
  155. //****************************************************************************
  156. //
  157. // IUnknown
  158. //
  159. //****************************************************************************
  160. //////////////////////////////////////////////////////////////////////////////
  161. //++
  162. //
  163. // STDMETHODIMP
  164. // CLogManager::QueryInterface(
  165. // REFIID riidIn,
  166. // LPVOID * ppvOut
  167. // )
  168. //
  169. //--
  170. //////////////////////////////////////////////////////////////////////////////
  171. STDMETHODIMP
  172. CLogManager::QueryInterface(
  173. REFIID riidIn,
  174. LPVOID * ppvOut
  175. )
  176. {
  177. TraceQIFunc( riidIn, ppvOut );
  178. HRESULT hr = S_OK;
  179. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  180. {
  181. *ppvOut = static_cast< ILogManager * >( this );
  182. } // if: IUnknown
  183. else if ( IsEqualIID( riidIn, IID_ILogManager ) )
  184. {
  185. *ppvOut = TraceInterface( __THISCLASS__, ILogManager, this, 0 );
  186. } // else if: ILogManager
  187. else if ( IsEqualIID( riidIn, IID_IClusCfgCallback ) )
  188. {
  189. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgCallback, this, 0 );
  190. } // else if: IClusCfgCallback
  191. else
  192. {
  193. hr = E_NOINTERFACE;
  194. }
  195. if ( SUCCEEDED( hr ) )
  196. {
  197. ((IUnknown*) *ppvOut)->AddRef( );
  198. } // if: success
  199. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  200. } //*** CLogManager::QueryInterface( )
  201. //////////////////////////////////////////////////////////////////////////////
  202. //
  203. // STDMETHODIMP_( ULONG )
  204. // CLogManager::AddRef( void )
  205. //
  206. //////////////////////////////////////////////////////////////////////////////
  207. STDMETHODIMP_( ULONG )
  208. CLogManager::AddRef( void )
  209. {
  210. TraceFunc( "[IUnknown]" );
  211. InterlockedIncrement( &m_cRef );
  212. RETURN( m_cRef );
  213. } //*** CLogManager::AddRef( )
  214. //////////////////////////////////////////////////////////////////////////////
  215. //
  216. // STDMETHODIMP_( ULONG )
  217. // CLogManager::Release( void )
  218. //
  219. //////////////////////////////////////////////////////////////////////////////
  220. STDMETHODIMP_( ULONG )
  221. CLogManager::Release( void )
  222. {
  223. TraceFunc( "[IUnknown]" );
  224. LONG cRef;
  225. InterlockedDecrement( &m_cRef );
  226. cRef = m_cRef;
  227. if ( cRef == 0 )
  228. {
  229. TraceDo( delete this );
  230. }
  231. RETURN( cRef );
  232. } //*** CLogManager::Release( )
  233. //****************************************************************************
  234. //
  235. // ILogManager
  236. //
  237. //****************************************************************************
  238. //////////////////////////////////////////////////////////////////////////////
  239. //
  240. // STDMETHODIMP
  241. // CLogManager::StartLogging( void )
  242. //
  243. //////////////////////////////////////////////////////////////////////////////
  244. STDMETHODIMP
  245. CLogManager::StartLogging( void )
  246. {
  247. TraceFunc( "[ILogManager]" );
  248. HRESULT hr;
  249. IServiceProvider * psp = NULL;
  250. IConnectionPointContainer * pcpc = NULL;
  251. DWORD cookieGITLogger;
  252. //
  253. // Get a ClCfgSrv ILogger instance.
  254. //
  255. hr = CClCfgSrvLogger::S_HrGetLogger( &m_plLogger );
  256. if ( FAILED( hr ) )
  257. goto Cleanup;
  258. //
  259. // If not done already, get the connection point.
  260. //
  261. if ( m_pcpcb == NULL )
  262. {
  263. hr = THR( CServiceManager::S_HrGetManagerPointer( &psp ) );
  264. if ( FAILED( hr ) )
  265. goto Cleanup;
  266. hr = THR( psp->TypeSafeQS(
  267. CLSID_NotificationManager
  268. , IConnectionPointContainer
  269. , &pcpc
  270. ) );
  271. if ( FAILED( hr ) )
  272. goto Cleanup;
  273. hr = THR( pcpc->FindConnectionPoint(
  274. IID_IClusCfgCallback
  275. , &m_pcpcb
  276. ) );
  277. if ( FAILED( hr ) )
  278. goto Cleanup;
  279. } // if: connection point callback not retrieved yet
  280. //
  281. // Register to get notification (if needed)
  282. //
  283. if ( m_dwCookieCallback == 0 )
  284. {
  285. hr = THR( m_pcpcb->Advise( static_cast< IClusCfgCallback * >( this ), &m_dwCookieCallback ) );
  286. if ( FAILED( hr ) )
  287. goto Cleanup;
  288. } // if: advise cookie not retrieved yet
  289. Cleanup:
  290. if ( psp != NULL )
  291. {
  292. psp->Release();
  293. }
  294. if ( pcpc != NULL )
  295. {
  296. pcpc->Release( );
  297. }
  298. HRETURN( hr );
  299. } //*** CLogManager::StartLogging( )
  300. //////////////////////////////////////////////////////////////////////////////
  301. //
  302. // STDMETHODIMP
  303. // CLogManager::StopLogging( void )
  304. //
  305. //////////////////////////////////////////////////////////////////////////////
  306. STDMETHODIMP
  307. CLogManager::StopLogging( void )
  308. {
  309. TraceFunc( "[ILogManager]" );
  310. HRESULT hr = S_OK;
  311. // Unadvise the IConnectionPoint interface.
  312. if ( m_dwCookieCallback != 0 )
  313. {
  314. Assert( m_pcpcb != NULL );
  315. hr = THR( m_pcpcb->Unadvise( m_dwCookieCallback ) );
  316. if ( FAILED( hr ) )
  317. goto Cleanup;
  318. m_dwCookieCallback = 0;
  319. }
  320. // Release the IConnectionPoint interface.
  321. if ( m_pcpcb != NULL )
  322. {
  323. Assert( m_dwCookieCallback == 0 );
  324. m_pcpcb->Release();
  325. m_pcpcb = NULL;
  326. }
  327. // Release the ILogger interface.
  328. if ( m_plLogger != NULL )
  329. {
  330. m_plLogger->Release();
  331. m_plLogger = NULL;
  332. }
  333. Cleanup:
  334. HRETURN( hr );
  335. } //*** CLogManager::StopLogging( )
  336. //****************************************************************************
  337. //
  338. // IClusCfgCallback
  339. //
  340. //****************************************************************************
  341. //////////////////////////////////////////////////////////////////////////////
  342. //++
  343. //
  344. // STDMETHODIMP
  345. // CLogManager::SendStatusReport(
  346. // LPCWSTR pcszNodeNameIn,
  347. // CLSID clsidTaskMajorIn,
  348. // CLSID clsidTaskMinorIn,
  349. // ULONG ulMinIn,
  350. // ULONG ulMaxIn,
  351. // ULONG ulCurrentIn,
  352. // HRESULT hrStatusIn,
  353. // LPCWSTR pcszDescriptionIn,
  354. // FILETIME * pftTimeIn,
  355. // LPCWSTR pcszReferenceIn
  356. // )
  357. //
  358. //////////////////////////////////////////////////////////////////////////////
  359. STDMETHODIMP
  360. CLogManager::SendStatusReport(
  361. LPCWSTR pcszNodeNameIn,
  362. CLSID clsidTaskMajorIn,
  363. CLSID clsidTaskMinorIn,
  364. ULONG ulMinIn,
  365. ULONG ulMaxIn,
  366. ULONG ulCurrentIn,
  367. HRESULT hrStatusIn,
  368. LPCWSTR pcszDescriptionIn,
  369. FILETIME * pftTimeIn,
  370. LPCWSTR pcszReferenceIn
  371. )
  372. {
  373. TraceFunc( "[IClusCfgCallback]" );
  374. HRESULT hr = S_OK;
  375. hr = THR( CClCfgSrvLogger::S_HrLogStatusReport(
  376. m_plLogger
  377. , pcszNodeNameIn
  378. , clsidTaskMajorIn
  379. , clsidTaskMinorIn
  380. , ulMinIn
  381. , ulMaxIn
  382. , ulCurrentIn
  383. , hrStatusIn
  384. , pcszDescriptionIn
  385. , pftTimeIn
  386. , pcszReferenceIn
  387. ) );
  388. HRETURN( hr );
  389. } //*** CLogManager::SendStatusReport( )