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.

131 lines
3.5 KiB

  1. //---------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // File: darenum.cpp
  6. //
  7. // The current order of enumeration is Legacy --> Darwin --> SMS
  8. //
  9. // History:
  10. // 2-03-97 by dli
  11. //------------------------------------------------------------------------
  12. #include "priv.h"
  13. #include "darenum.h"
  14. #include "darapp.h"
  15. #include "util.h"
  16. CDarwinEnumPublishedApps::CDarwinEnumPublishedApps(GUID * pAppCategoryId) : _cRef(1)
  17. {
  18. ASSERT(_bGuidUsed == FALSE);
  19. // Do we have a Catogory GUID?
  20. if (pAppCategoryId)
  21. {
  22. // Yes
  23. _CategoryGUID = *pAppCategoryId;
  24. _bGuidUsed = TRUE;
  25. }
  26. GetManagedApplications(_bGuidUsed ? &_CategoryGUID : NULL, _bGuidUsed ? MANAGED_APPS_FROMCATEGORY : MANAGED_APPS_USERAPPLICATIONS,
  27. MANAGED_APPS_INFOLEVEL_DEFAULT, &_dwNumApps, &_prgApps);
  28. }
  29. CDarwinEnumPublishedApps::~CDarwinEnumPublishedApps()
  30. {
  31. if (_prgApps && (_dwNumApps > 0))
  32. {
  33. LocalFree(_prgApps);
  34. }
  35. }
  36. // IEnumPublishedApps::QueryInterface
  37. HRESULT CDarwinEnumPublishedApps::QueryInterface(REFIID riid, LPVOID * ppvOut)
  38. {
  39. static const QITAB qit[] = {
  40. QITABENT(CDarwinEnumPublishedApps, IEnumPublishedApps), // IID_IEnumPublishedApps
  41. { 0 },
  42. };
  43. return QISearch(this, qit, riid, ppvOut);
  44. }
  45. // IEnumPublishedApps::AddRef
  46. ULONG CDarwinEnumPublishedApps::AddRef()
  47. {
  48. _cRef++;
  49. TraceMsg(TF_OBJLIFE, "CDarwinEnumPublishedApps()::AddRef called, new _cRef=%lX", _cRef);
  50. return _cRef;
  51. }
  52. // IEnumPublishedApps::Release
  53. ULONG CDarwinEnumPublishedApps::Release()
  54. {
  55. _cRef--;
  56. TraceMsg(TF_OBJLIFE, "CDarwinEnumPublishedApps()::Release called, new _cRef=%lX", _cRef);
  57. if (_cRef > 0)
  58. return _cRef;
  59. delete this;
  60. return 0;
  61. }
  62. // IEnumPublishedApps::Next
  63. // PERF: we should do some optimization instead of enumerating these apps
  64. // one by one.
  65. // S_FALSE means end of enumeration
  66. HRESULT CDarwinEnumPublishedApps::Next(IPublishedApp ** ppia)
  67. {
  68. HRESULT hres = S_FALSE;
  69. *ppia = NULL;
  70. if (_prgApps && (_dwNumApps > 0) && (_dwIndex < _dwNumApps))
  71. {
  72. BOOL bContinue = FALSE;
  73. do {
  74. PMANAGEDAPPLICATION pma = &_prgApps[_dwIndex];
  75. // NOTE: no Hydra machines (_bTSSession == TRUE) we filter out all the
  76. // Darwin apps.
  77. if (pma->pszPackageName && pma->pszPackageName[0])
  78. {
  79. CDarwinPublishedApp *pdpa = new CDarwinPublishedApp(pma);
  80. if (pdpa)
  81. {
  82. *ppia = SAFECAST(pdpa, IPublishedApp *);
  83. hres = S_OK;
  84. }
  85. else
  86. hres = E_OUTOFMEMORY;
  87. bContinue = FALSE;
  88. }
  89. else
  90. {
  91. ClearManagedApplication(pma);
  92. bContinue = TRUE;
  93. }
  94. _dwIndex++;
  95. } while (bContinue && (_dwIndex < _dwNumApps));
  96. }
  97. return hres;
  98. }
  99. // IEnumPublishedApps::Reset
  100. HRESULT CDarwinEnumPublishedApps::Reset(void)
  101. {
  102. if (_prgApps && (_dwNumApps > 0))
  103. {
  104. LocalFree(_prgApps);
  105. }
  106. GetManagedApplications(_bGuidUsed ? &_CategoryGUID : NULL, MANAGED_APPS_USERAPPLICATIONS,
  107. _bGuidUsed ? MANAGED_APPS_FROMCATEGORY : MANAGED_APPS_INFOLEVEL_DEFAULT, &_dwNumApps, &_prgApps);
  108. _dwIndex = 0;
  109. return S_OK;
  110. }