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.

310 lines
8.0 KiB

  1. /*++
  2. 1998 Seagate Software, Inc. All rights reserved.
  3. Module Name:
  4. HsmCreate.cpp
  5. Abstract:
  6. Implementation of ISakNode interfaces init and creation.
  7. Author:
  8. Rohde Wakefield [rohde] 08-Aug-1997
  9. Revision History:
  10. --*/
  11. #include "stdafx.h"
  12. /////////////////////////////////////////////////////////////////////////////
  13. //
  14. // ISakNode
  15. //
  16. /////////////////////////////////////////////////////////////////////////////
  17. //---------------------------------------------------------------------------
  18. //
  19. // InitNode
  20. //
  21. // Initialize single COM object without using the registry. Derived
  22. // objects frequently augment this method by implementing it themselves.
  23. //
  24. STDMETHODIMP
  25. CSakNode::InitNode(
  26. ISakSnapAsk* pSakSnapAsk,
  27. IUnknown* pHsmObj,
  28. ISakNode* pParent
  29. )
  30. {
  31. WsbTraceIn( L"CSakNode::InitNode", L"pSakSnapAsk = <0x%p>, pHsmObj = <0x%p>, pParent = <0x%p>", pSakSnapAsk, pHsmObj, pParent );
  32. HRESULT hr = S_OK;
  33. try {
  34. CWsbStringPtr sz;
  35. // Grab Display Name, Displayed Type, Description
  36. WsbAffirmHr( put_DisplayName( L"Error Node Name" ) );
  37. WsbAffirmHr( put_Type( L"Error Node Type" ) );
  38. WsbAffirmHr( put_Description( L"Error Node Description" ) );
  39. // save a pointer to the ask interface in the main snapin.
  40. m_pSakSnapAsk = pSakSnapAsk;
  41. // Save the pointer to the COM object
  42. m_pHsmObj = pHsmObj;
  43. // save the cookie of the parent node.
  44. m_pParent = pParent;
  45. // Set result pane columns to the defaults
  46. WsbAffirmHr( SetChildProps(
  47. RS_STR_RESULT_PROPS_DEFAULT_IDS,
  48. IDS_RESULT_PROPS_DEFAULT_TITLES,
  49. IDS_RESULT_PROPS_DEFAULT_WIDTHS ) );
  50. } WsbCatch( hr );
  51. WsbTraceOut( L"CSakNode::InitNode", L"hr = <%ls>", WsbHrAsString( hr ) );
  52. return( S_OK );
  53. }
  54. STDMETHODIMP
  55. CSakNode::TerminateNode(
  56. )
  57. {
  58. WsbTraceIn( L"CSakNode::TerminateNode", L"" );
  59. HRESULT hr = S_OK;
  60. try {
  61. //
  62. // Remove any info in console
  63. //
  64. m_pSakSnapAsk->DetachFromNode( this );
  65. //
  66. // Release the connection point, if it was established
  67. //
  68. if( m_Advise && m_pUnkConnection ) {
  69. AtlUnadvise( m_pUnkConnection, IID_IHsmEvent, m_Advise );
  70. }
  71. //
  72. // And cleanup internal interface pointers
  73. //
  74. m_pUnkConnection.Release( );
  75. m_pSakSnapAsk.Release( );
  76. m_pHsmObj.Release( );
  77. m_pParent.Release( );
  78. } WsbCatch( hr );
  79. WsbTraceOut( L"CSakNode::TerminateNode", L"hr = <%ls>", WsbHrAsString( hr ) );
  80. return( hr );
  81. }
  82. //---------------------------------------------------------------------------
  83. //
  84. // CreateChildren
  85. //
  86. // Create and initialize all the children of a given node. This method should
  87. // be overridden in all derived classes that actually have children.
  88. //
  89. STDMETHODIMP CSakNode::CreateChildren( )
  90. {
  91. WsbTraceIn( L"CSakNode::CreateChildren", L"" );
  92. HRESULT hr = E_FAIL;
  93. WsbTraceOut( L"CSakNode::CreateChildren", L"hr = <%ls>", WsbHrAsString( hr ) );
  94. return( hr );
  95. }
  96. HRESULT
  97. CSakNode::InternalDelete(
  98. BOOL Recurse
  99. )
  100. {
  101. WsbTraceIn( L"CSakNode::InternalDelete", L"Recurse = <%ls>", WsbBoolAsString( Recurse ) );
  102. HRESULT hr = S_OK;
  103. //
  104. // Loop through children, deleting them recursively.
  105. //
  106. try {
  107. ISakNode** ppNode;
  108. for( ppNode = m_Children.begin( ); ppNode < m_Children.end( ); ppNode++ ) {
  109. if( *ppNode ) {
  110. (*ppNode)->TerminateNode( );
  111. if( Recurse ) {
  112. (*ppNode)->DeleteAllChildren( );
  113. }
  114. }
  115. }
  116. m_Children.Clear( );
  117. m_bChildrenAreValid = FALSE;
  118. } WsbCatch( hr );
  119. WsbTraceOut( L"CSakNode::InternalDelete", L"hr = <%ls>", WsbHrAsString( hr ) );
  120. return( hr );
  121. }
  122. //---------------------------------------------------------------------------
  123. //
  124. // DeleteChildren
  125. //
  126. // Delete immediate children from this UI node. There is no need for
  127. // derived classes to override this function. This is NOT a recursive function.
  128. //
  129. STDMETHODIMP CSakNode::DeleteChildren( )
  130. {
  131. WsbTraceIn( L"CSakNode::DeleteChildren", L"" );
  132. HRESULT hr = S_OK;
  133. hr = InternalDelete( FALSE );
  134. WsbTraceOut( L"CSakNode::DeleteChildren", L"hr = <%ls>", WsbHrAsString( hr ) );
  135. return( hr );
  136. }
  137. //---------------------------------------------------------------------------
  138. //
  139. // DeleteAllChildren
  140. //
  141. // Delete all children (recursively) from this UI node. There is no need for
  142. // derived classes to override this function. This IS a recursive function.
  143. // It is to be used to totally free up all UI nodes in the snapin from this node
  144. // on down.
  145. //
  146. STDMETHODIMP CSakNode::DeleteAllChildren( void )
  147. {
  148. WsbTraceIn( L"CSakNode::DeleteAllChildren", L"" );
  149. HRESULT hr = S_OK;
  150. hr = InternalDelete( TRUE );
  151. WsbTraceOut( L"CSakNode::DeleteAllChildren", L"hr = <%ls>", WsbHrAsString( hr ) );
  152. return( hr );
  153. }
  154. /////////////////////////////////////////////////////////////////////////////
  155. //
  156. // Helper Functions for derived classes
  157. //
  158. /////////////////////////////////////////////////////////////////////////////
  159. //---------------------------------------------------------------------------
  160. //
  161. // NewChild
  162. //
  163. // Given a string describing the node type, create an instance of the
  164. // corresponding COM object. Return an IUnknown pointer to the new child.
  165. //
  166. HRESULT CSakNode::NewChild( REFGUID nodetype, IUnknown** ppUnkChild )
  167. {
  168. WsbTraceIn( L"CSakNode::NewChild", L"nodetype = <%ls>, ppUnkChild = <0x%p>", WsbGuidAsString( nodetype ), ppUnkChild );
  169. HRESULT hr = S_OK;
  170. try {
  171. // Get the class ID of the new node, based on its spelled-out class.
  172. // Create a COM instance of the child and retrieve its IUnknown interface pointer.
  173. const CLSID * pclsid;
  174. WsbAffirmHr( GetCLSIDFromNodeType( nodetype, &pclsid ) );
  175. WsbAffirmHr( CoCreateInstance( *pclsid, 0, CLSCTX_INPROC, IID_IUnknown, (void**)ppUnkChild ));
  176. } WsbCatch( hr );
  177. WsbTraceOut( L"CSakNode::NewChild", L"hr = <%ls>, *ppUnkChild = <0x%p>", WsbHrAsString( hr ), WsbPtrToPtrAsString( (void**)ppUnkChild ) );
  178. return( hr );
  179. }
  180. //---------------------------------------------------------------------------
  181. //
  182. // GetCLSIDFromNodeType
  183. //
  184. // Given a class node type GUID report back its corresponding CLSID.
  185. //
  186. HRESULT CSakNode::GetCLSIDFromNodeType( REFGUID nodetype, const CLSID ** ppclsid )
  187. {
  188. HRESULT hr = S_FALSE;
  189. *ppclsid = NULL;
  190. // As more classes are introduced into this system, add entries for them here.
  191. if( IsEqualGUID( nodetype, cGuidCar ))
  192. *ppclsid = &CLSID_CUiCar;
  193. else if( IsEqualGUID( nodetype, cGuidHsmCom ))
  194. *ppclsid = &CLSID_CUiHsmCom;
  195. else if( IsEqualGUID( nodetype, cGuidManVol ))
  196. *ppclsid = &CLSID_CUiManVol;
  197. else if( IsEqualGUID( nodetype, cGuidManVolLst ))
  198. *ppclsid = &CLSID_CUiManVolLst;
  199. else if( IsEqualGUID( nodetype, cGuidMedSet ))
  200. *ppclsid = &CLSID_CUiMedSet;
  201. if( *ppclsid )
  202. hr = S_OK;
  203. return( hr );
  204. }
  205. const OLECHAR * CSakNode::GetClassNameFromNodeType( REFGUID NodeType )
  206. {
  207. const OLECHAR * retval = L"Unkown";
  208. if( IsEqualGUID( NodeType, cGuidCar ) )
  209. retval = L"CUiCar";
  210. else if( IsEqualGUID( NodeType, cGuidHsmCom ) )
  211. retval = L"CUiHsmCom";
  212. else if( IsEqualGUID( NodeType, cGuidManVol ) )
  213. retval = L"CUiManVol";
  214. else if( IsEqualGUID( NodeType, cGuidManVolLst ) )
  215. retval = L"CUiManVolLst";
  216. else if( IsEqualGUID( NodeType, cGuidMedSet ) )
  217. retval = L"CUiMedSet";
  218. else if( IsEqualGUID( NodeType, GUID_NULL ) )
  219. retval = L"GUID_NULL";
  220. return( retval );
  221. }