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.

213 lines
5.7 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. ipface
  7. Base IP interface node handler
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "ipface.h"
  12. #include "ipadmin.h" // for CreateDataObjectFromInterfaceInfo
  13. #include "column.h" // for ComponentConfigStream
  14. #include "ipconn.h" // for IPConnection
  15. #include "mstatus.h"
  16. BaseIPResultNodeData::BaseIPResultNodeData()
  17. {
  18. #ifdef DEBUG
  19. StrCpy(m_szDebug, _T("BaseIPResultNodeData"));
  20. #endif
  21. m_pIPConnection = NULL;
  22. }
  23. BaseIPResultNodeData::~BaseIPResultNodeData()
  24. {
  25. if (m_pIPConnection)
  26. m_pIPConnection->Release();
  27. m_pIPConnection = NULL;
  28. }
  29. HRESULT BaseIPResultNodeData::Init(ITFSNode *pNode, IInterfaceInfo *pIf,
  30. IPConnection *pIPConn)
  31. {
  32. HRESULT hr = hrOK;
  33. BaseIPResultNodeData * pData = NULL;
  34. pData = new BaseIPResultNodeData;
  35. pData->m_spIf.Set(pIf);
  36. pData->m_pIPConnection = pIPConn;
  37. pIPConn->AddRef();
  38. SET_BASEIPRESULT_NODEDATA(pNode, pData);
  39. return hr;
  40. }
  41. HRESULT BaseIPResultNodeData::Free(ITFSNode *pNode)
  42. {
  43. BaseIPResultNodeData * pData = GET_BASEIPRESULT_NODEDATA(pNode);
  44. ASSERT_BASEIPRESULT_NODEDATA(pData);
  45. pData->m_spIf.Release();
  46. delete pData;
  47. SET_BASEIPRESULT_NODEDATA(pNode, NULL);
  48. return hrOK;
  49. }
  50. /*---------------------------------------------------------------------------
  51. BaseIPResultHandler implementation
  52. ---------------------------------------------------------------------------*/
  53. DEBUG_DECLARE_INSTANCE_COUNTER(BaseIPResultHandler)
  54. IMPLEMENT_ADDREF_RELEASE(BaseIPResultHandler)
  55. STDMETHODIMP BaseIPResultHandler::QueryInterface(REFIID riid, LPVOID *ppv)
  56. {
  57. // Is the pointer bad?
  58. if (ppv == NULL)
  59. return E_INVALIDARG;
  60. // Place NULL in *ppv in case of failure
  61. *ppv = NULL;
  62. // This is the non-delegating IUnknown implementation
  63. if (riid == IID_IUnknown)
  64. *ppv = (LPVOID) this;
  65. else if (riid == IID_IRtrAdviseSink)
  66. *ppv = &m_IRtrAdviseSink;
  67. else
  68. return CBaseResultHandler::QueryInterface(riid, ppv);
  69. // If we're going to return an interface, AddRef it first
  70. if (*ppv)
  71. {
  72. ((LPUNKNOWN) *ppv)->AddRef();
  73. return hrOK;
  74. }
  75. else
  76. return E_NOINTERFACE;
  77. }
  78. /*---------------------------------------------------------------------------
  79. NodeHandler implementation
  80. ---------------------------------------------------------------------------*/
  81. /*!--------------------------------------------------------------------------
  82. BaseIPResultHandler::GetString
  83. -
  84. Author: KennT
  85. ---------------------------------------------------------------------------*/
  86. STDMETHODIMP_(LPCTSTR) BaseIPResultHandler::GetString(ITFSComponent * pComponent,
  87. MMC_COOKIE cookie,
  88. int nCol)
  89. {
  90. Assert(m_spNodeMgr);
  91. SPITFSNode spNode;
  92. BaseIPResultNodeData * pData;
  93. ConfigStream * pConfig;
  94. m_spNodeMgr->FindNode(cookie, &spNode);
  95. Assert(spNode);
  96. pData = GET_BASEIPRESULT_NODEDATA(spNode);
  97. Assert(pData);
  98. ASSERT_BASEIPRESULT_NODEDATA(pData);
  99. pComponent->GetUserData((LONG_PTR *) &pConfig);
  100. Assert(pConfig);
  101. return pData->m_rgData[pConfig->MapColumnToSubitem(m_ulColumnId, nCol)].m_stData;
  102. }
  103. /*!--------------------------------------------------------------------------
  104. BaseIPResultHandler::CompareItems
  105. -
  106. Author: KennT
  107. ---------------------------------------------------------------------------*/
  108. STDMETHODIMP_(int) BaseIPResultHandler::CompareItems(ITFSComponent * pComponent,
  109. MMC_COOKIE cookieA, MMC_COOKIE cookieB, int nCol)
  110. {
  111. ConfigStream * pConfig;
  112. pComponent->GetUserData((LONG_PTR *) &pConfig);
  113. Assert(pConfig);
  114. int nSubItem = pConfig->MapColumnToSubitem(m_ulColumnId, nCol);
  115. if (pConfig->GetSortCriteria(m_ulColumnId, nCol) == CON_SORT_BY_DWORD)
  116. {
  117. SPITFSNode spNodeA, spNodeB;
  118. BaseIPResultNodeData * pNodeDataA, *pNodeDataB;
  119. m_spNodeMgr->FindNode(cookieA, &spNodeA);
  120. m_spNodeMgr->FindNode(cookieB, &spNodeB);
  121. pNodeDataA = GET_BASEIPRESULT_NODEDATA(spNodeA);
  122. ASSERT_BASEIPRESULT_NODEDATA(pNodeDataA);
  123. pNodeDataB = GET_BASEIPRESULT_NODEDATA(spNodeB);
  124. ASSERT_BASEIPRESULT_NODEDATA(pNodeDataB);
  125. return pNodeDataA->m_rgData[nSubItem].m_dwData -
  126. pNodeDataB->m_rgData[nSubItem].m_dwData;
  127. }
  128. else
  129. return StriCmpW(GetString(pComponent, cookieA, nCol),
  130. GetString(pComponent, cookieB, nCol));
  131. }
  132. ImplementEmbeddedUnknown(BaseIPResultHandler, IRtrAdviseSink)
  133. STDMETHODIMP BaseIPResultHandler::EIRtrAdviseSink::OnChange(LONG_PTR ulConn,
  134. DWORD dwChangeType, DWORD dwObjectType, LPARAM lUserParam, LPARAM lParam)
  135. {
  136. InitPThis(BaseIPResultHandler, IRtrAdviseSink);
  137. HRESULT hr = hrOK;
  138. Panic0("Should never reach here, interface nodes have no children");
  139. return hr;
  140. }
  141. HRESULT BaseIPResultHandler::Init(IInterfaceInfo *pIfInfo, ITFSNode *pParent)
  142. {
  143. return hrOK;
  144. }
  145. STDMETHODIMP BaseIPResultHandler::DestroyResultHandler(MMC_COOKIE cookie)
  146. {
  147. SPITFSNode spNode;
  148. m_spNodeMgr->FindNode(cookie, &spNode);
  149. BaseIPResultNodeData::Free(spNode);
  150. BaseRouterHandler::DestroyResultHandler(cookie);
  151. return hrOK;
  152. }
  153. /*!--------------------------------------------------------------------------
  154. FillInNumberData
  155. -
  156. Author: KennT
  157. ---------------------------------------------------------------------------*/
  158. void FillInNumberData(BaseIPResultNodeData *pNodeData, UINT iIndex,
  159. DWORD dwData)
  160. {
  161. TCHAR szNumber[32];
  162. FormatNumber(dwData, szNumber, DimensionOf(szNumber), FALSE);
  163. pNodeData->m_rgData[iIndex].m_stData = szNumber;
  164. pNodeData->m_rgData[iIndex].m_dwData = dwData;
  165. }