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.

129 lines
2.6 KiB

  1. //____________________________________________________________________________
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997 - 1999
  5. //
  6. // File: TaskEnum.cpp
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 11/19/1997 RaviR Created
  15. //____________________________________________________________________________
  16. //
  17. #include "stdafx.h"
  18. #include "taskenum.h"
  19. CTaskEnumerator::~CTaskEnumerator()
  20. {
  21. POSITION pos = m_list.GetHeadPosition();
  22. while (pos)
  23. {
  24. STaskEnums& rte = m_list.GetNext(pos);
  25. rte.pET->Release();
  26. }
  27. m_list.RemoveAll();
  28. }
  29. bool
  30. CTaskEnumerator::AddTaskEnumerator(
  31. const CLSID& clsid,
  32. IEnumTASK* pEnumTASK)
  33. {
  34. ASSERT(pEnumTASK != NULL);
  35. if (pEnumTASK == NULL)
  36. return false;
  37. STaskEnums te;
  38. te.clsid = clsid;
  39. te.pET = pEnumTASK;
  40. m_list.AddTail(te);
  41. pEnumTASK->AddRef();
  42. if (m_posCurr == NULL)
  43. m_posCurr = m_list.GetHeadPosition();
  44. return true;
  45. }
  46. STDMETHODIMP
  47. CTaskEnumerator::Next(
  48. ULONG celt,
  49. MMC_TASK *rgelt,
  50. ULONG *pceltFetched)
  51. {
  52. ASSERT(celt == 1);
  53. if (celt != 1)
  54. return E_INVALIDARG;
  55. ASSERT(rgelt != NULL);
  56. if (rgelt == NULL)
  57. return E_POINTER;
  58. // init
  59. if (pceltFetched != NULL)
  60. *pceltFetched = 0;
  61. if (m_posCurr == NULL)
  62. return S_FALSE;
  63. HRESULT hr = S_FALSE;
  64. while (m_posCurr != NULL)
  65. {
  66. STaskEnums& rte = m_list.GetAt(m_posCurr);
  67. ASSERT(&rte != NULL);
  68. ULONG celtFetched = 0;
  69. hr = rte.pET->Next(1, rgelt, &celtFetched);
  70. ASSERT(SUCCEEDED(hr));
  71. if (pceltFetched)
  72. *pceltFetched = celtFetched;
  73. #ifdef DBG
  74. if (hr == S_FALSE) { ASSERT(celtFetched == 0); }
  75. #endif // DBG
  76. if (hr == S_OK)
  77. {
  78. MMC_ITASK* pTASK = reinterpret_cast<MMC_ITASK*>(rgelt);
  79. hr = ::StringFromCLSID(rte.clsid, &(pTASK->szClsid));
  80. ASSERT(SUCCEEDED(hr));
  81. break;
  82. }
  83. else if (FAILED(hr))
  84. {
  85. // continue if the snapin failed enum tasks
  86. hr = S_FALSE;
  87. }
  88. m_list.GetNext(m_posCurr);
  89. }
  90. return hr;
  91. }
  92. STDMETHODIMP
  93. CTaskEnumerator::Reset()
  94. {
  95. POSITION pos = m_list.GetHeadPosition();
  96. while (pos != NULL && pos != m_posCurr)
  97. {
  98. STaskEnums& rte = m_list.GetNext(pos);
  99. ASSERT(&rte != NULL);
  100. rte.pET->Reset();
  101. }
  102. m_posCurr = m_list.GetHeadPosition();
  103. return S_OK;
  104. }