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.

133 lines
2.9 KiB

  1. /*
  2. File: enum.cpp
  3. Implementation of OneStop Enumerator
  4. Based on sample code from OneStop.
  5. */
  6. #include "pch.hxx"
  7. #include "syncenum.h"
  8. CEnumOfflineItems::CEnumOfflineItems(LPSYNCMGRHANDLERITEMS pOfflineItems, DWORD cOffset):
  9. m_cRef(1), m_pOfflineItems(pOfflineItems), m_cOffset(cOffset)
  10. {
  11. DWORD dwItemIndex;
  12. TraceCall("CEnumOfflineItems::CEnumOfflineItems()");
  13. OHIL_AddRef(m_pOfflineItems);
  14. // Set the current item to point to next record.
  15. m_pNextItem = m_pOfflineItems->pFirstOfflineItem;
  16. dwItemIndex = cOffset;
  17. Assert(dwItemIndex <= m_pOfflineItems->dwNumOfflineItems);
  18. while(dwItemIndex--)
  19. {
  20. m_pNextItem = m_pNextItem->pNextOfflineItem;
  21. ++m_cOffset;
  22. }
  23. }
  24. CEnumOfflineItems::~CEnumOfflineItems()
  25. {
  26. OHIL_Release(m_pOfflineItems);
  27. }
  28. STDMETHODIMP CEnumOfflineItems::QueryInterface(REFIID riid, LPVOID FAR *ppvObj)
  29. {
  30. TraceCall("CEnumOfflineItems::QueryInterface");
  31. if(!ppvObj)
  32. return E_INVALIDARG;
  33. *ppvObj = NULL;
  34. if (IsEqualIID(riid, IID_IUnknown))
  35. *ppvObj = SAFECAST(this, IUnknown *);
  36. else if (IsEqualIID(riid, IID_ISyncMgrEnumItems))
  37. *ppvObj = SAFECAST(this, ISyncMgrEnumItems *);
  38. else
  39. return E_NOINTERFACE;
  40. InterlockedIncrement(&m_cRef);
  41. return NOERROR;
  42. }
  43. STDMETHODIMP_(ULONG) CEnumOfflineItems::AddRef()
  44. {
  45. TraceCall("CEnumOfflineItems::AddRef");
  46. return InterlockedIncrement(&m_cRef);
  47. }
  48. STDMETHODIMP_(ULONG) CEnumOfflineItems::Release()
  49. {
  50. TraceCall("CEnumOfflineItems::Release");
  51. LONG cRef = InterlockedDecrement(&m_cRef);
  52. if (cRef > 0)
  53. return (ULONG)cRef;
  54. // OHIL released in destructor
  55. delete this;
  56. return 0;
  57. }
  58. STDMETHODIMP CEnumOfflineItems::Next(ULONG celt, LPSYNCMGRITEM rgelt,ULONG *pceltFetched)
  59. {
  60. HRESULT hr = NOERROR;
  61. ULONG ulFetchCount = celt;
  62. LPSYNCMGRITEM pOfflineItem;
  63. if ( (m_cOffset + celt) > m_pOfflineItems->dwNumOfflineItems)
  64. {
  65. ulFetchCount = m_pOfflineItems->dwNumOfflineItems - m_cOffset;
  66. hr = S_FALSE;
  67. }
  68. pOfflineItem = rgelt;
  69. while (ulFetchCount--)
  70. {
  71. *pOfflineItem = m_pNextItem->offlineItem;
  72. m_pNextItem = m_pNextItem->pNextOfflineItem;
  73. ++m_cOffset;
  74. ++pOfflineItem;
  75. }
  76. return hr;
  77. }
  78. STDMETHODIMP CEnumOfflineItems::Skip(ULONG celt)
  79. {
  80. HRESULT hr;
  81. if ( (m_cOffset + celt) > m_pOfflineItems->dwNumOfflineItems)
  82. {
  83. m_cOffset = m_pOfflineItems->dwNumOfflineItems;
  84. m_pNextItem = NULL;
  85. hr = S_FALSE;
  86. }
  87. else
  88. {
  89. while (celt--)
  90. {
  91. ++m_cOffset;
  92. m_pNextItem = m_pNextItem->pNextOfflineItem;
  93. }
  94. hr = NOERROR;
  95. }
  96. return hr;
  97. }
  98. STDMETHODIMP CEnumOfflineItems::Reset()
  99. {
  100. m_pNextItem = m_pOfflineItems->pFirstOfflineItem;
  101. return NOERROR;
  102. }
  103. STDMETHODIMP CEnumOfflineItems::Clone(ISyncMgrEnumItems **ppenum)
  104. {
  105. *ppenum = new CEnumOfflineItems(m_pOfflineItems,m_cOffset);
  106. return *ppenum ? NOERROR : E_OUTOFMEMORY;
  107. }