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.

678 lines
15 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CEnumCfgResource.cpp
  7. //
  8. // Description:
  9. // CEnumCfgResource implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 02-AUG-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "CEnumCfgResources.h"
  17. #include "CResourcePhysicalDisk.h"
  18. DEFINE_THISCLASS("CEnumCfgResources")
  19. //////////////////////////////////////////////////////////////////////////////
  20. //
  21. // HRESULT
  22. // CEnumCfgResources::S_HrCreateInstance(
  23. // IUnknown ** ppunkOut
  24. // )
  25. //
  26. //////////////////////////////////////////////////////////////////////////////
  27. HRESULT
  28. CEnumCfgResources::S_HrCreateInstance(
  29. IUnknown ** ppunkOut,
  30. IUnknown * punkOuterIn,
  31. HCLUSTER * phClusterIn,
  32. CLSID * pclsidMajorIn
  33. )
  34. {
  35. TraceFunc( "" );
  36. HRESULT hr = S_OK;
  37. CEnumCfgResources * pecr = NULL;
  38. if ( ppunkOut == NULL )
  39. {
  40. hr = THR( E_POINTER );
  41. goto Cleanup;
  42. } // if:
  43. pecr = new CEnumCfgResources;
  44. if ( pecr == NULL )
  45. {
  46. hr = THR( E_OUTOFMEMORY );
  47. goto Cleanup;
  48. } // if:
  49. hr = THR( pecr->HrInit( punkOuterIn, phClusterIn, pclsidMajorIn ) );
  50. if ( FAILED( hr ) )
  51. {
  52. goto Cleanup;
  53. }
  54. hr = THR( pecr->TypeSafeQI( IUnknown, ppunkOut ) );
  55. if ( FAILED( hr ) )
  56. {
  57. goto Cleanup;
  58. }
  59. Cleanup:
  60. if ( pecr != NULL )
  61. {
  62. pecr->Release();
  63. } // if:
  64. HRETURN( hr );
  65. } //*** CEnumCfgResources::S_HrCreateInstance
  66. //////////////////////////////////////////////////////////////////////////////
  67. //
  68. // CEnumCfgResources::CEnumCfgResources
  69. //
  70. //////////////////////////////////////////////////////////////////////////////
  71. CEnumCfgResources::CEnumCfgResources( void )
  72. : m_cRef( 1 )
  73. {
  74. TraceFunc( "" );
  75. InterlockedIncrement( &g_cObjects );
  76. Assert( m_punkOuter == NULL );
  77. Assert( m_phCluster == NULL );
  78. Assert( m_pclsidMajor == NULL );
  79. Assert( m_pcccb == NULL );
  80. Assert( m_hClusEnum == NULL );
  81. Assert( m_dwIndex == 0 );
  82. TraceFuncExit();
  83. } //*** CEnumCfgResources::CEnumCfgResources
  84. //////////////////////////////////////////////////////////////////////////////
  85. //
  86. // CEnumCfgResources::~CEnumCfgResources
  87. //
  88. //////////////////////////////////////////////////////////////////////////////
  89. CEnumCfgResources::~CEnumCfgResources( void )
  90. {
  91. TraceFunc( "" );
  92. // m_cRef
  93. if ( m_punkOuter != NULL )
  94. {
  95. m_punkOuter->Release();
  96. }
  97. // m_phCluster - DO NOT CLOSE!
  98. // m_pclsidMajor
  99. if ( m_pcccb != NULL )
  100. {
  101. m_pcccb->Release();
  102. }
  103. if ( m_hClusEnum != NULL )
  104. {
  105. ClusterCloseEnum( m_hClusEnum );
  106. }
  107. // m_dwIndex
  108. InterlockedDecrement( &g_cObjects );
  109. TraceFuncExit();
  110. } //*** CEnumCfgResources::~CEnumCfgResources
  111. //////////////////////////////////////////////////////////////////////////////
  112. //
  113. // HRESULT
  114. // CEnumCfgResources::HrInit
  115. //
  116. //////////////////////////////////////////////////////////////////////////////
  117. HRESULT
  118. CEnumCfgResources::HrInit(
  119. IUnknown * punkOuterIn,
  120. HCLUSTER * phClusterIn,
  121. CLSID * pclsidMajorIn
  122. )
  123. {
  124. TraceFunc( "" );
  125. HRESULT hr;
  126. // IUnknown
  127. Assert( m_cRef == 1 );
  128. if ( punkOuterIn != NULL )
  129. {
  130. m_punkOuter = punkOuterIn;
  131. m_punkOuter->AddRef();
  132. }
  133. if ( phClusterIn == NULL )
  134. {
  135. hr = THR( E_INVALIDARG );
  136. goto Cleanup;
  137. }
  138. m_phCluster = phClusterIn;
  139. if ( pclsidMajorIn != NULL )
  140. {
  141. m_pclsidMajor = pclsidMajorIn;
  142. }
  143. else
  144. {
  145. m_pclsidMajor = (CLSID *) &TASKID_Major_Client_And_Server_Log;
  146. }
  147. if ( punkOuterIn != NULL )
  148. {
  149. hr = THR( punkOuterIn->TypeSafeQI( IClusCfgCallback, &m_pcccb ) );
  150. if ( FAILED( hr ) )
  151. {
  152. goto Cleanup;
  153. }
  154. }
  155. //
  156. // Open the enumer.
  157. //
  158. m_hClusEnum = ClusterOpenEnum( *m_phCluster, CLUSTER_ENUM_RESOURCE );
  159. if ( m_hClusEnum == NULL )
  160. {
  161. hr = HRESULT_FROM_WIN32( TW32( GetLastError() ) );
  162. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_Resources_HrInit_ClusterOpenEnum_Failed, hr );
  163. goto Cleanup;
  164. }
  165. hr = S_OK;
  166. Cleanup:
  167. HRETURN( hr );
  168. } //*** CEnumCfgResources::HrInit
  169. // ************************************************************************
  170. //
  171. // IUnknown
  172. //
  173. // ************************************************************************
  174. //////////////////////////////////////////////////////////////////////////////
  175. //++
  176. //
  177. // CEnumCfgResources::QueryInterface
  178. //
  179. // Description:
  180. // Query this object for the passed in interface.
  181. //
  182. // Arguments:
  183. // riidIn
  184. // Id of interface requested.
  185. //
  186. // ppvOut
  187. // Pointer to the requested interface.
  188. //
  189. // Return Value:
  190. // S_OK
  191. // If the interface is available on this object.
  192. //
  193. // E_NOINTERFACE
  194. // If the interface is not available.
  195. //
  196. // E_POINTER
  197. // ppvOut was NULL.
  198. //
  199. // Remarks:
  200. // None.
  201. //
  202. //--
  203. //////////////////////////////////////////////////////////////////////////////
  204. STDMETHODIMP
  205. CEnumCfgResources::QueryInterface(
  206. REFIID riidIn
  207. , void ** ppvOut
  208. )
  209. {
  210. TraceQIFunc( riidIn, ppvOut );
  211. HRESULT hr = S_OK;
  212. //
  213. // Validate arguments.
  214. //
  215. Assert( ppvOut != NULL );
  216. if ( ppvOut == NULL )
  217. {
  218. hr = THR( E_POINTER );
  219. goto Cleanup;
  220. }
  221. //
  222. // Handle known interfaces.
  223. //
  224. if ( IsEqualIID( riidIn, IID_IUnknown ) )
  225. {
  226. *ppvOut = static_cast< IEnumClusCfgManagedResources * >( this );
  227. } // if: IUnknown
  228. else if ( IsEqualIID( riidIn, IID_IEnumClusCfgManagedResources ) )
  229. {
  230. *ppvOut = TraceInterface( __THISCLASS__, IEnumClusCfgManagedResources, this, 0 );
  231. } // else if: IEnumClusCfgManagedResources
  232. else
  233. {
  234. *ppvOut = NULL;
  235. hr = E_NOINTERFACE;
  236. } // else
  237. //
  238. // Add a reference to the interface if successful.
  239. //
  240. if ( SUCCEEDED( hr ) )
  241. {
  242. ((IUnknown*) *ppvOut)->AddRef();
  243. } // if: success
  244. Cleanup:
  245. QIRETURN_IGNORESTDMARSHALLING( hr, riidIn );
  246. } //*** CEnumCfgResources::QueryInterface
  247. //////////////////////////////////////////////////////////////////////////////
  248. //
  249. // STDMETHODIMP_(ULONG)
  250. // CEnumCfgResources::AddRef
  251. //
  252. //////////////////////////////////////////////////////////////////////////////
  253. STDMETHODIMP_( ULONG )
  254. CEnumCfgResources::AddRef( void )
  255. {
  256. TraceFunc( "[IUnknown]" );
  257. InterlockedIncrement( &m_cRef );
  258. CRETURN( m_cRef );
  259. } //*** CEnumCfgResources::AddRef
  260. //////////////////////////////////////////////////////////////////////////////
  261. //
  262. // STDMETHODIMP_(ULONG)
  263. // CEnumCfgResources::Release
  264. //
  265. //////////////////////////////////////////////////////////////////////////////
  266. STDMETHODIMP_( ULONG )
  267. CEnumCfgResources::Release( void )
  268. {
  269. TraceFunc( "[IUnknown]" );
  270. LONG cRef;
  271. cRef = InterlockedDecrement( &m_cRef );
  272. if ( cRef == 0 )
  273. {
  274. TraceDo( delete this );
  275. }
  276. CRETURN( cRef );
  277. } //*** CEnumCfgResources::Release
  278. //****************************************************************************
  279. //
  280. // IEnumClusCfgManagedResources
  281. //
  282. //****************************************************************************
  283. //
  284. //
  285. //
  286. STDMETHODIMP
  287. CEnumCfgResources::Next(
  288. ULONG cNumberRequestedIn,
  289. IClusCfgManagedResourceInfo ** rgpManagedResourceInfoOut,
  290. ULONG * pcNumberFetchedOut
  291. )
  292. {
  293. TraceFunc( "[IEnumClusCfgManagedResources]" );
  294. HRESULT hr;
  295. ULONG cFetched = 0;
  296. if ( rgpManagedResourceInfoOut == NULL )
  297. {
  298. hr= THR( E_POINTER );
  299. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_Resources_Next_InvalidPointer, hr );
  300. goto Cleanup;
  301. }
  302. for( ; cFetched < cNumberRequestedIn; m_dwIndex++ )
  303. {
  304. hr = STHR( HrGetItem( &(rgpManagedResourceInfoOut[ cFetched ]) ) );
  305. if ( FAILED( hr ) )
  306. {
  307. goto Cleanup;
  308. }
  309. if ( hr == S_FALSE )
  310. {
  311. continue; // resource was not type physical disk
  312. }
  313. if ( hr == MAKE_HRESULT( 0, FACILITY_WIN32, ERROR_NO_MORE_ITEMS ) )
  314. {
  315. break; // no more items
  316. }
  317. cFetched ++;
  318. } // for: cFetched
  319. if ( pcNumberFetchedOut != NULL )
  320. {
  321. *pcNumberFetchedOut = cFetched;
  322. } // if:
  323. if ( cFetched < cNumberRequestedIn )
  324. {
  325. hr = S_FALSE;
  326. } // if:
  327. else
  328. {
  329. hr = S_OK;
  330. }
  331. Cleanup:
  332. if ( FAILED( hr ) )
  333. {
  334. ULONG idx;
  335. for ( idx = 0; idx < cFetched; idx++ )
  336. {
  337. (rgpManagedResourceInfoOut[ idx ])->Release();
  338. } // for:
  339. cFetched = 0;
  340. } // if:
  341. HRETURN( hr );
  342. } //*** CEnumCfgResources::Next
  343. //
  344. //
  345. //
  346. STDMETHODIMP
  347. CEnumCfgResources::Reset( void )
  348. {
  349. TraceFunc( "[IEnumClusCfgManagedResources]" );
  350. HRESULT hr = S_OK;
  351. m_dwIndex = 0;
  352. HRETURN( hr );
  353. } //*** CEnumCfgResources::Reset
  354. //
  355. //
  356. //
  357. STDMETHODIMP
  358. CEnumCfgResources::Skip( ULONG cNumberToSkipIn )
  359. {
  360. TraceFunc( "[IEnumClusCfgManagedResources]" );
  361. HRESULT hr = S_OK;
  362. //
  363. // TODO: GalenB 27 SEPT 2000
  364. //
  365. // Need to ensure that we don't run off the end of the enumeration.
  366. //
  367. m_dwIndex += cNumberToSkipIn;
  368. HRETURN( hr );
  369. } //*** CEnumCfgResources::Skip
  370. //
  371. //
  372. //
  373. STDMETHODIMP
  374. CEnumCfgResources::Clone( IEnumClusCfgManagedResources ** ppEnumManagedResourcesOut )
  375. {
  376. TraceFunc( "[IEnumClusCfgManagedResources]" );
  377. HRESULT hr = THR( E_NOTIMPL );
  378. HRETURN( hr );
  379. } //*** CEnumCfgResourcess::Clone
  380. //
  381. //
  382. //
  383. STDMETHODIMP
  384. CEnumCfgResources::Count( DWORD * pnCountOut)
  385. {
  386. TraceFunc( "[IEnumClusCfgManagedResources]" );
  387. Assert( m_hClusEnum != NULL );
  388. HRESULT hr = S_OK;
  389. if ( pnCountOut == NULL )
  390. {
  391. hr = THR( E_POINTER );
  392. goto Cleanup;
  393. }
  394. *pnCountOut = ClusterGetEnumCount(m_hClusEnum);
  395. Cleanup:
  396. HRETURN( hr );
  397. } //*** CEnumCfgResourcess::Count
  398. //****************************************************************************
  399. //
  400. // IClusCfgCallback
  401. //
  402. //****************************************************************************
  403. //////////////////////////////////////////////////////////////////////////////
  404. //++
  405. //
  406. // CEnumCfgResources::SendStatusReport
  407. //
  408. // Description:
  409. //
  410. // Arguments:
  411. //
  412. // Return Value:
  413. //
  414. // Remarks:
  415. // None.
  416. //
  417. //--
  418. //////////////////////////////////////////////////////////////////////////////
  419. STDMETHODIMP
  420. CEnumCfgResources::SendStatusReport(
  421. BSTR bstrNodeNameIn,
  422. CLSID clsidTaskMajorIn,
  423. CLSID clsidTaskMinorIn,
  424. ULONG ulMinIn,
  425. ULONG ulMaxIn,
  426. ULONG ulCurrentIn,
  427. HRESULT hrStatusIn,
  428. BSTR bstrDescriptionIn,
  429. FILETIME * pftTimeIn,
  430. BSTR bstrReferenceIn
  431. )
  432. {
  433. TraceFunc( "[IClusCfgCallback]" );
  434. HRESULT hr = S_OK;
  435. if ( m_pcccb != NULL )
  436. {
  437. hr = THR( m_pcccb->SendStatusReport( bstrNodeNameIn,
  438. clsidTaskMajorIn,
  439. clsidTaskMinorIn,
  440. ulMinIn,
  441. ulMaxIn,
  442. ulCurrentIn,
  443. hrStatusIn,
  444. bstrDescriptionIn,
  445. pftTimeIn,
  446. bstrReferenceIn
  447. ) );
  448. } // if:
  449. HRETURN( hr );
  450. } //*** CEnumCfgResources::SendStatusReport
  451. //****************************************************************************
  452. //
  453. // Local methods.
  454. //
  455. //****************************************************************************
  456. //
  457. //
  458. //
  459. HRESULT
  460. CEnumCfgResources::HrGetItem(
  461. IClusCfgManagedResourceInfo ** ppManagedResourceInfoOut
  462. )
  463. {
  464. TraceFunc( "" );
  465. HRESULT hr = S_OK;
  466. DWORD sc;
  467. DWORD dwTypeDummy;
  468. DWORD cchName = 64; // good starting value
  469. BSTR bstrName = NULL;
  470. IUnknown * punk = NULL;
  471. Assert( ppManagedResourceInfoOut != NULL );
  472. Assert( m_hClusEnum != NULL );
  473. bstrName = TraceSysAllocStringLen( NULL, cchName );
  474. if ( bstrName == NULL )
  475. {
  476. hr = THR( E_OUTOFMEMORY );
  477. goto Cleanup;
  478. }
  479. cchName ++; // SysAllocStringLen allocates cchName + 1.
  480. // We are wrapping this a cchName should be significantly large enough to handle
  481. // most of our testing.
  482. sc = ClusterEnum( m_hClusEnum, m_dwIndex, &dwTypeDummy, bstrName, &cchName );
  483. if ( sc == ERROR_MORE_DATA )
  484. {
  485. //
  486. // Our "typical" buffer is too small. Try make it to the size ClusterEnum
  487. // returned.
  488. //
  489. TraceSysFreeString( bstrName );
  490. bstrName = NULL;
  491. bstrName = TraceSysAllocStringLen( NULL, cchName );
  492. if ( bstrName == NULL )
  493. {
  494. hr = THR( E_OUTOFMEMORY );
  495. goto Cleanup;
  496. }
  497. cchName ++; // SysAllocStringLen allocates cchName + 1.
  498. sc = TW32( ClusterEnum( m_hClusEnum, m_dwIndex, &dwTypeDummy, bstrName, &cchName ) );
  499. }
  500. else if ( sc == ERROR_NO_MORE_ITEMS )
  501. {
  502. hr = MAKE_HRESULT( 0, FACILITY_WIN32, ERROR_NO_MORE_ITEMS );
  503. goto Cleanup;
  504. }
  505. if ( sc != ERROR_SUCCESS )
  506. {
  507. hr = HRESULT_FROM_WIN32( TW32( sc ) );
  508. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_Resources_HrGetItem_ClusterEnum_Failed, hr );
  509. goto Cleanup;
  510. }
  511. Assert( dwTypeDummy == CLUSTER_ENUM_RESOURCE );
  512. //
  513. // Create the requested object and store it.
  514. //
  515. hr = STHR( CResourcePhysicalDisk::S_HrCreateInstance( &punk, m_punkOuter, m_phCluster, m_pclsidMajor, bstrName ) );
  516. if ( FAILED( hr ) )
  517. {
  518. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_HrGetItem_Create_CResourcePhysicalDisk_Failed, hr );
  519. goto Cleanup;
  520. }
  521. if ( hr == S_FALSE )
  522. {
  523. goto Cleanup; // This means that the object was not a physical disk resource.
  524. }
  525. //
  526. // QI for the interface to return.
  527. //
  528. hr = THR( punk->TypeSafeQI( IClusCfgManagedResourceInfo, ppManagedResourceInfoOut ) );
  529. if ( FAILED( hr ) )
  530. {
  531. SSR_W2KPROXY_STATUS( TASKID_Major_Client_And_Server_Log, TASKID_Minor_W2KProxy_Resources_HrGetItem_QI_Failed, hr );
  532. goto Cleanup;
  533. }
  534. Cleanup:
  535. TraceSysFreeString( bstrName );
  536. if ( punk != NULL )
  537. {
  538. punk->Release();
  539. }
  540. HRETURN( hr );
  541. } //*** CEnumCfgResources::HrGetItem