Source code of Windows XP (NT5)
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.

165 lines
3.5 KiB

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993-1996 Microsoft Corporation. All Rights Reserved.
  7. //
  8. //
  9. // Purpose: Implements the IEnumOfflineItems Interfaces for the OneStop Handler
  10. //#include "priv.h"
  11. #include "SyncHndl.h"
  12. extern HINSTANCE g_hmodThisDll; // Handle to this DLL itself.
  13. CEnumOfflineItems::CEnumOfflineItems(LPSYNCMGRHANDLERITEMS pOfflineItems,DWORD cOffset)
  14. {
  15. DWORD dwItemIndex;
  16. ODS("CEnumOfflineItems::CEnumOfflineItems()\r\n");
  17. m_cRef = 1; // give the intial reference
  18. m_pOfflineItems = pOfflineItems;
  19. m_cOffset = cOffset;
  20. AddRef_OfflineHandlerItemsList(m_pOfflineItems); // increment our hold on shared memory.
  21. // set the current item to point to next record.
  22. m_pNextItem = m_pOfflineItems->pFirstOfflineItem;
  23. dwItemIndex = cOffset;
  24. // this is a bug if this happens so assert in final.
  25. if (dwItemIndex > m_pOfflineItems->dwNumOfflineItems)
  26. dwItemIndex = 0;
  27. while(dwItemIndex--)
  28. {
  29. m_pNextItem = m_pNextItem->pNextOfflineItem;
  30. ++m_cOffset;
  31. if (NULL == m_pNextItem)
  32. break; // Again, another error.
  33. }
  34. }
  35. CEnumOfflineItems::~CEnumOfflineItems()
  36. {
  37. Release_OfflineHandlerItemsList(m_pOfflineItems); // decrement our hold on shared memory.
  38. }
  39. STDMETHODIMP CEnumOfflineItems::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  40. {
  41. *ppv = NULL;
  42. if (IsEqualIID(riid, IID_IUnknown))
  43. {
  44. ODS("CEnumOfflineItems::QueryInterface()==>IID_IUknown\r\n");
  45. *ppv = (LPUNKNOWN)this;
  46. }
  47. else if (IsEqualIID(riid, IID_ISyncMgrEnumItems))
  48. {
  49. ODS("CEnumOfflineItems::QueryInterface()==>IID_IEnumOfflineItems\r\n");
  50. *ppv = (LPSYNCMGRENUMITEMS) this;
  51. }
  52. if (*ppv)
  53. {
  54. AddRef();
  55. return NOERROR;
  56. }
  57. ODS("CEnumOfflineItems::QueryInterface()==>Unknown Interface!\r\n");
  58. return E_NOINTERFACE;
  59. }
  60. STDMETHODIMP_(ULONG) CEnumOfflineItems::AddRef()
  61. {
  62. ODS("CEnumOfflineItems::AddRef()\r\n");
  63. return ++m_cRef;
  64. }
  65. STDMETHODIMP_(ULONG) CEnumOfflineItems::Release()
  66. {
  67. ODS("CEnumOfflineItems::Release()\r\n");
  68. if (--m_cRef)
  69. return m_cRef;
  70. delete this;
  71. return 0L;
  72. }
  73. STDMETHODIMP CEnumOfflineItems::Next(ULONG celt, LPSYNCMGRITEM rgelt,ULONG *pceltFetched)
  74. {
  75. HRESULT hr = NOERROR;
  76. ULONG ulFetchCount = celt;
  77. LPSYNCMGRITEM pOfflineItem;
  78. if ( (m_cOffset + celt) > m_pOfflineItems->dwNumOfflineItems)
  79. {
  80. ulFetchCount = m_pOfflineItems->dwNumOfflineItems - m_cOffset;
  81. hr = S_FALSE;
  82. }
  83. pOfflineItem = rgelt;
  84. while (ulFetchCount--)
  85. {
  86. *pOfflineItem = m_pNextItem->offlineItem;
  87. m_pNextItem = m_pNextItem->pNextOfflineItem; // add error checking
  88. ++m_cOffset;
  89. ++pOfflineItem;
  90. }
  91. return hr;
  92. }
  93. STDMETHODIMP CEnumOfflineItems::Skip(ULONG celt)
  94. {
  95. HRESULT hr;
  96. if ( (m_cOffset + celt) > m_pOfflineItems->dwNumOfflineItems)
  97. {
  98. m_cOffset = m_pOfflineItems->dwNumOfflineItems;
  99. m_pNextItem = NULL;
  100. hr = S_FALSE;
  101. }
  102. else
  103. {
  104. while (celt--)
  105. {
  106. ++m_cOffset;
  107. m_pNextItem = m_pNextItem->pNextOfflineItem;
  108. // add error checking for NULL, etc.
  109. }
  110. hr = NOERROR;
  111. }
  112. return hr;
  113. }
  114. STDMETHODIMP CEnumOfflineItems::Reset()
  115. {
  116. m_pNextItem = m_pOfflineItems->pFirstOfflineItem;
  117. return NOERROR;
  118. }
  119. STDMETHODIMP CEnumOfflineItems::Clone(ISyncMgrEnumItems **ppenum)
  120. {
  121. *ppenum = new CEnumOfflineItems(m_pOfflineItems,m_cOffset);
  122. return *ppenum ? NOERROR : E_OUTOFMEMORY;
  123. }