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.

149 lines
3.0 KiB

  1. //
  2. // enumguid.cpp
  3. //
  4. #include "private.h"
  5. #include "globals.h"
  6. #include "enumguid.h"
  7. DBG_ID_INSTANCE(CEnumGuid);
  8. //////////////////////////////////////////////////////////////////////////////
  9. //
  10. // CEnumGuid
  11. //
  12. //////////////////////////////////////////////////////////////////////////////
  13. //+---------------------------------------------------------------------------
  14. //
  15. // ctor
  16. //
  17. //----------------------------------------------------------------------------
  18. CEnumGuid::CEnumGuid()
  19. {
  20. Dbg_MemSetThisNameID(TEXT("CEnumGuid"));
  21. Assert(_nCur == 0);
  22. Assert(_pga == 0);
  23. }
  24. //+---------------------------------------------------------------------------
  25. //
  26. // dtor
  27. //
  28. //----------------------------------------------------------------------------
  29. CEnumGuid::~CEnumGuid()
  30. {
  31. CicEnterCriticalSection(g_cs);
  32. SGA_Release(_pga);
  33. CicLeaveCriticalSection(g_cs);
  34. }
  35. //+---------------------------------------------------------------------------
  36. //
  37. // Clone
  38. //
  39. //----------------------------------------------------------------------------
  40. STDAPI CEnumGuid::Clone(IEnumGUID **ppClone)
  41. {
  42. CEnumGuid *pClone;
  43. HRESULT hr = E_FAIL;
  44. if (ppClone == NULL)
  45. return E_INVALIDARG;
  46. CicEnterCriticalSection(g_cs);
  47. *ppClone = NULL;
  48. if ((pClone = new CEnumGuid) == NULL)
  49. {
  50. hr = E_OUTOFMEMORY;
  51. goto Exit;
  52. }
  53. pClone->_nCur = _nCur;
  54. pClone->_pga = _pga;
  55. SGA_AddRef(pClone->_pga);
  56. *ppClone = pClone;
  57. CicLeaveCriticalSection(g_cs);
  58. hr = S_OK;
  59. Exit:
  60. return S_OK;
  61. }
  62. //+---------------------------------------------------------------------------
  63. //
  64. // Next
  65. //
  66. //----------------------------------------------------------------------------
  67. STDAPI CEnumGuid::Next(ULONG ulCount, GUID *pguid, ULONG *pcFetched)
  68. {
  69. ULONG cFetched = 0;
  70. Assert(pguid);
  71. CicEnterCriticalSection(g_cs);
  72. while (cFetched < ulCount)
  73. {
  74. if ((ULONG)_nCur >= _pga->cGuid)
  75. break;
  76. *pguid = _pga->rgGuid[_nCur];
  77. _nCur++;
  78. pguid++;
  79. cFetched++;
  80. }
  81. CicLeaveCriticalSection(g_cs);
  82. if (pcFetched)
  83. *pcFetched = cFetched;
  84. return (cFetched == ulCount) ? S_OK : S_FALSE;
  85. }
  86. //+---------------------------------------------------------------------------
  87. //
  88. // Reset
  89. //
  90. //----------------------------------------------------------------------------
  91. STDAPI CEnumGuid::Reset()
  92. {
  93. _nCur = 0;
  94. return S_OK;
  95. }
  96. //+---------------------------------------------------------------------------
  97. //
  98. // Skip
  99. //
  100. //----------------------------------------------------------------------------
  101. STDAPI CEnumGuid::Skip(ULONG ulCount)
  102. {
  103. HRESULT hr = S_OK;
  104. _nCur += ulCount;
  105. CicEnterCriticalSection(g_cs);
  106. if ((ULONG)_nCur >= _pga->cGuid)
  107. {
  108. _nCur = _pga->cGuid; // prevent overflow for repeated calls
  109. hr = S_FALSE;
  110. }
  111. CicLeaveCriticalSection(g_cs);
  112. return hr;
  113. }