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.

308 lines
8.4 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. root.cpp
  7. Root node information (the root node is not displayed
  8. in the MMC framework but contains information such as
  9. all of the subnodes in this snapin).
  10. FILE HISTORY:
  11. */
  12. #include "stdafx.h"
  13. #include "ATLKROOT.h"
  14. #include "ATLKVIEW.h" // ATLK handlers
  15. #include "rtrcfg.h"
  16. /*---------------------------------------------------------------------------
  17. RipRootHandler implementation
  18. ---------------------------------------------------------------------------*/
  19. DEBUG_DECLARE_INSTANCE_COUNTER(ATLKRootHandler)
  20. extern const ContainerColumnInfo s_rgATLKInterfaceStatsColumnInfo[];
  21. extern const ContainerColumnInfo s_rgATLKGroupStatsColumnInfo[];
  22. struct _ViewInfoColumnEntry
  23. {
  24. UINT m_ulId;
  25. UINT m_cColumns;
  26. const ContainerColumnInfo *m_prgColumn;
  27. };
  28. //static const struct _ViewInfoColumnEntry s_rgViewColumnInfo[] =
  29. //{
  30. // { ATLKSTRM_STATS_ATLKNBR, MVR_ATLKGROUP_COUNT, s_rgATLKGroupStatsColumnInfo },
  31. // { ATLKSTRM_IFSTATS_ATLKNBR, MVR_ATLKINTERFACE_COUNT, s_rgATLKInterfaceStatsColumnInfo },
  32. //};
  33. ATLKRootHandler::ATLKRootHandler(ITFSComponentData *pCompData)
  34. : RootHandler(pCompData)
  35. {
  36. DEBUG_INCREMENT_INSTANCE_COUNTER(ATLKRootHandler)
  37. // m_ConfigStream.Init(DimensionOf(s_rgViewColumnInfo));
  38. // for (int i=0; i<DimensionOf(s_rgViewColumnInfo); i++)
  39. // {
  40. // m_ConfigStream.InitViewInfo(s_rgViewColumnInfo[i].m_ulId,
  41. // s_rgViewColumnInfo[i].m_cColumns,
  42. // s_rgViewColumnInfo[i].m_prgColumn);
  43. // }
  44. }
  45. STDMETHODIMP ATLKRootHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  46. {
  47. // Is the pointer bad?
  48. if ( ppv == NULL )
  49. return E_INVALIDARG;
  50. // Place NULL in *ppv in case of failure
  51. *ppv = NULL;
  52. // This is the non-delegating IUnknown implementation
  53. if ( riid == IID_IUnknown )
  54. *ppv = (LPVOID) this;
  55. else if ( riid == IID_IRtrAdviseSink )
  56. *ppv = &m_IRtrAdviseSink;
  57. else
  58. return RootHandler::QueryInterface(riid, ppv);
  59. // If we're going to return an interface, AddRef it first
  60. if ( *ppv )
  61. {
  62. ((LPUNKNOWN) *ppv)->AddRef();
  63. return hrOK;
  64. }
  65. else
  66. return E_NOINTERFACE;
  67. }
  68. ///////////////////////////////////////////////////////////////////////////////
  69. //// IPersistStream interface members
  70. STDMETHODIMP ATLKRootHandler::GetClassID
  71. (
  72. CLSID *pClassID
  73. )
  74. {
  75. ASSERT(pClassID != NULL);
  76. // Copy the CLSID for this snapin
  77. *pClassID = CLSID_ATLKAdminExtension;
  78. return hrOK;
  79. }
  80. /*!--------------------------------------------------------------------------
  81. ATLKRootHandler::OnExpand
  82. -
  83. Author: KennT
  84. ---------------------------------------------------------------------------*/
  85. HRESULT ATLKRootHandler::OnExpand(ITFSNode *pNode,LPDATAOBJECT pDataObject, DWORD dwType, LPARAM arg,LPARAM lParam)
  86. {
  87. HRESULT hr = hrOK;
  88. SPITFSNode spNode;
  89. SPIRtrMgrProtocolInfo spRmProt;
  90. SPIRouterInfo spRouterInfo;
  91. // Grab the router info from the dataobject
  92. spRouterInfo.Query(pDataObject);
  93. Assert(spRouterInfo);
  94. // dont expand AppleTalk node if remote or
  95. // appletalk isnt installed
  96. if ( !IsLocalMachine(spRouterInfo->GetMachineName()) ||
  97. FHrFailed(IsATLKValid(spRouterInfo)) )
  98. {
  99. hr=hrFail;
  100. goto Error;
  101. }
  102. CORg( AddProtocolNode(pNode, spRouterInfo) );
  103. Error:
  104. return hr;
  105. }
  106. HRESULT ATLKRootHandler::IsATLKValid(IRouterInfo *pRouter)
  107. {
  108. RegKey regkey;
  109. DWORD dwRtrType=0;
  110. HRESULT hr = hrOK;
  111. if ( ERROR_SUCCESS != regkey.Open(HKEY_LOCAL_MACHINE, c_szRegKeyAppletalk) )
  112. {
  113. return hrFail;
  114. }
  115. // If the Router is not a RAS router, then don't show AppleTalk
  116. // ----------------------------------------------------------------
  117. if ( ! (pRouter->GetRouterType() & (ROUTER_TYPE_RAS | ROUTER_TYPE_LAN)) )
  118. {
  119. return hrFail;
  120. }
  121. return hr;
  122. }
  123. /*!--------------------------------------------------------------------------
  124. ATLKRootHandler::OnCreateDataObject
  125. Implementation of ITFSNodeHandler::OnCreateDataObject
  126. Author: KennT
  127. ---------------------------------------------------------------------------*/
  128. STDMETHODIMP ATLKRootHandler::OnCreateDataObject(MMC_COOKIE cookie, DATA_OBJECT_TYPES type, IDataObject **ppDataObject)
  129. {
  130. HRESULT hr = hrOK;
  131. CDataObject * pObject = NULL;
  132. SPIDataObject spDataObject;
  133. SPITFSNode spNode;
  134. SPITFSNodeHandler spHandler;
  135. SPIRouterInfo spRouterInfo;
  136. COM_PROTECT_TRY
  137. {
  138. //if ( m_spRouterInfo == NULL )
  139. if (TRUE)
  140. {
  141. // If we haven't created the sub nodes yet, we still have to
  142. // create a dataobject.
  143. pObject = new CDataObject;
  144. spDataObject = pObject; // do this so that it gets released correctly
  145. Assert(pObject != NULL);
  146. // Save cookie and type for delayed rendering
  147. pObject->SetType(type);
  148. pObject->SetCookie(cookie);
  149. // Store the coclass with the data object
  150. pObject->SetClsid(*(m_spTFSCompData->GetCoClassID()));
  151. pObject->SetTFSComponentData(m_spTFSCompData);
  152. hr = pObject->QueryInterface(IID_IDataObject,
  153. reinterpret_cast<void**>(ppDataObject));
  154. }
  155. else
  156. hr = CreateDataObjectFromRouterInfo(spRouterInfo,
  157. spRouterInfo->GetMachineName(),
  158. type, cookie, m_spTFSCompData,
  159. ppDataObject, NULL, FALSE);
  160. }
  161. COM_PROTECT_CATCH;
  162. return hr;
  163. }
  164. ImplementEmbeddedUnknown(ATLKRootHandler, IRtrAdviseSink)
  165. STDMETHODIMP ATLKRootHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  166. DWORD dwChangeType,
  167. DWORD dwObjectType,
  168. LPARAM lUserParam,
  169. LPARAM lParam)
  170. {
  171. InitPThis(ATLKRootHandler, IRtrAdviseSink);
  172. HRESULT hr = hrOK;
  173. SPITFSNode spNode;
  174. if ( dwObjectType != ROUTER_OBJ_RmProt )
  175. return hr;
  176. COM_PROTECT_TRY
  177. {
  178. if ( dwChangeType == ROUTER_CHILD_ADD )
  179. {
  180. }
  181. else if ( dwChangeType == ROUTER_CHILD_DELETE )
  182. {
  183. }
  184. }
  185. COM_PROTECT_CATCH;
  186. return hr;
  187. }
  188. /*!--------------------------------------------------------------------------
  189. ATLKRootHandler::DestroyHandler
  190. -
  191. Author: KennT
  192. ---------------------------------------------------------------------------*/
  193. STDMETHODIMP ATLKRootHandler::DestroyHandler(ITFSNode *pNode)
  194. {
  195. return hrOK;
  196. }
  197. /*!--------------------------------------------------------------------------
  198. ATLKRootHandler::AddProtocolNode
  199. -
  200. Author: KennT
  201. ---------------------------------------------------------------------------*/
  202. HRESULT ATLKRootHandler::AddProtocolNode(ITFSNode *pNode, IRouterInfo * pRouterInfo)
  203. {
  204. SPITFSNodeHandler spHandler;
  205. ATLKNodeHandler * pHandler = NULL;
  206. HRESULT hr = hrOK;
  207. SPITFSNode spNode;
  208. pHandler = new ATLKNodeHandler(m_spTFSCompData);
  209. spHandler = pHandler;
  210. CORg( pHandler->Init(pRouterInfo, &m_ConfigStream) );
  211. CreateContainerTFSNode(&spNode,
  212. &GUID_ATLKNodeType,
  213. static_cast<ITFSNodeHandler *>(pHandler),
  214. static_cast<ITFSResultHandler *>(pHandler),
  215. m_spNodeMgr);
  216. // Call to the node handler to init the node data
  217. pHandler->ConstructNode(spNode);
  218. // Make the node immediately visible
  219. spNode->SetVisibilityState(TFS_VIS_SHOW);
  220. pNode->AddChild(spNode);
  221. Error:
  222. return hr;
  223. }
  224. /*!--------------------------------------------------------------------------
  225. ATLKRootHandler::RemoveProtocolNode
  226. -
  227. Author: KennT
  228. ---------------------------------------------------------------------------*/
  229. HRESULT ATLKRootHandler::RemoveProtocolNode(ITFSNode *pNode)
  230. {
  231. Assert(pNode);
  232. SPITFSNodeEnum spNodeEnum;
  233. SPITFSNode spNode;
  234. HRESULT hr = hrOK;
  235. CORg( pNode->GetEnum(&spNodeEnum) );
  236. while ( spNodeEnum->Next(1, &spNode, NULL) == hrOK )
  237. {
  238. pNode->RemoveChild(spNode);
  239. spNode->Destroy();
  240. spNode.Release();
  241. }
  242. Error:
  243. return hr;
  244. }