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.

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