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.

162 lines
3.3 KiB

  1. // MDSPEnumDevice.cpp : Implementation of CMDSPEnumDevice
  2. #include "stdafx.h"
  3. #include "MsPMSP.h"
  4. #include "MdspDefs.h"
  5. #include "MDSPEnumDevice.h"
  6. #include "MDSPDevice.h"
  7. #include "loghelp.h"
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CMDSPEnumDevice
  10. CMDSPEnumDevice::CMDSPEnumDevice()
  11. {
  12. m_nCurOffset=0; // When reset Cursor=0, actual element starts from 1.
  13. char str[8]="c:";
  14. int i, cnt;
  15. for(i=g_dwStartDrive, cnt=0; i<MDSP_MAX_DRIVE_COUNT; i++)
  16. {
  17. str[0] = 'A' + i;
  18. if( UtilGetDriveType(str) == DRIVE_REMOVABLE )
  19. {
  20. m_cEnumDriveLetter[cnt]=str[0];
  21. cnt ++;
  22. }
  23. }
  24. m_nMaxDeviceCount = cnt;
  25. }
  26. STDMETHODIMP CMDSPEnumDevice::Next(ULONG celt, IMDSPDevice * * ppDevice, ULONG * pceltFetched)
  27. {
  28. HRESULT hr=S_FALSE;
  29. CFRg(g_pAppSCServer);
  30. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  31. {
  32. CORg(WMDM_E_NOTCERTIFIED);
  33. }
  34. CARg(ppDevice);
  35. CARg(pceltFetched);
  36. *pceltFetched = 0;
  37. *ppDevice = NULL;
  38. ULONG i;
  39. for(i=0; (i<celt)&&(m_nCurOffset<m_nMaxDeviceCount); i++)
  40. {
  41. CComObject<CMDSPDevice> *pObj;
  42. CHRg(CComObject<CMDSPDevice>::CreateInstance(&pObj));
  43. hr=pObj->QueryInterface(IID_IMDSPDevice, reinterpret_cast<void**>(&(ppDevice[i])));
  44. if( FAILED(hr) )
  45. {
  46. delete pObj;
  47. break;
  48. } else {
  49. *pceltFetched = (*pceltFetched) + 1;
  50. pObj->m_wcsName[0] = m_cEnumDriveLetter[m_nCurOffset];
  51. pObj->m_wcsName[1] = L':';
  52. pObj->m_wcsName[2] = NULL;
  53. m_nCurOffset ++;
  54. pObj->InitGlobalDeviceInfo();
  55. }
  56. }
  57. if( SUCCEEDED(hr) )
  58. {
  59. if( *pceltFetched == celt)
  60. hr=S_OK;
  61. else
  62. hr = S_FALSE;
  63. }
  64. Error:
  65. hrLogDWORD("IMSDPEnumDevice::Next returned 0x%08lx", hr, hr);
  66. return hr;
  67. }
  68. STDMETHODIMP CMDSPEnumDevice::Skip(ULONG celt, ULONG *pceltFetched)
  69. {
  70. HRESULT hr;
  71. CFRg(g_pAppSCServer);
  72. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  73. {
  74. CORg(WMDM_E_NOTCERTIFIED);
  75. }
  76. CARg(pceltFetched);
  77. if( celt <= m_nMaxDeviceCount-m_nCurOffset )
  78. {
  79. *pceltFetched = celt;
  80. m_nCurOffset += celt;
  81. hr = S_OK;
  82. } else {
  83. *pceltFetched = m_nMaxDeviceCount-m_nCurOffset;
  84. m_nCurOffset = m_nMaxDeviceCount;
  85. hr = S_FALSE;
  86. }
  87. Error:
  88. hrLogDWORD("IMSDPEnumDevice::Skip returned 0x%08lx", hr, hr);
  89. return hr;
  90. }
  91. STDMETHODIMP CMDSPEnumDevice::Reset()
  92. {
  93. HRESULT hr;
  94. CFRg(g_pAppSCServer);
  95. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  96. {
  97. CORg(WMDM_E_NOTCERTIFIED);
  98. }
  99. m_nCurOffset = 0;
  100. hr = S_OK;
  101. Error:
  102. hrLogDWORD("IMSDPEnumDevice::Reset returned 0x%08lx", hr, hr);
  103. return hr;
  104. }
  105. STDMETHODIMP CMDSPEnumDevice::Clone(IMDSPEnumDevice * * ppEnumDevice)
  106. {
  107. HRESULT hr;
  108. CFRg(g_pAppSCServer);
  109. if ( !(g_pAppSCServer->fIsAuthenticated()) )
  110. {
  111. CORg(WMDM_E_NOTCERTIFIED);
  112. }
  113. CARg(ppEnumDevice);
  114. CComObject<CMDSPEnumDevice> *pEnumObj;
  115. hr=CComObject<CMDSPEnumDevice>::CreateInstance(&pEnumObj);
  116. if( SUCCEEDED(hr) )
  117. {
  118. hr=pEnumObj->QueryInterface(IID_IMDSPEnumDevice, reinterpret_cast<void**>(ppEnumDevice));
  119. if( FAILED(hr) )
  120. delete pEnumObj;
  121. else { // set the new enumerator state to be same as current
  122. pEnumObj->m_nCurOffset = m_nCurOffset;
  123. }
  124. }
  125. Error:
  126. hrLogDWORD("IMSDPEnumDevice::Clone returned 0x%08lx", hr, hr);
  127. return hr;
  128. }