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.

167 lines
3.4 KiB

  1. /******************************************************************************
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. MPCUploadEnum.cpp
  5. Abstract:
  6. This file contains the implementation of the MPCUploadEnum class,
  7. the enumerator of the MPCUpload class.
  8. Revision History:
  9. Davide Massarenti (Dmassare) 04/15/99
  10. created
  11. ******************************************************************************/
  12. #include "stdafx.h"
  13. CMPCUploadEnum::CMPCUploadEnum()
  14. {
  15. __ULT_FUNC_ENTRY( "CMPCUploadEnum::CMPCUploadEnum" );
  16. // List m_lstJobs
  17. m_itCurrent = m_lstJobs.begin(); // Iter m_itCurrent
  18. }
  19. void CMPCUploadEnum::FinalRelease()
  20. {
  21. __ULT_FUNC_ENTRY( "CMPCUploadEnum::FinalRelease" );
  22. MPC::ReleaseAll( m_lstJobs );
  23. }
  24. HRESULT CMPCUploadEnum::AddItem( /*[in]*/ IMPCUploadJob* job )
  25. {
  26. __ULT_FUNC_ENTRY( "CMPCUploadEnum::Init" );
  27. MPC::SmartLock<_ThreadModel> lock( this );
  28. m_lstJobs.push_back( job ); job->AddRef();
  29. m_itCurrent = m_lstJobs.begin();
  30. __ULT_FUNC_EXIT(S_OK);
  31. }
  32. STDMETHODIMP CMPCUploadEnum::Next( /*[in]*/ ULONG celt, /*[out]*/ VARIANT *rgelt, /*[out]*/ ULONG *pceltFetched )
  33. {
  34. __ULT_FUNC_ENTRY( "CMPCUploadEnum::Next" );
  35. HRESULT hr;
  36. ULONG cNum = 0;
  37. VARIANT *pelt = rgelt;
  38. MPC::SmartLock<_ThreadModel> lock( this );
  39. if(rgelt == NULL || (celt != 1 && pceltFetched == NULL))
  40. {
  41. __MPC_SET_ERROR_AND_EXIT(hr, E_POINTER);
  42. }
  43. while(celt && m_itCurrent != m_lstJobs.end())
  44. {
  45. IMPCUploadJob* mpcujJob = *m_itCurrent++;
  46. pelt->vt = VT_DISPATCH;
  47. if(FAILED(hr = mpcujJob->QueryInterface( IID_IDispatch, (void**)&pelt->pdispVal )))
  48. {
  49. while(rgelt < pelt)
  50. {
  51. ::VariantClear( rgelt++ );
  52. }
  53. cNum = 0;
  54. __MPC_FUNC_LEAVE;
  55. }
  56. pelt++; cNum++; celt--;
  57. }
  58. hr = S_OK;
  59. __ULT_FUNC_CLEANUP;
  60. if(pceltFetched != NULL) *pceltFetched = cNum;
  61. if(SUCCEEDED(hr))
  62. {
  63. if(celt != 0) hr = S_FALSE;
  64. }
  65. __ULT_FUNC_EXIT(hr);
  66. }
  67. STDMETHODIMP CMPCUploadEnum::Skip( /*[in]*/ ULONG celt )
  68. {
  69. __ULT_FUNC_ENTRY( "CMPCUploadEnum::Skip" );
  70. HRESULT hr;
  71. MPC::SmartLock<_ThreadModel> lock( this );
  72. while(celt && m_itCurrent != m_lstJobs.end())
  73. {
  74. m_itCurrent++;
  75. celt--;
  76. }
  77. hr = celt ? S_FALSE : S_OK;
  78. __ULT_FUNC_EXIT(hr);
  79. }
  80. STDMETHODIMP CMPCUploadEnum::Reset()
  81. {
  82. __ULT_FUNC_ENTRY( "CMPCUploadEnum::Reset" );
  83. HRESULT hr;
  84. MPC::SmartLock<_ThreadModel> lock( this );
  85. m_itCurrent = m_lstJobs.begin();
  86. hr = S_OK;
  87. __ULT_FUNC_EXIT(hr);
  88. }
  89. STDMETHODIMP CMPCUploadEnum::Clone( /*[out]*/ IEnumVARIANT* *ppEnum )
  90. {
  91. __ULT_FUNC_ENTRY( "CMPCUploadEnum::Clone" );
  92. HRESULT hr;
  93. Iter it;
  94. CComPtr<CMPCUploadEnum> pEnum;
  95. MPC::SmartLock<_ThreadModel> lock( this );
  96. __MPC_PARAMCHECK_BEGIN(hr)
  97. __MPC_PARAMCHECK_POINTER_AND_SET(ppEnum,NULL);
  98. __MPC_PARAMCHECK_END();
  99. __MPC_EXIT_IF_METHOD_FAILS(hr, MPC::CreateInstance( &pEnum ));
  100. for(it = m_lstJobs.begin(); it != m_lstJobs.end(); it++)
  101. {
  102. __MPC_EXIT_IF_METHOD_FAILS(hr, pEnum->AddItem( *it ));
  103. }
  104. __MPC_EXIT_IF_METHOD_FAILS(hr, pEnum->QueryInterface( IID_IEnumVARIANT, (void**)ppEnum ));
  105. hr = S_OK;
  106. __ULT_FUNC_CLEANUP;
  107. __ULT_FUNC_EXIT(hr);
  108. }