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.

435 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1998 **/
  4. /**********************************************************************/
  5. /*
  6. DVSumSTRM.cpp
  7. FILE HISTORY:
  8. */
  9. #include "stdafx.h"
  10. #include "dmvstrm.h"
  11. #include "dmvcomp.h"
  12. #include "xstream.h"
  13. #include "dmvroot.h"
  14. #include "refresh.h"
  15. #define CURRENT_DMVCONFIGSTREAM_VERSION 0x00020000
  16. /*!--------------------------------------------------------------------------
  17. DMVConfigStream::DMVConfigStream
  18. -
  19. Author: KennT
  20. ---------------------------------------------------------------------------*/
  21. DMVConfigStream::DMVConfigStream()
  22. {
  23. m_nVersionAdmin = 0x00010000;
  24. m_nVersion = CURRENT_DMVCONFIGSTREAM_VERSION;
  25. m_bAutoRefresh = FALSE;
  26. m_dwRefreshInterval = DEFAULT_REFRESH_INTERVAL;
  27. }
  28. /*!--------------------------------------------------------------------------
  29. DMVConfigStream::InitNew
  30. -
  31. Author: KennT
  32. ---------------------------------------------------------------------------*/
  33. HRESULT DMVConfigStream::InitNew()
  34. {
  35. // Setup the appropriate defaults
  36. // m_nVersionAdmin = 0x00020000;
  37. // m_nVersion = 0x00020000;
  38. // m_stName.Empty();
  39. return hrOK;
  40. }
  41. HRESULT DMVConfigStream::PrepareAutoRefreshDataForSave()
  42. {
  43. SPIRouterRefresh spRefresh;
  44. ASSERT(m_pDMVRootHandler);
  45. if (!m_pDMVRootHandler)
  46. return S_OK;
  47. HRESULT hr = m_pDMVRootHandler->GetServerNodesRefreshObject(&spRefresh);
  48. if(FAILED(hr) || !spRefresh)
  49. return S_OK;
  50. if(spRefresh->IsRefreshStarted() == hrOK)
  51. m_bAutoRefresh = TRUE;
  52. return spRefresh->GetRefreshInterval(&m_dwRefreshInterval);
  53. }
  54. /*!--------------------------------------------------------------------------
  55. DMVConfigStream::SaveTo
  56. -
  57. Author: KennT
  58. ---------------------------------------------------------------------------*/
  59. HRESULT DMVConfigStream::SaveTo(IStream *pstm)
  60. {
  61. return XferVersion0(pstm, XferStream::MODE_WRITE, NULL);
  62. }
  63. /*!--------------------------------------------------------------------------
  64. DMVConfigStream::SaveAs
  65. -
  66. Author: KennT
  67. ---------------------------------------------------------------------------*/
  68. HRESULT DMVConfigStream::SaveAs(UINT nVersion, IStream *pstm)
  69. {
  70. return XferVersion0(pstm, XferStream::MODE_WRITE, NULL);
  71. }
  72. /*!--------------------------------------------------------------------------
  73. DMVConfigStream::LoadFrom
  74. -
  75. Author: KennT
  76. ---------------------------------------------------------------------------*/
  77. HRESULT DMVConfigStream::LoadFrom(IStream *pstm)
  78. {
  79. return XferVersion0(pstm, XferStream::MODE_READ, NULL);
  80. }
  81. /*!--------------------------------------------------------------------------
  82. DMVConfigStream::GetSize
  83. -
  84. Author: KennT
  85. ---------------------------------------------------------------------------*/
  86. HRESULT DMVConfigStream::GetSize(ULONG *pcbSize)
  87. {
  88. return XferVersion0(NULL, XferStream::MODE_SIZE, NULL);
  89. }
  90. /*!--------------------------------------------------------------------------
  91. DMVConfigStream::GetVersionInfo
  92. -
  93. Author: KennT
  94. ---------------------------------------------------------------------------*/
  95. HRESULT DMVConfigStream::GetVersionInfo(DWORD *pdwVersion, DWORD *pdwAdminVersion)
  96. {
  97. if (pdwVersion)
  98. *pdwVersion = m_nVersion;
  99. if (pdwAdminVersion)
  100. *pdwAdminVersion = m_nVersionAdmin;
  101. return hrOK;
  102. }
  103. /*!--------------------------------------------------------------------------
  104. DMVConfigStream::XferVersion0
  105. -
  106. Author: KennT
  107. ---------------------------------------------------------------------------*/
  108. struct _ViewInfoEntry
  109. {
  110. ULONG m_ulId;
  111. ULONG m_idSort;
  112. ULONG m_idAscending;
  113. ULONG m_idColumns;
  114. ULONG m_idPos;
  115. };
  116. /*static const _ViewInfoEntry s_rgDVSumAdminViewInfo[]
  117. {
  118. { DVSumSTRM_STATS_DVSumNBR,
  119. DVSumSTRM_TAG_STATS_DVSumNBR_SORT, DVSumSTRM_TAG_STATS_DVSumNBR_ASCENDING,
  120. DVSumSTRM_TAG_STATS_DVSumNBR_COLUMNS, DVSumSTRM_TAG_STATS_DVSumNBR_POSITION },
  121. { DVSumSTRM_IFSTATS_DVSumNBR,
  122. DVSumSTRM_TAG_IFSTATS_DVSumNBR_SORT, DVSumSTRM_TAG_IFSTATS_DVSumNBR_ASCENDING,
  123. DVSumSTRM_TAG_IFSTATS_DVSumNBR_COLUMNS, DVSumSTRM_TAG_IFSTATS_DVSumNBR_POSITION },
  124. };
  125. */
  126. HRESULT DMVConfigStream::XferVersion0(IStream *pstm, XferStream::Mode mode, ULONG *pcbSize)
  127. {
  128. XferStream xstm(pstm, mode);
  129. HRESULT hr = hrOK;
  130. DWORD dwNum1;
  131. DWORD dwNum2;
  132. int i;
  133. if (mode==XferStream::MODE_WRITE)
  134. {
  135. // If we are writing the data, reload the current set of server names
  136. // (get it from the real list of nodes)
  137. // -------------------------------------------------------------
  138. Assert(m_pDMVRootHandler);
  139. m_pDMVRootHandler->LoadPersistedServerListFromNode();
  140. };
  141. CORg( xstm.XferDWORD( DMVSTRM_TAG_VERSION, &m_nVersion ) );
  142. CORg( xstm.XferDWORD( DMVSTRM_TAG_VERSIONADMIN, &m_nVersionAdmin ) );
  143. if (m_nVersion != CURRENT_DMVCONFIGSTREAM_VERSION)
  144. return E_FAIL;
  145. /*
  146. for ( i=0; i<DimensionOf(s_rgDVSumAdminViewInfo); i++)
  147. {
  148. CORg( m_rgViewInfo[s_rgDVSumAdminViewInfo[i].m_ulId].Xfer(&xstm,
  149. s_rgDVSumAdminViewInfo[i].m_idSort,
  150. s_rgDVSumAdminViewInfo[i].m_idAscending,
  151. s_rgDVSumAdminViewInfo[i].m_idColumns) );
  152. CORg( xstm.XferRect( s_rgDVSumAdminViewInfo[i].m_idPos,
  153. &m_prgrc[s_rgDVSumAdminViewInfo[i].m_ulId]) );
  154. }
  155. */
  156. CORg( xstm.XferDWORD( DMVSTRM_TAG_SIZEQRY, &(m_RQPersist.m_dwSizeQry) ) );
  157. if (mode==XferStream::MODE_READ)
  158. {
  159. CORg( xstm.XferDWORD( DMVSTRM_TAG_NUMQRY, &(dwNum1) ) );
  160. m_RQPersist.createQry(dwNum1);
  161. CORg( xstm.XferDWORD( DMVSTRM_TAG_NUMSRV, &(dwNum2) ) );
  162. m_RQPersist.createSrv(dwNum2);
  163. }
  164. else
  165. {
  166. CORg( xstm.XferDWORD( DMVSTRM_TAG_NUMQRY, &(m_RQPersist.m_dwNumQry) ) );
  167. CORg( xstm.XferDWORD( DMVSTRM_TAG_NUMSRV, &(m_RQPersist.m_dwNumSrv) ) );
  168. }
  169. Assert(m_RQPersist.m_v_pQData.size()==m_RQPersist.m_dwNumQry);
  170. Assert(m_RQPersist.m_v_pSData.size()==m_RQPersist.m_dwNumSrv);
  171. //persist the query list
  172. for (i=0; i < m_RQPersist.m_dwNumQry;i++)
  173. {
  174. CORg( xstm.XferDWORD( DMVSTRM_TAG_CATFLAG, &(m_RQPersist.m_v_pQData[i]->dwCatFlag) ) );
  175. CORg( xstm.XferCString( DMVSTRM_TAG_SCOPE, &(m_RQPersist.m_v_pQData[i]->strScope) ) );
  176. CORg( xstm.XferCString( DMVSTRM_TAG_FILTER, &(m_RQPersist.m_v_pQData[i]->strFilter) ) );
  177. }
  178. //persist the servername list
  179. for (i=0; i < m_RQPersist.m_dwNumSrv;i++)
  180. {
  181. CORg( xstm.XferCString(DMVSTRM_TAG_SERVERNAME, m_RQPersist.m_v_pSData[i]) );
  182. }
  183. if (mode==XferStream::MODE_READ)
  184. {
  185. // Load the list of persisted servers (add them to the list of
  186. // servers to be added into the UI).
  187. Assert(m_pDMVRootHandler);
  188. m_pDMVRootHandler->LoadPersistedServerList();
  189. }
  190. // refresh settings
  191. if (mode==XferStream::MODE_WRITE)
  192. {
  193. PrepareAutoRefreshDataForSave();
  194. }
  195. CORg( xstm.XferDWORD( DMVSTRM_TAG_IFAUTOREFRESHISON, &m_bAutoRefresh ) );
  196. CORg( xstm.XferDWORD( DMVSTRM_TAG_AUTOREFRESHINTERVAL, &m_dwRefreshInterval ) );
  197. if (pcbSize)
  198. *pcbSize = xstm.GetSize();
  199. Error:
  200. return hr;
  201. }
  202. /*---------------------------------------------------------------------------
  203. DVSumComponentConfigStream implementation
  204. ---------------------------------------------------------------------------*/
  205. enum DVSCOMPSTRM_TAG
  206. {
  207. DVSCOMPSTRM_TAG_VERSION = XFER_TAG(1, XFER_DWORD),
  208. DVSCOMPSTRM_TAG_VERSIONADMIN = XFER_TAG(2, XFER_DWORD),
  209. DVSCOMPSTRM_TAG_SUMMARY_COLUMNS = XFER_TAG(3, XFER_COLUMNDATA_ARRAY),
  210. DVSCOMPSTRM_TAG_SUMMARY_SORT_COLUMN = XFER_TAG(4, XFER_DWORD),
  211. DVSCOMPSTRM_TAG_SUMMARY_SORT_ASCENDING = XFER_TAG(5, XFER_DWORD),
  212. DVSCOMPSTRM_TAG_IFADMIN_COLUMNS = XFER_TAG(6, XFER_COLUMNDATA_ARRAY),
  213. DVSCOMPSTRM_TAG_IFADMIN_SORT_COLUMN = XFER_TAG(7, XFER_DWORD),
  214. DVSCOMPSTRM_TAG_IFADMIN_SORT_ASCENDING = XFER_TAG(8, XFER_DWORD),
  215. DVSCOMPSTRM_TAG_DIALIN_COLUMNS = XFER_TAG(9, XFER_COLUMNDATA_ARRAY),
  216. DVSCOMPSTRM_TAG_DIALIN_SORT_COLUMN = XFER_TAG(10, XFER_DWORD),
  217. DVSCOMPSTRM_TAG_DIALIN_SORT_ASCENDING = XFER_TAG(11, XFER_DWORD),
  218. DVSCOMPSTRM_TAG_PORTS_COLUMNS = XFER_TAG(12, XFER_COLUMNDATA_ARRAY),
  219. DVSCOMPSTRM_TAG_PORTS_SORT_COLUMN = XFER_TAG(13, XFER_DWORD),
  220. DVSCOMPSTRM_TAG_PORTS_SORT_ASCENDING = XFER_TAG(14, XFER_DWORD),
  221. };
  222. HRESULT DVComponentConfigStream::XferVersion0(IStream *pstm, XferStream::Mode mode, ULONG *pcbSize)
  223. {
  224. XferStream xstm(pstm, mode);
  225. HRESULT hr = hrOK;
  226. CORg( xstm.XferDWORD( DVSCOMPSTRM_TAG_VERSION, &m_nVersion ) );
  227. CORg( xstm.XferDWORD( DVSCOMPSTRM_TAG_VERSIONADMIN, &m_nVersionAdmin ) );
  228. CORg( m_rgViewInfo[DM_COLUMNS_DVSUM].Xfer(&xstm,
  229. DVSCOMPSTRM_TAG_SUMMARY_SORT_COLUMN,
  230. DVSCOMPSTRM_TAG_SUMMARY_SORT_ASCENDING,
  231. DVSCOMPSTRM_TAG_SUMMARY_COLUMNS) );
  232. CORg( m_rgViewInfo[DM_COLUMNS_IFADMIN].Xfer(&xstm,
  233. DVSCOMPSTRM_TAG_IFADMIN_SORT_COLUMN,
  234. DVSCOMPSTRM_TAG_IFADMIN_SORT_ASCENDING,
  235. DVSCOMPSTRM_TAG_IFADMIN_COLUMNS) );
  236. CORg( m_rgViewInfo[DM_COLUMNS_DIALIN].Xfer(&xstm,
  237. DVSCOMPSTRM_TAG_DIALIN_SORT_COLUMN,
  238. DVSCOMPSTRM_TAG_DIALIN_SORT_ASCENDING,
  239. DVSCOMPSTRM_TAG_DIALIN_COLUMNS) );
  240. CORg( m_rgViewInfo[DM_COLUMNS_PORTS].Xfer(&xstm,
  241. DVSCOMPSTRM_TAG_PORTS_SORT_COLUMN,
  242. DVSCOMPSTRM_TAG_PORTS_SORT_ASCENDING,
  243. DVSCOMPSTRM_TAG_PORTS_COLUMNS) );
  244. if (pcbSize)
  245. *pcbSize = xstm.GetSize();
  246. Error:
  247. return hr;
  248. }
  249. //---------------------------------------------------------------
  250. // RRASQryPersist implementation
  251. //---------------------------------------------------------------
  252. HRESULT RRASQryPersist::createQry(DWORD dwNum)
  253. {
  254. HRESULT hr=S_OK;
  255. try
  256. {
  257. removeAllQry();
  258. m_dwNumQry=dwNum;
  259. for (int i=0;i<m_dwNumQry;i++)
  260. {
  261. RRASQryData* p = new RRASQryData;
  262. p->dwCatFlag=RRAS_QRY_CAT_NONE;
  263. p->strScope=_T("");
  264. p->strFilter=_T("");
  265. m_v_pQData.push_back(p);
  266. }
  267. }
  268. catch(...)
  269. {
  270. hr=E_FAIL;
  271. }
  272. return hr;
  273. }
  274. HRESULT RRASQryPersist::createSrv(DWORD dwNum)
  275. {
  276. HRESULT hr=S_OK;
  277. try
  278. {
  279. removeAllSrv();
  280. m_dwNumSrv=dwNum;
  281. for (int i=0;i<m_dwNumSrv;i++)
  282. m_v_pSData.push_back(new CString);
  283. }
  284. catch(...)
  285. {
  286. hr=E_FAIL;
  287. }
  288. return hr;
  289. }
  290. HRESULT RRASQryPersist::add_Qry(const RRASQryData& qd)
  291. {
  292. HRESULT hr=S_OK;
  293. try
  294. {
  295. for (int i=0;i<m_v_pQData.size(); i++ )
  296. {
  297. RRASQryData& qd0 = *(m_v_pQData[i]);
  298. if ( (qd0.dwCatFlag==qd.dwCatFlag) &&
  299. (qd0.strScope==qd.strScope) &&
  300. (qd0.strFilter==qd.strFilter) )
  301. return S_FALSE;
  302. }
  303. RRASQryData *pqd= new RRASQryData ;
  304. pqd->dwCatFlag=qd.dwCatFlag;
  305. pqd->strScope=qd.strScope;
  306. pqd->strFilter=qd.strFilter;
  307. m_v_pQData.push_back(pqd);
  308. m_dwNumQry++;
  309. }
  310. catch(...)
  311. {
  312. hr=E_FAIL;
  313. }
  314. return hr;
  315. }
  316. HRESULT RRASQryPersist::add_Srv(const CString& szServer)
  317. {
  318. HRESULT hr=S_OK;
  319. try
  320. {
  321. for (int i=0;i<m_v_pSData.size(); i++ )
  322. {
  323. if ( szServer==*(m_v_pSData[i]) )
  324. return S_FALSE;
  325. }
  326. CString* psz= new CString(szServer) ;
  327. m_v_pSData.push_back(psz);
  328. m_dwNumSrv++;
  329. }
  330. catch(...)
  331. {
  332. hr=E_FAIL;
  333. }
  334. return hr;
  335. }
  336. HRESULT RRASQryPersist::removeAllSrv()
  337. {
  338. HRESULT hr=S_OK;
  339. try
  340. {
  341. for (int i=0;i<m_v_pSData.size(); i++ )
  342. delete m_v_pSData[i];
  343. m_v_pSData.clear();
  344. }
  345. catch(...)
  346. {
  347. hr=E_FAIL;
  348. }
  349. m_dwNumSrv=0;
  350. return hr;
  351. }
  352. HRESULT RRASQryPersist::removeAllQry()
  353. {
  354. HRESULT hr=S_OK;
  355. try
  356. {
  357. for (int i=0;i<m_v_pQData.size(); i++ )
  358. delete m_v_pQData[i];
  359. m_v_pQData.clear();
  360. }
  361. catch(...)
  362. {
  363. TRACE0("RRASQryPersist::remove error\n");
  364. hr=E_FAIL;
  365. }
  366. m_dwNumQry=0;
  367. return hr;
  368. }