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.

179 lines
3.2 KiB

  1. #include "precomp.h"
  2. #include "NmChannel.h"
  3. #include "NmChannelFt.h"
  4. #include "NmFt.h"
  5. //static
  6. HRESULT CNmFtObj::CreateInstance(
  7. CNmChannelFtObj* pChannelObj,
  8. MBFTEVENTHANDLE hFileEvent,
  9. MBFTFILEHANDLE hFile,
  10. bool bIncoming,
  11. LPCTSTR szFileName,
  12. DWORD dwSizeInBytes,
  13. INmMember* pSDKMember,
  14. INmFt** ppNmFt)
  15. {
  16. DBGENTRY(CNmFtObj::CreateInstance);
  17. HRESULT hr = S_OK;
  18. CComObject<CNmFtObj>* p = NULL;
  19. p = new CComObject<CNmFtObj>(NULL);
  20. if(p)
  21. {
  22. p->SetVoid(NULL);
  23. if(hr == S_OK)
  24. {
  25. hr = p->QueryInterface(IID_INmFt, reinterpret_cast<void**>(ppNmFt));
  26. if(SUCCEEDED(hr))
  27. {
  28. p->m_pChannelFtObj = pChannelObj;
  29. p->m_hFileEvent = hFileEvent;
  30. p->m_hFile = hFile;
  31. p->m_bIncoming = bIncoming;
  32. p->m_strFileName = szFileName;
  33. p->m_dwSizeInBytes = dwSizeInBytes;
  34. p->m_spSDKMember = pSDKMember;
  35. p->m_State = bIncoming ? NM_FT_RECEIVING : NM_FT_SENDING;
  36. p->m_dwBytesTransferred = 0;
  37. p->m_bSomeoneCanceled = false;
  38. }
  39. }
  40. if(FAILED(hr))
  41. {
  42. delete p;
  43. *ppNmFt = NULL;
  44. }
  45. }
  46. else
  47. {
  48. hr = E_OUTOFMEMORY;
  49. }
  50. DBGEXIT_HR(CNmFtObj::CreateInstance,hr);
  51. return hr;
  52. }
  53. ////////////////////////////////////////////////
  54. // INmFt interface
  55. STDMETHODIMP CNmFtObj::IsIncoming(void)
  56. {
  57. DBGENTRY(CNmFtObj::IsIncoming);
  58. HRESULT hr = m_bIncoming ? S_OK : S_FALSE;
  59. DBGEXIT_HR(CNmFtObj::IsIncoming,hr);
  60. return hr;
  61. }
  62. STDMETHODIMP CNmFtObj::GetState(NM_FT_STATE *puState)
  63. {
  64. DBGENTRY(CNmFtObj::GetState);
  65. HRESULT hr = S_OK;
  66. *puState = m_State;
  67. DBGEXIT_HR(CNmFtObj::GetState,hr);
  68. return hr;
  69. }
  70. STDMETHODIMP CNmFtObj::GetName(BSTR *pbstrName)
  71. {
  72. DBGENTRY(CNmFtObj::GetName);
  73. HRESULT hr = S_OK;
  74. *pbstrName = m_strFileName.Copy();
  75. DBGEXIT_HR(CNmFtObj::GetName,hr);
  76. return hr;
  77. }
  78. STDMETHODIMP CNmFtObj::GetSize(ULONG *puBytes)
  79. {
  80. DBGENTRY(CNmFtObj::GetSize);
  81. HRESULT hr = S_OK;
  82. *puBytes = m_dwSizeInBytes;
  83. DBGEXIT_HR(CNmFtObj::GetSize,hr);
  84. return hr;
  85. }
  86. STDMETHODIMP CNmFtObj::GetBytesTransferred(ULONG *puBytes)
  87. {
  88. DBGENTRY(CNmFtObj::GetBytesTransferred);
  89. HRESULT hr = S_OK;
  90. *puBytes = m_dwBytesTransferred;
  91. DBGEXIT_HR(CNmFtObj::GetBytesTransferred,hr);
  92. return hr;
  93. }
  94. STDMETHODIMP CNmFtObj::GetMember(INmMember **ppMember)
  95. {
  96. DBGENTRY(CNmFtObj::GetMember);
  97. HRESULT hr = S_OK;
  98. *ppMember = m_spSDKMember;
  99. if(*ppMember)
  100. {
  101. (*ppMember)->AddRef();
  102. }
  103. DBGEXIT_HR(CNmFtObj::GetMember,hr);
  104. return hr;
  105. }
  106. STDMETHODIMP CNmFtObj::Cancel(void)
  107. {
  108. if((NM_FT_INVALID == m_State) || (NM_FT_COMPLETE == m_State))
  109. {
  110. return E_FAIL;
  111. }
  112. return CFt::CancelFt(m_hFileEvent, m_hFile);
  113. }
  114. ////////////////////////////////////////////////
  115. // IInternalFtObj interface
  116. STDMETHODIMP CNmFtObj::GetHEvent(UINT *phEvent)
  117. {
  118. ASSERT(phEvent);
  119. *phEvent = m_hFileEvent;
  120. return S_OK;
  121. }
  122. STDMETHODIMP CNmFtObj::OnFileProgress(UINT hFile, ULONG lFileSize, ULONG lBytesTransmitted)
  123. {
  124. m_hFile = hFile;
  125. m_dwBytesTransferred = lBytesTransmitted;
  126. return S_OK;
  127. }
  128. STDMETHODIMP CNmFtObj::FileTransferDone()
  129. {
  130. m_dwBytesTransferred = m_dwSizeInBytes;
  131. m_State = NM_FT_COMPLETE;
  132. // Return S_FALSE if someone canceled
  133. return m_bSomeoneCanceled ? S_FALSE : S_OK;
  134. }
  135. STDMETHODIMP CNmFtObj::OnError()
  136. {
  137. m_bSomeoneCanceled = true;
  138. return S_OK;
  139. }