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.

669 lines
18 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1996-2002 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // CluAdmExDataObj.h
  7. //
  8. // Implementation File:
  9. // CCluAdmExDataObject.cpp
  10. //
  11. // Description:
  12. // Definition of the CCluAdmExDataObject class, which is the IDataObject
  13. // class used to transfer data between a cluster management tool and the
  14. // extension DLL handlers.
  15. //
  16. // Author:
  17. // David Potter (davidp) June 4, 1996
  18. //
  19. // Revision History:
  20. //
  21. // Notes:
  22. //
  23. /////////////////////////////////////////////////////////////////////////////
  24. #pragma once
  25. #ifndef __CLUADMEXDATAOBJ_H_
  26. #define __CLUADMEXDATAOBJ_H_
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Include Files
  29. /////////////////////////////////////////////////////////////////////////////
  30. #ifndef __cluadmex_h__
  31. #include "CluAdmEx.h" // for IIDs
  32. #endif
  33. #ifndef __cluadmexhostsvr_h__
  34. #include "CluAdmExHostSvr.h" // for CLSIDs
  35. #endif
  36. #ifndef __CLUSOBJ_H_
  37. #include "ClusObj.h" // for CClusterObject
  38. #endif
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Type Declarations
  41. /////////////////////////////////////////////////////////////////////////////
  42. typedef BOOL (*PFGETRESOURCENETWORKNAME)(
  43. OUT BSTR lpszNetName,
  44. IN OUT DWORD * pcchNetName,
  45. IN OUT PVOID pvContext
  46. );
  47. /////////////////////////////////////////////////////////////////////////////
  48. // Forward Class Declarations
  49. /////////////////////////////////////////////////////////////////////////////
  50. class CCluAdmExDataObject;
  51. /////////////////////////////////////////////////////////////////////////////
  52. // External Class Declarations
  53. /////////////////////////////////////////////////////////////////////////////
  54. class CClusterObject;
  55. /////////////////////////////////////////////////////////////////////////////
  56. //++
  57. //
  58. // class CCluAdmExDataObject
  59. //
  60. // Description:
  61. // Encapsulates the IDataObject interface for exchanging data with
  62. // extension DLL handlers.
  63. //
  64. // Inheritance:
  65. // CCluAdmExDataObject
  66. // CComObjectRootEx<>, CComCoClass<>, <interface classes>
  67. //
  68. //--
  69. /////////////////////////////////////////////////////////////////////////////
  70. class CCluAdmExDataObject :
  71. public CComObjectRootEx< CComSingleThreadModel >,
  72. public CComCoClass< CCluAdmExDataObject, &CLSID_CoCluAdmExHostSvrData >,
  73. public ISupportErrorInfo,
  74. public IGetClusterUIInfo,
  75. public IGetClusterDataInfo,
  76. public IGetClusterObjectInfo,
  77. public IGetClusterNodeInfo,
  78. public IGetClusterGroupInfo,
  79. public IGetClusterResourceInfo,
  80. public IGetClusterNetworkInfo,
  81. public IGetClusterNetInterfaceInfo
  82. {
  83. public:
  84. //
  85. // Construction
  86. //
  87. // Default constructor
  88. CCluAdmExDataObject( void )
  89. {
  90. m_pco = NULL;
  91. m_lcid = NULL;
  92. m_hfont = NULL;
  93. m_hicon = NULL;
  94. m_pfGetResNetName = NULL;
  95. // m_pModuleState = AfxGetModuleState();
  96. // ATLASSERT( m_pModuleState != NULL );
  97. } //*** CCluAdmExDataObject()
  98. // Destructor
  99. virtual ~CCluAdmExDataObject( void )
  100. {
  101. // m_pModuleState = NULL;
  102. } //*** ~CCluAdmExDataObject()
  103. // Second-phase constructor.
  104. void Init(
  105. IN OUT CClusterObject * pco,
  106. IN LCID lcid,
  107. IN HFONT hfont,
  108. IN HICON hicon
  109. )
  110. {
  111. ATLASSERT( pco != NULL );
  112. ATLASSERT( pco->Pci() != NULL );
  113. ATLASSERT( pco->Pci()->Hcluster() != NULL );
  114. // Save parameters.
  115. m_pco = pco;
  116. m_lcid = lcid;
  117. m_hfont = hfont;
  118. m_hicon = hicon;
  119. } //*** Init()
  120. //
  121. // Map interfaces to this class.
  122. //
  123. BEGIN_COM_MAP( CCluAdmExDataObject )
  124. COM_INTERFACE_ENTRY( IGetClusterUIInfo )
  125. COM_INTERFACE_ENTRY( IGetClusterDataInfo )
  126. COM_INTERFACE_ENTRY( IGetClusterObjectInfo )
  127. COM_INTERFACE_ENTRY( IGetClusterNodeInfo )
  128. COM_INTERFACE_ENTRY( IGetClusterGroupInfo )
  129. COM_INTERFACE_ENTRY( IGetClusterResourceInfo )
  130. COM_INTERFACE_ENTRY( IGetClusterNetworkInfo )
  131. COM_INTERFACE_ENTRY( IGetClusterNetInterfaceInfo )
  132. COM_INTERFACE_ENTRY( ISupportErrorInfo )
  133. END_COM_MAP()
  134. DECLARE_NOT_AGGREGATABLE( CCluAdmExDataObject )
  135. protected:
  136. //
  137. // Properties of this data object.
  138. //
  139. CClusterObject * m_pco; // Cluster object being extended.
  140. LCID m_lcid; // Locale ID of resources to be loaded by extension.
  141. HFONT m_hfont; // Font for all text.
  142. HICON m_hicon; // Icon for upper left corner.
  143. PFGETRESOURCENETWORKNAME m_pfGetResNetName; // Pointer to static function for getting net name for resource.
  144. PVOID m_pvGetResNetNameContext; // Context for m_pfGetResNetName;
  145. static const IID * s_rgiid[]; // Array of interface IDs supported by this class.
  146. //
  147. // Accessor methods.
  148. //
  149. HCLUSTER Hcluster( void ) const
  150. {
  151. ATLASSERT( m_pco != NULL );
  152. ATLASSERT( m_pco->Pci() != NULL );
  153. return m_pco->Pci()->Hcluster();
  154. } //*** Hcluster()
  155. CClusterObject * Pco( void ) const { return m_pco; }
  156. LCID Lcid( void ) const { return m_lcid; }
  157. HFONT Hfont( void ) const { return m_hfont; }
  158. HICON Hicon( void ) const { return m_hicon; }
  159. public:
  160. PFGETRESOURCENETWORKNAME PfGetResNetName( void ) const { return m_pfGetResNetName; }
  161. // Set the function pointer for getting the resource name
  162. void SetPfGetResNetName( PFGETRESOURCENETWORKNAME pfGetResNetName, PVOID pvContext )
  163. {
  164. m_pfGetResNetName = pfGetResNetName;
  165. m_pvGetResNetNameContext = pvContext;
  166. } //*** SetPfGetResNetName()
  167. public:
  168. //
  169. // ISupportsErrorInfo methods.
  170. //
  171. // Determine if interface supports IErrorInfo
  172. STDMETHOD( InterfaceSupportsErrorInfo )( REFIID riid )
  173. {
  174. const IID ** piid;
  175. for ( piid = s_rgiid ; *piid != NULL ; piid++ )
  176. {
  177. if ( InlineIsEqualGUID( **piid, riid ) )
  178. {
  179. return S_OK;
  180. } // if: matching IID found
  181. }
  182. return S_FALSE;
  183. } //*** InterfaceSupportsErrorInfo()
  184. public:
  185. //
  186. // IGetClusterUIInfo methods.
  187. //
  188. // Get the locale of the running program
  189. STDMETHOD_( LCID, GetLocale )( void )
  190. {
  191. return Lcid();
  192. } //*** GetLocale()
  193. // Get the font to use for text on property pages
  194. STDMETHOD_( HFONT, GetFont )( void )
  195. {
  196. return Hfont();
  197. } //*** GetFont()
  198. // Get the icon to use for the upper left corner
  199. STDMETHOD_( HICON, GetIcon )( void )
  200. {
  201. return Hicon();
  202. } //*** GetIcon()
  203. public:
  204. //
  205. // IGetClusterDataInfo methods.
  206. //
  207. // Get the name of the cluster
  208. STDMETHOD( GetClusterName )(
  209. OUT BSTR lpszName,
  210. IN OUT LONG * pcchName
  211. )
  212. {
  213. ATLASSERT( Pco() != NULL );
  214. ATLASSERT( Pco()->Pci() != NULL );
  215. HRESULT hr;
  216. //
  217. // Validate parameters.
  218. //
  219. if ( pcchName == NULL )
  220. {
  221. return E_INVALIDARG;
  222. }
  223. //
  224. // Copy the name to the caller's buffer.
  225. //
  226. hr = GetStringProperty(
  227. Pco()->Pci()->RstrName(),
  228. lpszName,
  229. pcchName
  230. );
  231. return hr;
  232. } //*** GetClusterName()
  233. // Get a handle to the cluster
  234. STDMETHOD_( HCLUSTER, GetClusterHandle )( void )
  235. {
  236. return Hcluster();
  237. } //*** GetClusterHandle()
  238. // Get the number of objects currently selected
  239. STDMETHOD_( LONG, GetObjectCount )( void )
  240. {
  241. //
  242. // We only support one selected object at a time for now.
  243. //
  244. return 1;
  245. } //*** GetObjectCount()
  246. public:
  247. //
  248. // IGetClusterObjectInfo methods.
  249. //
  250. // Get the name of the object at the specified index
  251. STDMETHOD( GetObjectName )(
  252. IN LONG nObjIndex,
  253. OUT BSTR lpszName,
  254. IN OUT LONG * pcchName
  255. )
  256. {
  257. ATLASSERT( Pco() != NULL );
  258. HRESULT hr;
  259. //
  260. // Validate parameters.
  261. // We only support one selected object at a time for now.
  262. //
  263. if ( (nObjIndex != 0) || (pcchName == NULL) )
  264. {
  265. return E_INVALIDARG;
  266. } // if: wrong object index or no count buffer
  267. //
  268. // Copy the name to the caller's buffer.
  269. //
  270. hr = GetStringProperty(
  271. Pco()->RstrName(),
  272. lpszName,
  273. pcchName
  274. );
  275. return hr;
  276. } //*** GetObjectName()
  277. // Get the type of the object at the specified index
  278. STDMETHOD_( CLUADMEX_OBJECT_TYPE, GetObjectType )(
  279. IN LONG nObjIndex
  280. )
  281. {
  282. ATLASSERT( Pco() != NULL );
  283. //
  284. // Validate parameters.
  285. // We only support one selected object at a time for now.
  286. //
  287. if ( nObjIndex == 1 )
  288. {
  289. SetLastError( (DWORD) E_INVALIDARG );
  290. return (CLUADMEX_OBJECT_TYPE) -1;
  291. } // if: invalid argument
  292. return Pco()->Cot();
  293. } //*** GetObjectType()
  294. public:
  295. //
  296. // IGetClusterNodeInfo methods.
  297. //
  298. // Get the handle to the node at the specified index
  299. STDMETHOD_( HNODE, GetNodeHandle )(
  300. IN LONG nObjIndex
  301. )
  302. {
  303. ATLASSERT( Pco() != NULL );
  304. //
  305. // Validate parameters.
  306. // We only support one selected object at a time for now.
  307. //
  308. if ( (nObjIndex == 1)
  309. || (Pco()->Cot() != CLUADMEX_OT_NODE) )
  310. {
  311. SetLastError( (DWORD) E_INVALIDARG );
  312. return NULL;
  313. } // if: invalid argument
  314. CClusNodeInfo * pni = reinterpret_cast< CClusNodeInfo * >( Pco() );
  315. return pni->Hnode();
  316. } //*** GetNodeHandle()
  317. public:
  318. //
  319. // IGetClusterGroupInfo methods.
  320. //
  321. // Get the handle to the group at the specified index
  322. STDMETHOD_( HGROUP, GetGroupHandle )(
  323. IN LONG nObjIndex
  324. )
  325. {
  326. ATLASSERT( Pco() != NULL );
  327. //
  328. // Validate parameters.
  329. // We only support one selected object at a time for now.
  330. //
  331. if ( (nObjIndex == 1)
  332. || (Pco()->Cot() != CLUADMEX_OT_GROUP) )
  333. {
  334. SetLastError( (DWORD) E_INVALIDARG );
  335. return NULL;
  336. } // if: invalid argument
  337. CClusGroupInfo * pgi = reinterpret_cast< CClusGroupInfo * >( Pco() );
  338. return pgi->Hgroup();
  339. } //*** GetGroupHandle()
  340. public:
  341. //
  342. // IGetClusterResourceInfo methods.
  343. //
  344. // Get the handle to the resource at the specified index
  345. STDMETHOD_( HRESOURCE, GetResourceHandle )(
  346. IN LONG nObjIndex
  347. )
  348. {
  349. ATLASSERT( Pco() != NULL );
  350. //
  351. // Validate parameters.
  352. // We only support one selected object at a time for now.
  353. //
  354. if ( (nObjIndex == 1)
  355. || (Pco()->Cot() != CLUADMEX_OT_RESOURCE) )
  356. {
  357. SetLastError( (DWORD) E_INVALIDARG );
  358. return NULL;
  359. } // if: invalid argument
  360. CClusResInfo * pri = reinterpret_cast< CClusResInfo * >( Pco() );
  361. return pri->Hresource();
  362. } //*** GetResourceHandle()
  363. // Get the type of the resource at the specified index
  364. STDMETHOD( GetResourceTypeName )(
  365. IN LONG nObjIndex,
  366. OUT BSTR lpszResourceTypeName,
  367. IN OUT LONG * pcchResTypeName
  368. )
  369. {
  370. ATLASSERT( Pco() != NULL );
  371. HRESULT hr;
  372. CClusResInfo * pri = reinterpret_cast< CClusResInfo * >( Pco() );
  373. //
  374. // Validate parameters.
  375. // We only support one selected object at a time for now.
  376. //
  377. if ( (nObjIndex != 0)
  378. || (pcchResTypeName == NULL)
  379. || (Pco()->Cot() != CLUADMEX_OT_RESOURCE) )
  380. {
  381. return E_INVALIDARG;
  382. } // if: invalid argument
  383. //
  384. // Copy the name to the caller's buffer.
  385. //
  386. ATLASSERT( pri->Prti() != NULL );
  387. hr = GetStringProperty(
  388. pri->Prti()->RstrName(),
  389. lpszResourceTypeName,
  390. pcchResTypeName
  391. );
  392. return hr;
  393. } //*** GetResourceTypeName()
  394. // Get the network name for the resource at the specified index
  395. STDMETHOD_( BOOL, GetResourceNetworkName )(
  396. IN LONG nObjIndex,
  397. OUT BSTR lpszNetName,
  398. IN OUT ULONG * pcchNetName
  399. )
  400. {
  401. ATLASSERT( Pco() != NULL );
  402. BOOL bSuccess = FALSE;
  403. CClusResInfo * pri = reinterpret_cast< CClusResInfo * >( Pco() );
  404. try
  405. {
  406. //
  407. // Validate parameters.
  408. // We only support one selected object at a time for now.
  409. //
  410. if ( (nObjIndex != 0)
  411. || (pcchNetName == NULL)
  412. || (*pcchNetName < MAX_COMPUTERNAME_LENGTH)
  413. || (Pco()->Cot() != CLUADMEX_OT_RESOURCE) )
  414. {
  415. SetLastError( (DWORD) E_INVALIDARG );
  416. return FALSE;
  417. } // if: invalid argument
  418. //
  419. // If there is a function for getting this information, call it.
  420. // Otherwise, handle it ourselves.
  421. //
  422. if ( PfGetResNetName() != NULL )
  423. {
  424. bSuccess = (*PfGetResNetName())( lpszNetName, pcchNetName, m_pvGetResNetNameContext );
  425. } // if: function specified for getting this info
  426. else
  427. {
  428. bSuccess = pri->BGetNetworkName( lpszNetName, pcchNetName );
  429. } // if: no function specified for getting this info
  430. } // try
  431. catch (...)
  432. {
  433. bSuccess = FALSE;
  434. SetLastError( (DWORD) E_INVALIDARG );
  435. } // catch: anything
  436. return bSuccess;
  437. } //*** GetResourceNetworkName()
  438. public:
  439. //
  440. // IGetClusterNetworkInfo methods.
  441. //
  442. // Get the handle to the network at the specified index
  443. STDMETHOD_( HNETWORK, GetNetworkHandle )(
  444. IN LONG nObjIndex
  445. )
  446. {
  447. ATLASSERT( Pco() != NULL );
  448. // Validate parameters.
  449. // We only support one selected object at a time for now.
  450. if ( (nObjIndex == 1)
  451. || (Pco()->Cot() != CLUADMEX_OT_NETWORK) )
  452. {
  453. SetLastError( (DWORD) E_INVALIDARG );
  454. return NULL;
  455. } // if: invalid argument
  456. CClusNetworkInfo * pni = reinterpret_cast< CClusNetworkInfo * >( Pco() );
  457. return pni->Hnetwork();
  458. } //*** GetNetworkHandle()
  459. public:
  460. //
  461. // IGetClusterNetInterfaceInfo methods.
  462. //
  463. // Get the handle to the network interface at the specified index
  464. STDMETHOD_( HNETINTERFACE, GetNetInterfaceHandle )(
  465. IN LONG nObjIndex
  466. )
  467. {
  468. ATLASSERT( Pco() != NULL );
  469. // Validate parameters.
  470. // We only support one selected object at a time for now.
  471. if ( (nObjIndex == 1)
  472. || (Pco()->Cot() != CLUADMEX_OT_NETINTERFACE) )
  473. {
  474. SetLastError( (DWORD) E_INVALIDARG );
  475. return NULL;
  476. } // if: invalid argument
  477. CClusNetIFInfo * pnii = reinterpret_cast< CClusNetIFInfo * >( Pco() );
  478. return pnii->Hnetinterface();
  479. } //*** GetNetInterfaceHandle()
  480. // Implementation
  481. protected:
  482. // AFX_MODULE_STATE * m_pModuleState; // Required for resetting our state during callbacks.
  483. // Get a string property
  484. STDMETHOD( GetStringProperty )(
  485. IN const CString & rstrNameSource,
  486. OUT BSTR lpszName,
  487. IN OUT LONG * pcchName
  488. )
  489. {
  490. ATLASSERT( pcchName != NULL );
  491. LONG cchName = 0;
  492. HRESULT hr = S_OK;
  493. //
  494. // Save the length to copy.
  495. //
  496. try
  497. {
  498. cchName = *pcchName;
  499. *pcchName = rstrNameSource.GetLength() + 1;
  500. } // try
  501. catch (...)
  502. {
  503. hr = E_INVALIDARG;
  504. goto Cleanup;
  505. } // catch: anything
  506. //
  507. // If only the length is being requested, return it now.
  508. //
  509. if ( lpszName == NULL )
  510. {
  511. hr = S_OK;
  512. goto Cleanup;
  513. } // if: no name buffer specified
  514. //
  515. // If a buffer is specified and it is too small, return an error.
  516. //
  517. if ( cchName < *pcchName )
  518. {
  519. hr = ERROR_MORE_DATA;
  520. goto Cleanup;
  521. } // if: buffer too small
  522. //
  523. // Copy the data.
  524. //
  525. hr = StringCchCopyNW( lpszName, cchName, rstrNameSource, rstrNameSource.GetLength() );
  526. if ( FAILED( hr ) )
  527. {
  528. goto Cleanup;
  529. } // if: error copying data
  530. Cleanup:
  531. return hr;
  532. } //*** GetStringProperty()
  533. }; //*** class CCluAdmExDataObject
  534. /////////////////////////////////////////////////////////////////////////////
  535. // Class Data
  536. /////////////////////////////////////////////////////////////////////////////
  537. _declspec( selectany ) const IID * CCluAdmExDataObject::s_rgiid[] =
  538. {
  539. &IID_IGetClusterDataInfo,
  540. &IID_IGetClusterObjectInfo,
  541. &IID_IGetClusterNodeInfo,
  542. &IID_IGetClusterGroupInfo,
  543. &IID_IGetClusterResourceInfo,
  544. &IID_IGetClusterNetworkInfo,
  545. &IID_IGetClusterNetInterfaceInfo,
  546. NULL
  547. };
  548. /////////////////////////////////////////////////////////////////////////////
  549. #endif // __CLUADMEXDATAOBJ_H_