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.

536 lines
12 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2002 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. HRESULT hr = S_OK;
  41. IServiceProvider * psp = NULL;
  42. CLogManager * plm = NULL;
  43. Assert( ppunkOut != NULL );
  44. if ( ppunkOut == NULL )
  45. {
  46. hr = THR( E_POINTER );
  47. goto Cleanup;
  48. }
  49. // Don't wrap - this can fail with E_POINTER.
  50. hr = CServiceManager::S_HrGetManagerPointer( &psp );
  51. if ( hr == E_POINTER )
  52. {
  53. //
  54. // This happens when the Service Manager is first started.
  55. //
  56. plm = new CLogManager();
  57. if ( plm == NULL )
  58. {
  59. hr = THR( E_OUTOFMEMORY );
  60. goto Cleanup;
  61. }
  62. hr = THR( plm->HrInit() );
  63. if ( FAILED( hr ) )
  64. {
  65. goto Cleanup;
  66. }
  67. hr = THR( plm->TypeSafeQI( IUnknown, ppunkOut ) );
  68. if ( FAILED( hr ) )
  69. {
  70. goto Cleanup;
  71. }
  72. } // if: service manager doesn't exist
  73. else if ( FAILED( hr ) )
  74. {
  75. THR( hr );
  76. goto Cleanup;
  77. }
  78. else
  79. {
  80. hr = THR( psp->TypeSafeQS( CLSID_LogManager, IUnknown, ppunkOut ) );
  81. psp->Release();
  82. } // else: service manager exists
  83. Cleanup:
  84. if ( plm != NULL )
  85. {
  86. plm->Release();
  87. }
  88. HRETURN( hr );
  89. } //*** CLogManager::S_HrCreateInstance
  90. //////////////////////////////////////////////////////////////////////////////
  91. //++
  92. //
  93. // CLogManager::CLogManager
  94. //
  95. //--
  96. //////////////////////////////////////////////////////////////////////////////
  97. CLogManager::CLogManager( void )
  98. : m_cRef( 1 )
  99. {
  100. TraceFunc( "" );
  101. InterlockedIncrement( &g_cObjects );
  102. Assert( m_plLogger == NULL );
  103. Assert( m_cookieCompletion == 0 );
  104. Assert( m_hrResult == S_OK );
  105. Assert( m_bstrLogMsg == NULL );
  106. Assert( m_pcpcb == NULL );
  107. Assert( m_dwCookieCallback == NULL );
  108. TraceFuncExit();
  109. } //*** CLogManager::CLogManager
  110. //////////////////////////////////////////////////////////////////////////////
  111. //
  112. // STDMETHODIMP
  113. // CLogManager::HrInit
  114. //
  115. //////////////////////////////////////////////////////////////////////////////
  116. STDMETHODIMP
  117. CLogManager::HrInit( void )
  118. {
  119. TraceFunc( "" );
  120. HRESULT hr = S_OK;
  121. // IUnknown stuff
  122. Assert( m_cRef == 1 );
  123. hr = THR( CClCfgSrvLogger::S_HrCreateInstance( reinterpret_cast< IUnknown ** >( &m_plLogger ) ) );
  124. HRETURN( hr );
  125. } //*** CLogManager::HrInit
  126. //////////////////////////////////////////////////////////////////////////////
  127. //++
  128. //
  129. // CLogManager::~CLogManager
  130. //
  131. //--
  132. //////////////////////////////////////////////////////////////////////////////
  133. CLogManager::~CLogManager( void )
  134. {
  135. TraceFunc( "" );
  136. Assert( m_cRef == 0 );
  137. THR( StopLogging() );
  138. // Release the ILogger interface.
  139. if ( m_plLogger != NULL )
  140. {
  141. m_plLogger->Release();
  142. m_plLogger = NULL;
  143. }
  144. // Decrement the global count of objects.
  145. InterlockedDecrement( &g_cObjects );
  146. TraceFuncExit();
  147. } //*** CLogManager::~CLogManager
  148. //****************************************************************************
  149. //
  150. // IUnknown
  151. //
  152. //****************************************************************************
  153. //////////////////////////////////////////////////////////////////////////////
  154. //++
  155. //
  156. // CLogManager::QueryInterface
  157. //
  158. // Description:
  159. // Query this object for the passed in interface.
  160. //
  161. // Arguments:
  162. // riidIn
  163. // Id of interface requested.
  164. //
  165. // ppvOut
  166. // Pointer to the requested interface.
  167. //
  168. // Return Value:
  169. // S_OK
  170. // If the interface is available on this object.
  171. //
  172. // E_NOINTERFACE
  173. // If the interface is not available.
  174. //
  175. // E_POINTER
  176. // ppvOut was NULL.
  177. //
  178. // Remarks:
  179. // None.
  180. //
  181. //--
  182. //////////////////////////////////////////////////////////////////////////////
  183. STDMETHODIMP
  184. CLogManager::QueryInterface(
  185. REFIID riidIn
  186. , LPVOID * ppvOut
  187. )
  188. {
  189. TraceQIFunc( riidIn, ppvOut );
  190. HRESULT hr = S_OK;
  191. //
  192. // Validate arguments.
  193. //
  194. Assert( ppvOut != NULL );
  195. if ( ppvOut == NULL )
  196. {
  197. hr = THR( E_POINTER );
  198. goto Cleanup;
  199. }
  200. //
  201. // Handle known interfaces.
  202. //
  203. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  204. {
  205. *ppvOut = static_cast< ILogManager * >( this );
  206. } // if: IUnknown
  207. else if ( IsEqualIID( riidIn, IID_ILogManager ) )
  208. {
  209. *ppvOut = TraceInterface( __THISCLASS__, ILogManager, this, 0 );
  210. } // else if: ILogManager
  211. else if ( IsEqualIID( riidIn, IID_IClusCfgCallback ) )
  212. {
  213. *ppvOut = TraceInterface( __THISCLASS__, IClusCfgCallback, this, 0 );
  214. } // else if: IClusCfgCallback
  215. else
  216. {
  217. *ppvOut = NULL;
  218. hr = E_NOINTERFACE;
  219. }
  220. //
  221. // Add a reference to the interface if successful.
  222. //
  223. if ( SUCCEEDED( hr ) )
  224. {
  225. ((IUnknown*) *ppvOut)->AddRef();
  226. } // if: success
  227. Cleanup:
  228. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  229. } //*** CLogManager::QueryInterface
  230. //////////////////////////////////////////////////////////////////////////////
  231. //
  232. // STDMETHODIMP_( ULONG )
  233. // CLogManager::AddRef
  234. //
  235. //////////////////////////////////////////////////////////////////////////////
  236. STDMETHODIMP_( ULONG )
  237. CLogManager::AddRef( void )
  238. {
  239. TraceFunc( "[IUnknown]" );
  240. InterlockedIncrement( &m_cRef );
  241. CRETURN( m_cRef );
  242. } //*** CLogManager::AddRef
  243. //////////////////////////////////////////////////////////////////////////////
  244. //
  245. // STDMETHODIMP_( ULONG )
  246. // CLogManager::Release
  247. //
  248. //////////////////////////////////////////////////////////////////////////////
  249. STDMETHODIMP_( ULONG )
  250. CLogManager::Release( void )
  251. {
  252. TraceFunc( "[IUnknown]" );
  253. LONG cRef;
  254. cRef = InterlockedDecrement( &m_cRef );
  255. if ( cRef == 0 )
  256. {
  257. TraceDo( delete this );
  258. }
  259. CRETURN( cRef );
  260. } //*** CLogManager::Release
  261. //****************************************************************************
  262. //
  263. // ILogManager
  264. //
  265. //****************************************************************************
  266. //////////////////////////////////////////////////////////////////////////////
  267. //
  268. // STDMETHODIMP
  269. // CLogManager::StartLogging
  270. //
  271. //////////////////////////////////////////////////////////////////////////////
  272. STDMETHODIMP
  273. CLogManager::StartLogging( void )
  274. {
  275. TraceFunc( "[ILogManager]" );
  276. HRESULT hr = S_OK;
  277. IServiceProvider * psp = NULL;
  278. IConnectionPointContainer * pcpc = NULL;
  279. //
  280. // If not done already, get the connection point.
  281. //
  282. if ( m_pcpcb == NULL )
  283. {
  284. hr = THR( CServiceManager::S_HrGetManagerPointer( &psp ) );
  285. if ( FAILED( hr ) )
  286. goto Cleanup;
  287. hr = THR( psp->TypeSafeQS(
  288. CLSID_NotificationManager
  289. , IConnectionPointContainer
  290. , &pcpc
  291. ) );
  292. if ( FAILED( hr ) )
  293. goto Cleanup;
  294. hr = THR( pcpc->FindConnectionPoint(
  295. IID_IClusCfgCallback
  296. , &m_pcpcb
  297. ) );
  298. if ( FAILED( hr ) )
  299. goto Cleanup;
  300. } // if: connection point callback not retrieved yet
  301. //
  302. // Register to get notification (if needed)
  303. //
  304. if ( m_dwCookieCallback == 0 )
  305. {
  306. hr = THR( m_pcpcb->Advise( static_cast< IClusCfgCallback * >( this ), &m_dwCookieCallback ) );
  307. if ( FAILED( hr ) )
  308. goto Cleanup;
  309. } // if: advise cookie not retrieved yet
  310. Cleanup:
  311. if ( psp != NULL )
  312. {
  313. psp->Release();
  314. }
  315. if ( pcpc != NULL )
  316. {
  317. pcpc->Release();
  318. }
  319. HRETURN( hr );
  320. } //*** CLogManager::StartLogging
  321. //////////////////////////////////////////////////////////////////////////////
  322. //
  323. // STDMETHODIMP
  324. // CLogManager::StopLogging
  325. //
  326. //////////////////////////////////////////////////////////////////////////////
  327. STDMETHODIMP
  328. CLogManager::StopLogging( void )
  329. {
  330. TraceFunc( "[ILogManager]" );
  331. HRESULT hr = S_OK;
  332. // Unadvise the IConnectionPoint interface.
  333. if ( m_dwCookieCallback != 0 )
  334. {
  335. Assert( m_pcpcb != NULL );
  336. hr = THR( m_pcpcb->Unadvise( m_dwCookieCallback ) );
  337. if ( FAILED( hr ) )
  338. goto Cleanup;
  339. m_dwCookieCallback = 0;
  340. }
  341. // Release the IConnectionPoint interface.
  342. if ( m_pcpcb != NULL )
  343. {
  344. Assert( m_dwCookieCallback == 0 );
  345. m_pcpcb->Release();
  346. m_pcpcb = NULL;
  347. }
  348. Cleanup:
  349. HRETURN( hr );
  350. } //*** CLogManager::StopLogging
  351. //////////////////////////////////////////////////////////////////////////////
  352. //
  353. // STDMETHODIMP
  354. // CLogManager::GetLogger
  355. //
  356. //////////////////////////////////////////////////////////////////////////////
  357. STDMETHODIMP
  358. CLogManager::GetLogger( ILogger ** ppLoggerOut )
  359. {
  360. TraceFunc( "[ILogManager]" );
  361. HRESULT hr = S_OK;
  362. if ( ppLoggerOut == NULL )
  363. {
  364. hr = THR( E_POINTER );
  365. goto Cleanup;
  366. }
  367. *ppLoggerOut = NULL;
  368. if ( m_plLogger != NULL )
  369. {
  370. hr = THR( m_plLogger->TypeSafeQI( ILogger, ppLoggerOut ) );
  371. if ( FAILED( hr ) )
  372. {
  373. goto Cleanup;
  374. }
  375. } // if: we have the logger interface
  376. else
  377. {
  378. hr = THR( E_NOINTERFACE );
  379. goto Cleanup;
  380. }
  381. Cleanup:
  382. HRETURN( hr );
  383. } //*** CLogManager::GetLogger
  384. //****************************************************************************
  385. //
  386. // IClusCfgCallback
  387. //
  388. //****************************************************************************
  389. //////////////////////////////////////////////////////////////////////////////
  390. //++
  391. //
  392. // STDMETHODIMP
  393. // CLogManager::SendStatusReport(
  394. // LPCWSTR pcszNodeNameIn,
  395. // CLSID clsidTaskMajorIn,
  396. // CLSID clsidTaskMinorIn,
  397. // ULONG ulMinIn,
  398. // ULONG ulMaxIn,
  399. // ULONG ulCurrentIn,
  400. // HRESULT hrStatusIn,
  401. // LPCWSTR pcszDescriptionIn,
  402. // FILETIME * pftTimeIn,
  403. // LPCWSTR pcszReferenceIn
  404. // )
  405. //
  406. //////////////////////////////////////////////////////////////////////////////
  407. STDMETHODIMP
  408. CLogManager::SendStatusReport(
  409. LPCWSTR pcszNodeNameIn,
  410. CLSID clsidTaskMajorIn,
  411. CLSID clsidTaskMinorIn,
  412. ULONG ulMinIn,
  413. ULONG ulMaxIn,
  414. ULONG ulCurrentIn,
  415. HRESULT hrStatusIn,
  416. LPCWSTR pcszDescriptionIn,
  417. FILETIME * pftTimeIn,
  418. LPCWSTR pcszReferenceIn
  419. )
  420. {
  421. TraceFunc( "[IClusCfgCallback]" );
  422. HRESULT hr = S_OK;
  423. hr = THR( CClCfgSrvLogger::S_HrLogStatusReport(
  424. m_plLogger
  425. , pcszNodeNameIn
  426. , clsidTaskMajorIn
  427. , clsidTaskMinorIn
  428. , ulMinIn
  429. , ulMaxIn
  430. , ulCurrentIn
  431. , hrStatusIn
  432. , pcszDescriptionIn
  433. , pftTimeIn
  434. , pcszReferenceIn
  435. ) );
  436. HRETURN( hr );
  437. } //*** CLogManager::SendStatusReport