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.

501 lines
13 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. MeSe.cpp
  5. Abstract:
  6. Node representing our Media Set (Media Pool) within NTMS.
  7. Author:
  8. Rohde Wakefield [rohde] 04-Aug-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. #include "MeSe.h"
  13. #include "WzMedSet.h"
  14. #include "ca.h"
  15. int CUiMedSet::m_nScopeCloseIcon = AddScopeImage( IDI_NODELIB );
  16. int CUiMedSet::m_nScopeCloseIconX = AddScopeImage( IDI_NODELIBX );
  17. int CUiMedSet::m_nScopeOpenIcon = AddScopeImage( IDI_NODEOPENFOLDER );
  18. int CUiMedSet::m_nScopeOpenIconX = CUiMedSet::m_nScopeCloseIconX;
  19. int CUiMedSet::m_nResultIcon = AddResultImage( IDI_NODELIB );
  20. int CUiMedSet::m_nResultIconX = AddResultImage( IDI_NODELIBX );
  21. /////////////////////////////////////////////////////////////////////////////
  22. //
  23. // CoComObjectRoot
  24. //
  25. /////////////////////////////////////////////////////////////////////////////
  26. //---------------------------------------------------------------------------
  27. //
  28. // FinalConstruct
  29. //
  30. // Initialize this level of the object hierarchy
  31. //
  32. HRESULT CUiMedSet::FinalConstruct( )
  33. {
  34. WsbTraceIn( L"CUiMedSet::FinalConstruct", L"" );
  35. m_rTypeGuid = &cGuidMedSet;
  36. m_NumCopySets = 0;
  37. HRESULT hr = CSakNode::FinalConstruct( );
  38. m_bSupportsPropertiesSingle = FALSE;
  39. m_bSupportsPropertiesMulti = FALSE;
  40. m_bSupportsDeleteSingle = FALSE;
  41. m_bSupportsDeleteMulti = FALSE;
  42. m_bSupportsRefreshSingle = TRUE;
  43. m_bSupportsRefreshMulti = FALSE;
  44. m_bIsContainer = TRUE;
  45. m_bHasDynamicChildren = TRUE;
  46. // Toolbar values
  47. INT i = 0;
  48. m_ToolbarButtons[i].nBitmap = 0;
  49. m_ToolbarButtons[i].idCommand = TB_CMD_MESE_COPY;
  50. m_ToolbarButtons[i].idButtonText = IDS_TB_TEXT_MESE_COPY;
  51. m_ToolbarButtons[i].idTooltipText = IDS_TB_TIP_MESE_COPY;
  52. i++;
  53. m_ToolbarBitmap = IDB_TOOLBAR_MESE;
  54. m_cToolbarButtons = i;
  55. WsbTraceOut( L"CUiMedSet::FinalConstruct", L"hr = <%ls>", WsbHrAsString( hr ) );
  56. return( hr );
  57. }
  58. //---------------------------------------------------------------------------
  59. //
  60. // FinalRelease
  61. //
  62. // Clean up this level of the object hierarchy
  63. //
  64. void CUiMedSet::FinalRelease( )
  65. {
  66. WsbTraceIn( L"CUiMedSet::FinalRelease", L"" );
  67. // if( m_pDbSession ) {
  68. //
  69. // m_pDb->Close( m_pDbSession );
  70. //
  71. // }
  72. CSakNode::FinalRelease( );
  73. WsbTraceOut( L"CUiMedSet::FinalRelease", L"" );
  74. }
  75. /////////////////////////////////////////////////////////////////////////////
  76. //
  77. // ISakNode
  78. //
  79. /////////////////////////////////////////////////////////////////////////////
  80. //---------------------------------------------------------------------------
  81. //
  82. // GetContextMenu
  83. //
  84. // Return an HMENU to be used for context menus on this node.
  85. //
  86. STDMETHODIMP
  87. CUiMedSet::GetContextMenu( BOOL bMultiSelect, HMENU* phMenu )
  88. {
  89. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  90. HRESULT hr = S_OK;
  91. try {
  92. CMenu* pRootMenu;
  93. LoadContextMenu( IDR_MEDSET, phMenu );
  94. CMenu menu;
  95. menu.Attach( *phMenu );
  96. pRootMenu = menu.GetSubMenu( MENU_INDEX_ROOT );
  97. pRootMenu->EnableMenuItem( ID_MEDSET_ROOT_COPY, MF_GRAYED | MF_BYCOMMAND );
  98. //
  99. // If not multi-select, and media copies are supported,
  100. // and If engine up, enable copy
  101. //
  102. if( !bMultiSelect && ( m_pSakSnapAsk->GetState() == S_OK ) ) {
  103. if( m_MediaCopiesEnabled ) {
  104. pRootMenu->EnableMenuItem( ID_MEDSET_ROOT_COPY, MF_BYCOMMAND );
  105. }
  106. }
  107. menu.Detach();
  108. } WsbCatch( hr );
  109. return( hr );
  110. }
  111. //---------------------------------------------------------------------------
  112. //
  113. // InvokeCommand
  114. //
  115. // User has selected a command from the menu. Process it here.
  116. //
  117. STDMETHODIMP
  118. CUiMedSet::InvokeCommand( SHORT sCmd, IDataObject* /*pDataObject*/ )
  119. {
  120. WsbTraceIn( L"CUiMedSet::InvokeCommand", L"sCmd = <%d>", sCmd );
  121. HRESULT hr = S_OK;
  122. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  123. CComPtr<IHsmServer> pHsm;
  124. try {
  125. switch (sCmd) {
  126. case ID_MEDSET_ROOT_COPY:
  127. {
  128. //
  129. // use wizard to sync media copies
  130. //
  131. CComObject<CMediaCopyWizard>* pWizard = new CComObject<CMediaCopyWizard>;
  132. WsbAffirmAlloc( pWizard );
  133. CComPtr<ISakWizard> pSakWizard = (ISakWizard*)pWizard;
  134. WsbAffirmHr( m_pSakSnapAsk->CreateWizard( pSakWizard ) );
  135. }
  136. break;
  137. }
  138. } WsbCatch( hr );
  139. WsbTraceOut( L"CUiMedSet::InvokeCommand", L"hr = <%ls>", WsbHrAsString( hr ) );
  140. return hr;
  141. }
  142. HRESULT CUiMedSet::SetupToolbar( IToolbar *pToolbar )
  143. {
  144. WsbTraceIn( L"CUiMedSet::SetupToolbar", L"pToolbar = <0x%p>", pToolbar );
  145. HRESULT hr = S_OK;
  146. try {
  147. BOOL state = ( S_OK == m_pSakSnapAsk->GetState( ) ) ? TRUE : FALSE;
  148. for( INT i = 0; i < m_cToolbarButtons; i++ ) {
  149. m_ToolbarButtons[i].fsState = (UCHAR)( state ? TBSTATE_ENABLED : 0 );
  150. //
  151. // If media copy button, need to check if should be enabled
  152. //
  153. if( state && ( TB_CMD_MESE_COPY == m_ToolbarButtons[i].idCommand ) ) {
  154. if( m_MediaCopiesEnabled ) {
  155. m_ToolbarButtons[i].fsState = TBSTATE_ENABLED;
  156. } else {
  157. m_ToolbarButtons[i].fsState = 0;
  158. }
  159. }
  160. }
  161. WsbAffirmHr( CSakNode::SetupToolbar( pToolbar ) );
  162. } WsbCatch( hr );
  163. WsbTraceOut( L"CUiMedSet::SetupToolbar", L"hr = <%ls>", WsbHrAsString( hr ) );
  164. return hr;
  165. }
  166. HRESULT CUiMedSet::OnToolbarButtonClick( IDataObject * /* pDataObject */, long cmdId )
  167. {
  168. WsbTraceIn( L"CUiMedSet::OnToolbarButtonClick", L"cmdId = <%d>", cmdId );
  169. HRESULT hr = S_OK;
  170. try {
  171. switch ( cmdId ) {
  172. case TB_CMD_MESE_COPY:
  173. {
  174. //
  175. // use wizard to sync media copies
  176. //
  177. CComObject<CMediaCopyWizard>* pWizard = new CComObject<CMediaCopyWizard>;
  178. WsbAffirmAlloc( pWizard );
  179. CComPtr<ISakWizard> pSakWizard = (ISakWizard*)pWizard;
  180. WsbAffirmHr( m_pSakSnapAsk->CreateWizard( pSakWizard ) );
  181. }
  182. break;
  183. }
  184. } WsbCatch( hr );
  185. WsbTraceOut( L"CUiMedSet::OnToolbarButtonClick", L"hr = <%ls>", WsbHrAsString( hr ) );
  186. return( hr );
  187. }
  188. //---------------------------------------------------------------------------
  189. //
  190. // CreateChildren
  191. //
  192. // Create and initialize all the children of the media node.
  193. //
  194. STDMETHODIMP CUiMedSet::CreateChildren( )
  195. {
  196. CMediaInfoObject mio;
  197. WsbTraceIn( L"CUiMedSet::CreateChildren", L"" );
  198. HRESULT hr = S_OK;
  199. try {
  200. WsbAffirmPointer( m_pHsmServer );
  201. WsbAffirmPointer( m_pRmsServer );
  202. HRESULT hrEnum;
  203. // Get media info
  204. WsbAffirmHr( mio.Initialize( GUID_NULL, m_pHsmServer, m_pRmsServer ) );
  205. // Did we get a node?
  206. if( mio.m_MediaId != GUID_NULL ) {
  207. hrEnum = S_OK;
  208. while( SUCCEEDED( hrEnum ) ) {
  209. if( S_OK == mio.IsViewable( FALSE ) ) {
  210. //
  211. // Create the coresponding node
  212. //
  213. CComPtr<IUnknown> pUnkChild;
  214. CComPtr<ISakNode> pNode;
  215. WsbAffirmHr( NewChild( cGuidCar, &pUnkChild ) );
  216. WsbAffirmHr( RsQueryInterface( pUnkChild, ISakNode, pNode ) );
  217. //
  218. // And initialize
  219. //
  220. // The media node now initializes based on the media id. Assign it in
  221. // the base class.
  222. pNode->SetObjectId( mio.m_MediaId );
  223. WsbAffirmHr( pNode->InitNode( m_pSakSnapAsk, 0, this ) );
  224. //
  225. // Add the child COM object to the parent's list of children.
  226. //
  227. WsbAffirmHr( AddChild( pNode ) );
  228. }
  229. hrEnum = mio.Next();
  230. }
  231. WsbAffirm( SUCCEEDED( hrEnum ) || ( WSB_E_NOTFOUND == hrEnum ), hrEnum );
  232. }
  233. } WsbCatch( hr );
  234. //
  235. // Indicate that this node's children are valid and up-to-date (even if there ARE
  236. // no children - at least now we know it).
  237. //
  238. m_bChildrenAreValid = TRUE;
  239. //
  240. // indicate that this parent node needs to be re-enumerated
  241. //
  242. m_bEnumState = FALSE;
  243. WsbTraceOut( L"CUiMedSet::CreateChildren", L"hr = <%ls>", WsbHrAsString( hr ) );
  244. return( hr );
  245. }
  246. //
  247. // InitNode
  248. //
  249. // Initialize single COM object. Derived objects frequently augment this method
  250. // by implementing it themselves.
  251. //
  252. STDMETHODIMP
  253. CUiMedSet::InitNode(
  254. ISakSnapAsk* pSakSnapAsk,
  255. IUnknown* pHsmObj,
  256. ISakNode* pParent
  257. )
  258. {
  259. WsbTraceIn( L"CUiMedSet::InitNode", L"pSakSnapAsk = <0x%p>, pHsmObj = <0x%p>, pParent = <0x%p>", pSakSnapAsk, pHsmObj, pParent );
  260. HRESULT hr = S_OK;
  261. try {
  262. WsbAffirmHr( CSakNode::InitNode( pSakSnapAsk, pHsmObj, pParent ) );
  263. //
  264. // Set Display Type and Description
  265. //
  266. CString tempString;
  267. tempString.LoadString( IDS_MEDSET_DISPLAYNAME );
  268. WsbAffirmHr( put_DisplayName( (OLECHAR *)(LPCWSTR)tempString ) );
  269. tempString.LoadString( IDS_MEDSET_TYPE );
  270. WsbAffirmHr( put_Type( (OLECHAR *)(LPCWSTR)tempString ) );
  271. tempString.LoadString( IDS_MEDSET_DESCRIPTION );
  272. WsbAffirmHr( put_Description( (OLECHAR *)(LPCWSTR)tempString ) );
  273. WsbAffirmHr( RefreshObject() );
  274. } WsbCatch( hr );
  275. WsbTraceOut( L"CUiMedSet::InitNode", L"hr = <%ls>", WsbHrAsString( hr ) );
  276. return( hr );
  277. }
  278. STDMETHODIMP
  279. CUiMedSet::TerminateNode(
  280. )
  281. /*++
  282. Routine Description:
  283. Free any interface connections or other resources
  284. that would prevent correct shutdown of node (would
  285. keep ref count from going to 0).
  286. Arguments:
  287. CopySet - copy set of interest.
  288. pszValue - return string representing the state.
  289. Return Value:
  290. S_OK - Handled.
  291. E_* - Some error occurred.
  292. --*/
  293. {
  294. WsbTraceIn( L"CUiMedSet::TerminateNode", L"" );
  295. HRESULT hr = S_OK;
  296. try {
  297. //
  298. // Release any interface pointers kept so that circular references
  299. // are broken
  300. //
  301. m_pStoragePool.Release( );
  302. m_pHsmServer.Release( );
  303. m_pRmsServer.Release( );
  304. //
  305. // And call the base class for it's pieces
  306. //
  307. WsbAffirmHr( CSakNode::TerminateNode( ) );
  308. } WsbCatch( hr );
  309. WsbTraceOut( L"CUiMedSet::TerminateNode", L"hr = <%ls>", WsbHrAsString( hr ) );
  310. return( hr );
  311. }
  312. HRESULT CUiMedSet::RefreshObject()
  313. {
  314. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  315. HRESULT hr = S_OK;
  316. try {
  317. m_NumCopySets = 0;
  318. m_MediaCopiesEnabled = FALSE;
  319. WsbAssertPointer( m_pSakSnapAsk );
  320. //
  321. // If the engine is down, we want to create the node anyway
  322. // Need to release smart pointers so that interfaces are
  323. // correctly reference counted. IOW, if they already have
  324. // an interface pointer stored, it will not get released
  325. // before being clobbered here in the Get functions.
  326. //
  327. m_pHsmServer.Release( );
  328. m_pRmsServer.Release( );
  329. m_pStoragePool.Release( );
  330. if( m_pSakSnapAsk->GetHsmServer( &m_pHsmServer ) == S_OK ) {
  331. if( m_pSakSnapAsk->GetRmsServer( &m_pRmsServer ) == S_OK ) {
  332. //
  333. // Get the storage pool of interest
  334. //
  335. if( RsGetStoragePool( m_pHsmServer, &m_pStoragePool ) == S_OK ) {
  336. //
  337. // Contact data base and store necessary info
  338. //
  339. CMediaInfoObject mio;
  340. mio.Initialize( GUID_NULL, m_pHsmServer, m_pRmsServer );
  341. m_NumCopySets = mio.m_NumMediaCopies;
  342. //
  343. // Find out if media copies are supported
  344. //
  345. GUID mediaSetId;
  346. CWsbBstrPtr mediaName;
  347. WsbAffirmHr( m_pStoragePool->GetMediaSet( &mediaSetId, &mediaName ) );
  348. CComPtr<IRmsMediaSet> pMediaSet;
  349. WsbAffirmHr( m_pRmsServer->CreateObject( mediaSetId, CLSID_CRmsMediaSet, IID_IRmsMediaSet, RmsOpenExisting, (void**)&pMediaSet ) );
  350. m_MediaCopiesEnabled = ( pMediaSet->IsMediaCopySupported( ) == S_OK );
  351. }
  352. }
  353. }
  354. //
  355. // Set up the result view columns
  356. // This changes with the number of media copies, so can't
  357. // do once in Init()
  358. //
  359. WsbAffirmHr( SetChildProps( RS_STR_RESULT_PROPS_MEDSET_IDS,
  360. IDS_RESULT_PROPS_MEDSET_TITLES, IDS_RESULT_PROPS_MEDSET_WIDTHS ) );
  361. m_cChildPropsShow = m_cChildProps - HSMADMIN_MAX_COPY_SETS + m_NumCopySets;
  362. } WsbCatch( hr );
  363. return( hr );
  364. }