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.

119 lines
3.0 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // File: pubenum.cpp
  6. //
  7. // The current order of enumeration is Legacy --> Darwin --> SMS
  8. //
  9. // History:
  10. // 1-18-97 by dli
  11. //------------------------------------------------------------------------
  12. #include "priv.h"
  13. #include "pubenum.h"
  14. void _DestroyHdpaEnum(HDPA hdpaEnum)
  15. {
  16. ASSERT(IsValidHDPA(hdpaEnum));
  17. IEnumPublishedApps * pepa;
  18. int idpa;
  19. for (idpa = 0; idpa < DPA_GetPtrCount(hdpaEnum); idpa++)
  20. {
  21. pepa = (IEnumPublishedApps *)DPA_GetPtr(hdpaEnum, idpa);
  22. if (EVAL(pepa))
  23. pepa->Release();
  24. }
  25. DPA_Destroy(hdpaEnum);
  26. }
  27. CShellEnumPublishedApps::CShellEnumPublishedApps(HDPA hdpaEnum) : _cRef(1), _hdpaEnum(hdpaEnum)
  28. {
  29. }
  30. CShellEnumPublishedApps::~CShellEnumPublishedApps()
  31. {
  32. if (_hdpaEnum)
  33. _DestroyHdpaEnum(_hdpaEnum);
  34. }
  35. // IEnumPublishedApps::QueryInterface
  36. HRESULT CShellEnumPublishedApps::QueryInterface(REFIID riid, LPVOID * ppvOut)
  37. {
  38. static const QITAB qit[] = {
  39. QITABENT(CShellEnumPublishedApps, IEnumPublishedApps), // IID_IEnumPublishedApps
  40. { 0 },
  41. };
  42. return QISearch(this, qit, riid, ppvOut);
  43. }
  44. // IEnumPublishedApps::AddRef
  45. ULONG CShellEnumPublishedApps::AddRef()
  46. {
  47. _cRef++;
  48. TraceMsg(TF_OBJLIFE, "CShellEnumPublishedApps()::AddRef called, new _cRef=%lX", _cRef);
  49. return _cRef;
  50. }
  51. // IEnumPublishedApps::Release
  52. ULONG CShellEnumPublishedApps::Release()
  53. {
  54. _cRef--;
  55. TraceMsg(TF_OBJLIFE, "CShellEnumPublishedApps()::Release called, new _cRef=%lX", _cRef);
  56. if (_cRef > 0)
  57. return _cRef;
  58. delete this;
  59. return 0;
  60. }
  61. // IEnumPublishedApps::Next
  62. HRESULT CShellEnumPublishedApps::Next(IPublishedApp ** ppia)
  63. {
  64. HRESULT hres = E_FAIL;
  65. if (_hdpaEnum)
  66. {
  67. IEnumPublishedApps * pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, _iEnum);
  68. //
  69. // If pepa is not valid or pepa->Next failed, or at the end of the current enumerator,
  70. // we skip this Enumerator, and go on to the next one until we hit the limit
  71. while ((!pepa || S_OK != (hres = pepa->Next(ppia))) && (_iEnum < DPA_GetPtrCount(_hdpaEnum)))
  72. {
  73. _iEnum++;
  74. pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, _iEnum);
  75. }
  76. }
  77. return hres;
  78. }
  79. // IEnumPublishedApps::Reset
  80. HRESULT CShellEnumPublishedApps::Reset(void)
  81. {
  82. // Call reset on everyone in the list and set our index iEnum to 0;
  83. if (_hdpaEnum)
  84. {
  85. IEnumPublishedApps * pepa;
  86. int idpa;
  87. for (idpa = 0; idpa < DPA_GetPtrCount(_hdpaEnum); idpa++)
  88. {
  89. pepa = (IEnumPublishedApps *)DPA_GetPtr(_hdpaEnum, idpa);
  90. if (pepa)
  91. pepa->Reset();
  92. }
  93. _iEnum = 0;
  94. return S_OK;
  95. }
  96. return E_FAIL;
  97. }