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.

551 lines
13 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2000-2001 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // TaskGatherClusterInfo.cpp
  7. //
  8. // Description:
  9. // TaskGatherClusterInfo implementation.
  10. //
  11. // Maintained By:
  12. // Galen Barbee (GalenB) 07-APR-2000
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "pch.h"
  16. #include "TaskGatherClusterInfo.h"
  17. DEFINE_THISCLASS("CTaskGatherClusterInfo")
  18. // ************************************************************************
  19. //
  20. // Constructor / Destructor
  21. //
  22. // ************************************************************************
  23. //////////////////////////////////////////////////////////////////////////////
  24. //
  25. // HRESULT
  26. // CTaskGatherClusterInfo::S_HrCreateInstance(
  27. // IUnknown ** ppunkOut
  28. // )
  29. //
  30. //////////////////////////////////////////////////////////////////////////////
  31. HRESULT
  32. CTaskGatherClusterInfo::S_HrCreateInstance(
  33. IUnknown ** ppunkOut
  34. )
  35. {
  36. TraceFunc( "" );
  37. Assert( ppunkOut != NULL );
  38. HRESULT hr;
  39. CTaskGatherClusterInfo * ptgci = new CTaskGatherClusterInfo;
  40. if ( ptgci != NULL )
  41. {
  42. hr = THR( ptgci->Init() );
  43. if ( SUCCEEDED( hr ) )
  44. {
  45. hr = THR( ptgci->TypeSafeQI( IUnknown, ppunkOut ) );
  46. }
  47. ptgci->Release();
  48. // This gets passed to other threads.
  49. TraceMoveToMemoryList( ptgci, g_GlobalMemoryList );
  50. }
  51. else
  52. {
  53. hr = E_OUTOFMEMORY;
  54. }
  55. HRETURN( hr );
  56. } // S_HrCreateInstance()
  57. //////////////////////////////////////////////////////////////////////////////
  58. //
  59. // CTaskGatherClusterInfo::CTaskGatherClusterInfo( void )
  60. //
  61. //////////////////////////////////////////////////////////////////////////////
  62. CTaskGatherClusterInfo::CTaskGatherClusterInfo( void )
  63. {
  64. TraceFunc( "" );
  65. InterlockedIncrement( &g_cObjects );
  66. TraceFuncExit();
  67. } // CTaskGatherClusterInfo()
  68. //////////////////////////////////////////////////////////////////////////////
  69. //
  70. // STDMETHODIMP
  71. // CTaskGatherClusterInfo::Init( void )
  72. //
  73. //////////////////////////////////////////////////////////////////////////////
  74. STDMETHODIMP
  75. CTaskGatherClusterInfo::Init( void )
  76. {
  77. TraceFunc( "" );
  78. HRESULT hr = S_OK;
  79. // IUnknown stuff
  80. Assert( m_cRef == 0 );
  81. AddRef(); // Add one count
  82. // IDoTask / ITaskGatherClusterInfo
  83. Assert( m_cookie == NULL );
  84. HRETURN( hr );
  85. } // Init()
  86. //////////////////////////////////////////////////////////////////////////////
  87. //
  88. // CTaskGatherClusterInfo::~CTaskGatherClusterInfo()
  89. //
  90. //////////////////////////////////////////////////////////////////////////////
  91. CTaskGatherClusterInfo::~CTaskGatherClusterInfo()
  92. {
  93. TraceFunc( "" );
  94. //
  95. // This keeps the per thread memory tracking from screaming.
  96. //
  97. TraceMoveFromMemoryList( this, g_GlobalMemoryList );
  98. InterlockedDecrement( &g_cObjects );
  99. TraceFuncExit();
  100. } // ~CTaskGatherClusterInfo()
  101. // ************************************************************************
  102. //
  103. // IUnknown
  104. //
  105. // ************************************************************************
  106. //////////////////////////////////////////////////////////////////////////////
  107. //
  108. // STDMETHODIMP
  109. // CTaskGatherClusterInfo::QueryInterface(
  110. // REFIID riid,
  111. // LPVOID *ppv
  112. // )
  113. //
  114. //////////////////////////////////////////////////////////////////////////////
  115. STDMETHODIMP
  116. CTaskGatherClusterInfo::QueryInterface(
  117. REFIID riid,
  118. LPVOID *ppv
  119. )
  120. {
  121. TraceQIFunc( riid, ppv );
  122. HRESULT hr = E_NOINTERFACE;
  123. if ( IsEqualIID( riid, IID_IUnknown ) )
  124. {
  125. *ppv = static_cast< ITaskGatherClusterInfo * >( this );
  126. hr = S_OK;
  127. } // if: IUnknown
  128. else if ( IsEqualIID( riid, IID_IDoTask ) )
  129. {
  130. *ppv = TraceInterface( __THISCLASS__, IDoTask, this, 0 );
  131. hr = S_OK;
  132. } // else if: IDoTask
  133. else if ( IsEqualIID( riid, IID_ITaskGatherClusterInfo ) )
  134. {
  135. *ppv = TraceInterface( __THISCLASS__, ITaskGatherClusterInfo, this, 0 );
  136. hr = S_OK;
  137. } // else if: IClusCfgManagedResourceInfo
  138. if ( SUCCEEDED( hr ) )
  139. {
  140. ((IUnknown*) *ppv)->AddRef();
  141. } // if: success
  142. QIRETURN_IGNORESTDMARSHALLING( hr, riid );
  143. } // QueryInterface()
  144. //////////////////////////////////////////////////////////////////////////////
  145. //
  146. // STDMETHODIMP_(ULONG)
  147. // CTaskGatherClusterInfo::AddRef( void )
  148. //
  149. //////////////////////////////////////////////////////////////////////////////
  150. STDMETHODIMP_(ULONG)
  151. CTaskGatherClusterInfo::AddRef( void )
  152. {
  153. TraceFunc( "[IUnknown]" );
  154. InterlockedIncrement( &m_cRef );
  155. RETURN( m_cRef );
  156. } // AddRef()
  157. //////////////////////////////////////////////////////////////////////////////
  158. //
  159. // STDMETHODIMP_(ULONG)
  160. // CTaskGatherClusterInfo::Release( void )
  161. //
  162. //////////////////////////////////////////////////////////////////////////////
  163. STDMETHODIMP_(ULONG)
  164. CTaskGatherClusterInfo::Release( void )
  165. {
  166. TraceFunc( "[IUnknown]" );
  167. InterlockedDecrement( &m_cRef );
  168. if ( m_cRef )
  169. RETURN( m_cRef );
  170. TraceDo( delete this );
  171. RETURN(0);
  172. } // Release()
  173. // ************************************************************************
  174. //
  175. // IDoTask / ITaskGatherClusterInfo
  176. //
  177. // ************************************************************************
  178. //////////////////////////////////////////////////////////////////////////////
  179. //
  180. // STDMETHODIMP
  181. // CTaskGatherClusterInfo::BeginTask( void );
  182. //
  183. //////////////////////////////////////////////////////////////////////////////
  184. STDMETHODIMP
  185. CTaskGatherClusterInfo::BeginTask( void )
  186. {
  187. TraceFunc( "[IDoTask]" );
  188. HRESULT hr;
  189. IServiceProvider * psp = NULL;
  190. IUnknown * punk = NULL;
  191. IObjectManager * pom = NULL;
  192. IConnectionManager * pcm = NULL;
  193. IConnectionPointContainer * pcpc = NULL;
  194. IConnectionPoint * pcp = NULL;
  195. INotifyUI * pnui = NULL;
  196. INotificationManager * pnm = NULL;
  197. IClusCfgNodeInfo * pccni = NULL;
  198. IClusCfgServer * pccs = NULL;
  199. IGatherData * pgd = NULL;
  200. IClusCfgClusterInfo * pccci = NULL;
  201. TraceInitializeThread( L"TaskGatherClusterInfo" );
  202. //
  203. // Collect the manager we need to complete this task.
  204. //
  205. hr = THR( CoCreateInstance( CLSID_ServiceManager,
  206. NULL,
  207. CLSCTX_INPROC_SERVER,
  208. TypeSafeParams( IServiceProvider, &psp )
  209. ) );
  210. if ( FAILED( hr ) )
  211. goto Cleanup;
  212. hr = THR( psp->TypeSafeQS( CLSID_ObjectManager,
  213. IObjectManager,
  214. &pom
  215. ) );
  216. if ( FAILED( hr ) )
  217. goto Cleanup;
  218. hr = THR( psp->TypeSafeQS( CLSID_ClusterConnectionManager,
  219. IConnectionManager,
  220. &pcm
  221. ) );
  222. if ( FAILED( hr ) )
  223. goto Cleanup;
  224. hr = THR( psp->TypeSafeQS( CLSID_NotificationManager,
  225. IConnectionPointContainer,
  226. &pcpc
  227. ) );
  228. if ( FAILED( hr ) )
  229. goto Cleanup;
  230. hr = THR( pcpc->FindConnectionPoint( IID_INotifyUI, &pcp ) );
  231. if ( FAILED( hr ) )
  232. goto Cleanup;
  233. pcp = TraceInterface( L"CTaskGatherClusterInfo!IConnectionPoint", IConnectionPoint, pcp, 1 );
  234. hr = THR( pcp->TypeSafeQI( INotifyUI, &pnui ) );
  235. if ( FAILED( hr ) )
  236. goto Cleanup;
  237. pnui = TraceInterface( L"CTaskGatherClusterInfo!INotifyUI", INotifyUI, pnui, 1 );
  238. psp->Release();
  239. psp = NULL;
  240. //
  241. // Ask the Connection Manager for a connection to the object.
  242. //
  243. // don't wrap - this can fail.
  244. hr = pcm->GetConnectionToObject( m_cookie,
  245. &punk
  246. );
  247. //
  248. // This means the cluster has not been created yet.
  249. //
  250. if ( hr == HR_S_RPC_S_SERVER_UNAVAILABLE )
  251. {
  252. goto ReportStatus;
  253. }
  254. // HR_S_RPC_S_CLUSTER_NODE_DOWN
  255. else if ( FAILED( hr ) )
  256. {
  257. THR( hr );
  258. goto ReportStatus;
  259. }
  260. hr = THR( punk->TypeSafeQI( IClusCfgServer, &pccs ) );
  261. if ( FAILED( hr ) )
  262. goto Cleanup;
  263. punk->Release();
  264. punk = NULL;
  265. //
  266. // Get the Node information.
  267. //
  268. hr = THR( pccs->GetClusterNodeInfo( &pccni ) );
  269. if ( FAILED( hr ) )
  270. goto ReportStatus;
  271. //
  272. // See if the node is a member of a cluster.
  273. //
  274. hr = STHR( pccni->IsMemberOfCluster() );
  275. if ( FAILED( hr ) )
  276. goto ReportStatus;
  277. //
  278. // If it is not a cluster, then there is nothing to do the "default"
  279. // configuration will do.
  280. //
  281. if ( hr == S_FALSE )
  282. {
  283. hr = S_OK;
  284. goto ReportStatus;
  285. }
  286. //
  287. // Ask the Node for the Cluster Information.
  288. //
  289. hr = THR( pccni->GetClusterConfigInfo( &pccci ) );
  290. if ( FAILED( hr ) )
  291. goto ReportStatus;
  292. //
  293. // Ask the Object Manager to retrieve the data format to store the information.
  294. //
  295. Assert( punk == NULL );
  296. hr = THR( pom->GetObject( DFGUID_ClusterConfigurationInfo, m_cookie, &punk ) );
  297. if ( FAILED( hr ) )
  298. goto ReportStatus;
  299. hr = THR( punk->TypeSafeQI( IGatherData, &pgd ) );
  300. if ( FAILED( hr ) )
  301. goto ReportStatus;
  302. //
  303. // Start sucking.
  304. //
  305. hr = THR( pgd->Gather( NULL, pccci ) );
  306. //
  307. // Update the status. Ignore the error (if any).
  308. //
  309. ReportStatus:
  310. if ( pom != NULL )
  311. {
  312. HRESULT hr2;
  313. IUnknown * punk;
  314. hr2 = THR( pom->GetObject( DFGUID_StandardInfo,
  315. m_cookie,
  316. &punk
  317. ) );
  318. if ( SUCCEEDED( hr2 ) )
  319. {
  320. IStandardInfo * psi;
  321. hr2 = THR( punk->TypeSafeQI( IStandardInfo, &psi ) );
  322. punk->Release();
  323. if ( SUCCEEDED( hr2 ) )
  324. {
  325. hr2 = THR( psi->SetStatus( hr ) );
  326. psi->Release();
  327. }
  328. }
  329. }
  330. if ( pnui != NULL )
  331. {
  332. THR( pnui->ObjectChanged( m_cookie ) );
  333. }
  334. Cleanup:
  335. if ( psp != NULL )
  336. {
  337. psp->Release();
  338. }
  339. if ( pcm != NULL )
  340. {
  341. pcm->Release();
  342. }
  343. if ( pccs != NULL )
  344. {
  345. pccs->Release();
  346. }
  347. if ( pccni != NULL )
  348. {
  349. pccni->Release();
  350. }
  351. if ( punk != NULL )
  352. {
  353. punk->Release();
  354. }
  355. if ( pom != NULL )
  356. {
  357. HRESULT hr2;
  358. IUnknown * punk;
  359. hr2 = THR( pom->GetObject( DFGUID_StandardInfo,
  360. m_cookieCompletion,
  361. &punk
  362. ) );
  363. if ( SUCCEEDED( hr2 ) )
  364. {
  365. IStandardInfo * psi;
  366. hr2 = THR( punk->TypeSafeQI( IStandardInfo, &psi ) );
  367. punk->Release();
  368. if ( SUCCEEDED( hr2 ) )
  369. {
  370. hr2 = THR( psi->SetStatus( hr ) );
  371. psi->Release();
  372. }
  373. }
  374. pom->Release();
  375. }
  376. if ( pgd != NULL )
  377. {
  378. pgd->Release();
  379. }
  380. if ( pccci != NULL )
  381. {
  382. pccci->Release();
  383. }
  384. if ( pcp != NULL )
  385. {
  386. pcp->Release();
  387. }
  388. if ( pcpc != NULL )
  389. {
  390. pcpc->Release();
  391. }
  392. if ( pnui !=NULL )
  393. {
  394. if ( m_cookieCompletion != 0 )
  395. {
  396. THR( pnui->ObjectChanged( m_cookieCompletion ) );
  397. }
  398. pnui->Release();
  399. }
  400. HRETURN( hr );
  401. } // BeginTask()
  402. //////////////////////////////////////////////////////////////////////////////
  403. //
  404. // STDMETHODIMP
  405. // CTaskGatherClusterInfo::StopTask( void )
  406. //
  407. //////////////////////////////////////////////////////////////////////////////
  408. STDMETHODIMP
  409. CTaskGatherClusterInfo::StopTask( void )
  410. {
  411. TraceFunc( "[IDoTask]" );
  412. HRESULT hr = S_OK;
  413. HRETURN( hr );
  414. } //*** StopTask
  415. //////////////////////////////////////////////////////////////////////////////
  416. //
  417. // STDMETHODIMP
  418. // CTaskGatherClusterInfo::SetCookie(
  419. // OBJECTCOOKIE cookieIn
  420. // )
  421. //
  422. //////////////////////////////////////////////////////////////////////////////
  423. STDMETHODIMP
  424. CTaskGatherClusterInfo::SetCookie(
  425. OBJECTCOOKIE cookieIn
  426. )
  427. {
  428. TraceFunc( "[ITaskGatherClusterInfo]" );
  429. HRESULT hr = S_OK;
  430. m_cookie = cookieIn;
  431. HRETURN( hr );
  432. } //*** SetCookie
  433. //////////////////////////////////////////////////////////////////////////////
  434. //
  435. // STDMETHODIMP
  436. // CTaskGatherClusterInfo::SetCompletionCookie(
  437. // OBJECTCOOKIE cookieIn
  438. // )
  439. //
  440. //////////////////////////////////////////////////////////////////////////////
  441. STDMETHODIMP
  442. CTaskGatherClusterInfo::SetCompletionCookie(
  443. OBJECTCOOKIE cookieIn
  444. )
  445. {
  446. TraceFunc( "" );
  447. HRESULT hr = S_OK;
  448. m_cookieCompletion = cookieIn;
  449. HRETURN( hr );
  450. } // SetGatherPunk()