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.

662 lines
14 KiB

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