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.

500 lines
14 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. HsmCom.cpp
  5. Abstract:
  6. Root node of snapin - represents the Computer.
  7. Author:
  8. Rohde Wakefield [rohde] 08-Aug-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "HsmCom.h"
  13. #include "WzQstart.h"
  14. #include "PrMrLsRc.h"
  15. #include "PrMedSet.h"
  16. #include "PrSched.h"
  17. int CUiHsmCom::m_nScopeCloseIcon = AddScopeImage( IDI_BLUESAKKARA );
  18. int CUiHsmCom::m_nScopeCloseIconX = CUiHsmCom::m_nScopeCloseIcon;
  19. int CUiHsmCom::m_nScopeOpenIcon = CUiHsmCom::m_nScopeCloseIcon;
  20. int CUiHsmCom::m_nScopeOpenIconX = CUiHsmCom::m_nScopeCloseIconX;
  21. int CUiHsmCom::m_nResultIcon = AddResultImage( IDI_BLUESAKKARA );
  22. int CUiHsmCom::m_nResultIconX = CUiHsmCom::m_nResultIcon;
  23. /////////////////////////////////////////////////////////////////////////////
  24. //
  25. // CoComObjectRoot
  26. //
  27. /////////////////////////////////////////////////////////////////////////////
  28. //---------------------------------------------------------------------------
  29. //
  30. // FinalConstruct
  31. //
  32. // Initialize this level of the object hierarchy
  33. //
  34. HRESULT CUiHsmCom::FinalConstruct( )
  35. {
  36. WsbTraceIn( L"CUiHsmCom::FinalConstruct", L"" );
  37. m_rTypeGuid = &cGuidHsmCom;
  38. HRESULT hr = CSakNode::FinalConstruct( );
  39. m_bSupportsPropertiesSingle = TRUE;
  40. m_bSupportsPropertiesMulti = FALSE;
  41. m_bSupportsPropertiesNoEngine = TRUE;
  42. m_bSupportsDeleteSingle = FALSE;
  43. m_bSupportsDeleteMulti = FALSE;
  44. m_bSupportsRefreshSingle = TRUE;
  45. m_bSupportsRefreshMulti = FALSE;
  46. m_bSupportsRefreshNoEngine = TRUE;
  47. m_bIsContainer = TRUE;
  48. m_pPageStat = NULL;
  49. m_pPageServices = NULL;
  50. WsbTraceOut( L"CUiHsmCom::FinalConstruct", L"hr = <%ls>", WsbHrAsString( hr ) );
  51. return( hr );
  52. }
  53. //---------------------------------------------------------------------------
  54. //
  55. // FinalRelease
  56. //
  57. // Clean up this level of the object hierarchy
  58. //
  59. void CUiHsmCom::FinalRelease( )
  60. {
  61. WsbTraceIn( L"CUiHsmCom::FinalRelease", L"" );
  62. CSakNode::FinalRelease( );
  63. WsbTraceOut( L"CUiHsmCom::FinalRelease", L"" );
  64. }
  65. /////////////////////////////////////////////////////////////////////////////
  66. //
  67. // ISakNode
  68. //
  69. /////////////////////////////////////////////////////////////////////////////
  70. //---------------------------------------------------------------------------
  71. //
  72. // GetContextMenu
  73. //
  74. // Return an HMENU to be used for context menus on this node.
  75. //
  76. STDMETHODIMP
  77. CUiHsmCom::GetContextMenu( BOOL /*bMultiSelect*/, HMENU* phMenu )
  78. {
  79. WsbTraceIn( L"CUiHsmCom::GetContextMenu", L"" );
  80. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  81. HRESULT hr = S_OK;
  82. CMenu* pRootMenu, *pNewMenu, *pTaskMenu;
  83. try {
  84. //
  85. // Get the context menu from the resource
  86. //
  87. WsbAffirmHr( LoadContextMenu( IDR_HSMCOM, phMenu ) );
  88. CMenu menu;
  89. menu.Attach( *phMenu );
  90. pRootMenu = menu.GetSubMenu( MENU_INDEX_ROOT );
  91. pNewMenu = menu.GetSubMenu( MENU_INDEX_NEW );
  92. pTaskMenu = menu.GetSubMenu( MENU_INDEX_TASK );
  93. //
  94. // If we are not configured locally, allow the option to setup
  95. // Remote Storage Server. If we are setup, allow them to reconnect
  96. // if not connected.
  97. //
  98. BOOL deleteMenu = TRUE;
  99. if( S_FALSE == m_pSakSnapAsk->GetHsmName( 0 ) ) {
  100. CComPtr<IHsmServer> pServer;
  101. HRESULT hrConn = m_pSakSnapAsk->GetHsmServer( &pServer );
  102. if( RS_E_NOT_CONFIGURED == hrConn ) {
  103. deleteMenu = FALSE;
  104. }
  105. }
  106. if( deleteMenu ) {
  107. pRootMenu->DeleteMenu( ID_HSMCOM_ROOT_SETUPWIZARD, MF_BYCOMMAND );
  108. }
  109. if( !deleteMenu || ( S_OK != m_pSakSnapAsk->GetState( ) ) ) {
  110. pRootMenu->EnableMenuItem( ID_HSMCOM_ROOT_SCHEDULE, MF_GRAYED | MF_BYCOMMAND );
  111. }
  112. menu.Detach( );
  113. } WsbCatch( hr );
  114. WsbTraceOut( L"CUiHsmCom::GetContextMenu", L"hr = <%ls>", WsbHrAsString( hr ) );
  115. return( hr );
  116. }
  117. //---------------------------------------------------------------------------
  118. //
  119. // InvokeCommand
  120. //
  121. // User has selected a command from the menu. Process it here.
  122. //
  123. STDMETHODIMP
  124. CUiHsmCom::InvokeCommand( SHORT sCmd, IDataObject* pDataObject )
  125. {
  126. WsbTraceIn( L"CUiHsmCom::InvokeCommand", L"sCmd = <%d>", sCmd );
  127. CString theString;
  128. HRESULT hr = S_OK;
  129. AFX_MANAGE_STATE( AfxGetStaticModuleState( ) );
  130. try {
  131. switch( sCmd ) {
  132. case ID_HSMCOM_ROOT_SETUPWIZARD:
  133. {
  134. //
  135. // use wizard to create manage volume
  136. //
  137. CComObject<CQuickStartWizard>* pWizard = new CComObject<CQuickStartWizard>;
  138. WsbAffirmAlloc( pWizard );
  139. CComPtr<ISakWizard> pSakWizard = (ISakWizard*)pWizard;
  140. WsbAffirmHr( m_pSakSnapAsk->CreateWizard( pSakWizard ) );
  141. //
  142. // RS_E_CANCELED indicates canceled, and FAILEd indicates error.
  143. // If so, then throw "Not set up"
  144. //
  145. if( S_OK == pWizard->m_HrFinish ) {
  146. WsbAffirmHr( RefreshScopePane( ) );
  147. }
  148. }
  149. break;
  150. case ID_HSMCOM_ROOT_SCHEDULE:
  151. WsbAffirmHr( m_pSakSnapAsk->ShowPropertySheet( this, pDataObject, 1 ) );
  152. break;
  153. case MMC_VERB_REFRESH:
  154. WsbAffirmHr( RefreshScopePane( ) );
  155. break;
  156. default:
  157. break;
  158. }
  159. } WsbCatch( hr );
  160. WsbTraceOut( L"CUiHsmCom::InvokeCommand", L"hr = <%ls>", WsbHrAsString( hr ) );
  161. return( hr );
  162. }
  163. //---------------------------------------------------------------------------
  164. //
  165. // CreateChildren
  166. //
  167. // Create and initialize all the children of the Hsm Computer node.
  168. //
  169. STDMETHODIMP CUiHsmCom::CreateChildren( )
  170. {
  171. WsbTraceIn( L"CUiHsmCom::CreateChildren", L"" );
  172. //
  173. // Initialize the children of this node (no recursion. Decendents of children
  174. // are NOT created here)
  175. //
  176. HRESULT hr = S_OK;
  177. try {
  178. CComPtr<IUnknown> pUnkChild; // IUnknown pointer to new child.
  179. CComPtr<ISakNode> pSakNode; // creation interface for new child node.
  180. //
  181. // Create a Managed Resource list UI node to be the parent of all managed volumes.
  182. //
  183. WsbAffirmHr( NewChild( cGuidManVolLst, &pUnkChild ) );
  184. //
  185. // Initialize the child UI COM object, putting the Hsm Managed Resource collection object inside the UI object.
  186. //
  187. WsbAffirmHr( RsQueryInterface( pUnkChild, ISakNode, pSakNode ) );
  188. WsbAffirmHr( pSakNode->InitNode( m_pSakSnapAsk, NULL, this ) );
  189. //
  190. // Add the child COM object to the parent's list of children.
  191. //
  192. WsbAffirmHr( AddChild( pSakNode ) );
  193. // Free up resources
  194. pUnkChild.Release( );
  195. pSakNode.Release( );
  196. ///////////////////////////////
  197. // CREATE MEDIA SET NODE
  198. //
  199. // Create a Remote Storage UI node to be the parent of all remote storage sub-nodes.
  200. //
  201. WsbAffirmHr( NewChild( cGuidMedSet, &pUnkChild ) );
  202. //
  203. // Initialize the child UI COM object, putting the Rms Server object inside the UI object.
  204. //
  205. WsbAffirmHr( RsQueryInterface( pUnkChild, ISakNode, pSakNode ) );
  206. WsbAffirmHr( pSakNode->InitNode( m_pSakSnapAsk, NULL, this ) );
  207. //
  208. // Add the child COM object to the parent's list of children.
  209. //
  210. WsbAffirmHr( AddChild( pSakNode ) );
  211. } WsbCatch( hr );
  212. //
  213. // Indicate that this node's children are valid and up-to-date (even if there ARE
  214. // no children - at least now we know it).
  215. //
  216. m_bChildrenAreValid = TRUE;
  217. //
  218. // indicate that this parent node needs to be re-enumerated
  219. //
  220. m_bEnumState = FALSE;
  221. WsbTraceOut( L"CUiHsmCom::CreateChildren", L"hr = <%ls>", WsbHrAsString( hr ) );
  222. return( hr );
  223. }
  224. //---------------------------------------------------------------------------
  225. //
  226. // InitNode
  227. //
  228. // Initialize single COM object without using the registry. Derived
  229. // objects frequently augment this method by implementing it themselves.
  230. //
  231. STDMETHODIMP
  232. CUiHsmCom::InitNode(
  233. ISakSnapAsk* pSakSnapAsk,
  234. IUnknown* pHsmObj,
  235. ISakNode* pParent
  236. )
  237. {
  238. WsbTraceIn( L"CUiHsmCom::InitNode", L"pSakSnapAsk = <0x%p>, pHsmObj = <0x%p>, pParent = <0x%p>", pSakSnapAsk, pHsmObj, pParent );
  239. HRESULT hr = S_OK;
  240. try {
  241. //
  242. // Note: The Hsm computer node no longer owns a server pointer
  243. //
  244. WsbAffirmHr( CSakNode::InitNode( pSakSnapAsk, NULL, pParent ));
  245. //
  246. // Set Display Type and Description.
  247. //
  248. CString tempString;
  249. tempString.LoadString( IDS_HSMCOM_TYPE );
  250. WsbAffirmHr( put_Type( (OLECHAR *)(LPCWSTR)tempString ) );
  251. tempString.LoadString( IDS_HSMCOM_DESCRIPTION );
  252. WsbAffirmHr( put_Description( (OLECHAR *)(LPCWSTR)tempString ) );
  253. //
  254. // Set up the result view columns
  255. //
  256. WsbAffirmHr( SetChildProps( RS_STR_RESULT_PROPS_COM_IDS, IDS_RESULT_PROPS_COM_TITLES, IDS_RESULT_PROPS_COM_WIDTHS ) );
  257. RefreshObject();
  258. } WsbCatch( hr );
  259. WsbTraceOut( L"CUiHsmCom::InitNode", L"hr = <%ls>", WsbHrAsString( hr ) );
  260. return( hr );
  261. }
  262. STDMETHODIMP
  263. CUiHsmCom::AddPropertyPages( RS_NOTIFY_HANDLE handle, IUnknown* pUnkPropSheetCallback, IEnumGUID *pEnumObjectId, IEnumUnknown *pEnumUnkNode)
  264. {
  265. WsbTraceIn( L"CUiHsmCom::AddPropertyPages", L"" );
  266. HRESULT hr = S_OK;
  267. try {
  268. //
  269. // Create an object to hold the pages
  270. //
  271. CUiHsmComSheet *pHsmComPropertySheet = new CUiHsmComSheet;
  272. WsbAffirmAlloc( pHsmComPropertySheet );
  273. WsbAffirmHr( pHsmComPropertySheet->InitSheet(
  274. handle,
  275. pUnkPropSheetCallback,
  276. this,
  277. m_pSakSnapAsk,
  278. pEnumObjectId,
  279. pEnumUnkNode
  280. ) );
  281. //
  282. // Tell the object to add it's pages
  283. //
  284. WsbAffirmHr( pHsmComPropertySheet->AddPropertyPages( ) );
  285. } WsbCatch ( hr );
  286. WsbTraceOut( L"CUiHsmCom::AddPropertyPages", L"hr = <%ls>", WsbHrAsString( hr ) );
  287. return ( hr );
  288. }
  289. /////////////////////////////////////////////////////////////////////////////////////////
  290. //
  291. // class CUiManVolSheet
  292. //
  293. HRESULT
  294. CUiHsmComSheet::InitSheet(
  295. RS_NOTIFY_HANDLE handle,
  296. IUnknown* pUnkPropSheetCallback,
  297. CSakNode* pSakNode,
  298. ISakSnapAsk* pSakSnapAsk,
  299. IEnumGUID* pEnumObjectId,
  300. IEnumUnknown* pEnumUnkNode
  301. )
  302. {
  303. WsbTraceIn( L"CUiHsmComSheet::InitSheet", L"handle = <%ld>, pUnkPropSheetCallback = <0x%p>, pSakNode = <0x%p>, pSakSnapAsk = <0x%p>, pEnumObjectId = <0x%p>, ",
  304. handle, pUnkPropSheetCallback, pSakNode, pSakSnapAsk, pEnumObjectId );
  305. HRESULT hr = S_OK;
  306. try {
  307. WsbAffirmHr( CSakPropertySheet::InitSheet( handle, pUnkPropSheetCallback, pSakNode,
  308. pSakSnapAsk, pEnumObjectId, pEnumUnkNode ) );
  309. CWsbBstrPtr nodeName;
  310. WsbAffirmHr( pSakNode->get_DisplayName( &nodeName ) );
  311. m_NodeTitle = nodeName;
  312. } WsbCatch( hr );
  313. WsbTraceOut( L"CUiHsmComSheet::InitSheet", L"hr = <%ls>", WsbHrAsString( hr ) );
  314. return( hr );
  315. }
  316. HRESULT CUiHsmComSheet::AddPropertyPages ( )
  317. {
  318. WsbTraceIn( L"CUiHsmComSheet::AddPropertyPages", L"" );
  319. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  320. HRESULT hr = S_OK;
  321. try {
  322. HPROPSHEETPAGE hPage = NULL; // Windows property page handle
  323. // --------------------- Statistics Page ----------------------------------
  324. // Create the Hsm Statistics property page.
  325. CPropHsmComStat* pPageStats = new CPropHsmComStat();
  326. WsbAffirmAlloc( pPageStats );
  327. pPageStats->m_NodeTitle = m_NodeTitle;
  328. AddPage( pPageStats );
  329. //
  330. // Add the Schedule, Recall, and Media Copies pages
  331. // if setup has happened and the Remote Storage Service
  332. // is running.
  333. //
  334. if( S_OK == m_pSakNode->m_pSakSnapAsk->GetState() ) {
  335. //--------------------- Schedule Page --------------------------------------
  336. CPrSchedule* pPageSched = new CPrSchedule();
  337. WsbAffirmAlloc( pPageSched );
  338. AddPage( pPageSched );
  339. //--------------------- Recall Limit Page --------------------------------------
  340. // Create the Hsm Recall property page.
  341. CPrMrLsRec* pPageRecall = new CPrMrLsRec();
  342. WsbAffirmAlloc( pPageRecall );
  343. AddPage( pPageRecall );
  344. // --------------------- Media Copies Page ----------------------------------
  345. CPrMedSet *pPageMediaCopies = new CPrMedSet();
  346. WsbAffirmAlloc( pPageMediaCopies )
  347. AddPage( pPageMediaCopies );
  348. // Add more pages here.
  349. // ....
  350. }
  351. } WsbCatch( hr );
  352. WsbTraceOut( L"CUiHsmComSheet::AddPropertyPages", L"hr = <%ls>", WsbHrAsString( hr ) );
  353. return( hr );
  354. }