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.

278 lines
5.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. DataCallback.cpp
  5. Abstract:
  6. WIA data callback class
  7. Author:
  8. Hakki T. Bostanci (hakkib) 06-Apr-2000
  9. Revision History:
  10. --*/
  11. #include "StdAfx.h"
  12. #include "WiaStress.h"
  13. #include "DataCallback.h"
  14. #include "ToStr.h"
  15. //////////////////////////////////////////////////////////////////////////
  16. //
  17. //
  18. //
  19. CDataCallback::CDataCallback()
  20. {
  21. m_cRef = 0;
  22. m_pBuffer = 0;
  23. m_lBufferSize = 0;
  24. m_TimeDeviceBegin.QuadPart = 0;
  25. m_TimeDeviceEnd.QuadPart = 0;
  26. m_TimeProcessBegin.QuadPart = 0;
  27. m_TimeProcessEnd.QuadPart = 0;
  28. m_TimeClientBegin.QuadPart = 0;
  29. m_TimeClientEnd.QuadPart = 0;
  30. }
  31. //////////////////////////////////////////////////////////////////////////
  32. //
  33. //
  34. //
  35. CDataCallback::~CDataCallback()
  36. {
  37. PrintTimes();
  38. delete [] m_pBuffer;
  39. }
  40. //////////////////////////////////////////////////////////////////////////
  41. //
  42. //
  43. //
  44. STDMETHODIMP CDataCallback::QueryInterface(REFIID iid, LPVOID *ppvObj)
  45. {
  46. if (ppvObj == 0)
  47. {
  48. return E_POINTER;
  49. }
  50. if (iid == IID_IUnknown)
  51. {
  52. AddRef();
  53. *ppvObj = (IUnknown*) this;
  54. return S_OK;
  55. }
  56. if (iid == IID_IWiaDataCallback)
  57. {
  58. AddRef();
  59. *ppvObj = (IWiaDataCallback *) this;
  60. return S_OK;
  61. }
  62. *ppvObj = 0;
  63. return E_NOINTERFACE;
  64. }
  65. //////////////////////////////////////////////////////////////////////////
  66. //
  67. //
  68. //
  69. STDMETHODIMP_(ULONG) CDataCallback::AddRef()
  70. {
  71. return InterlockedIncrement(&m_cRef);
  72. }
  73. //////////////////////////////////////////////////////////////////////////
  74. //
  75. //
  76. //
  77. STDMETHODIMP_(ULONG) CDataCallback::Release()
  78. {
  79. LONG cRef = InterlockedDecrement(&m_cRef);
  80. if (cRef == 0)
  81. {
  82. delete this;
  83. }
  84. return cRef;
  85. }
  86. //////////////////////////////////////////////////////////////////////////
  87. //
  88. //
  89. //
  90. STDMETHODIMP
  91. CDataCallback::BandedDataCallback(
  92. LONG lReason,
  93. LONG lStatus,
  94. LONG lPercentComplete,
  95. LONG lOffset,
  96. LONG lLength,
  97. LONG lReserved,
  98. LONG lResLength,
  99. PBYTE pbBuffer
  100. )
  101. {
  102. OutputDebugStringF(
  103. _T("DataCallback: Reason=%s Stat=%s %d%% Offset=%d Length=%d (%dK) Buf=%p\n"),
  104. (PCTSTR) WiaCallbackReasonToStr(lReason),
  105. (PCTSTR) WiaCallbackStatusToStr(lStatus),
  106. lPercentComplete,
  107. lOffset,
  108. lLength,
  109. lLength / 1024,
  110. pbBuffer
  111. );
  112. switch (lReason)
  113. {
  114. case IT_MSG_DATA_HEADER:
  115. {
  116. // allocate memory for the image
  117. PWIA_DATA_CALLBACK_HEADER pHeader = (PWIA_DATA_CALLBACK_HEADER) pbBuffer;
  118. m_lBufferSize = pHeader->lBufferSize;
  119. ASSERT(m_pBuffer == 0); //bugbug
  120. m_pBuffer = new BYTE[m_lBufferSize];
  121. if (m_pBuffer == 0)
  122. {
  123. return S_FALSE;
  124. }
  125. break;
  126. }
  127. case IT_MSG_DATA:
  128. {
  129. // copy the transfer buffer
  130. QueryStartTimes(lStatus, lPercentComplete);
  131. if (pbBuffer != 0 && lOffset + lLength <= m_lBufferSize)
  132. {
  133. CopyMemory(m_pBuffer + lOffset, pbBuffer, lLength);
  134. }
  135. else
  136. {
  137. }
  138. QueryStopTimes(lStatus, lPercentComplete);
  139. break;
  140. }
  141. case IT_MSG_STATUS:
  142. {
  143. QueryStartTimes(lStatus, lPercentComplete);
  144. QueryStopTimes(lStatus, lPercentComplete);
  145. break;
  146. }
  147. case IT_MSG_TERMINATION:
  148. break;
  149. case IT_MSG_NEW_PAGE:
  150. break;
  151. default:
  152. break;
  153. }
  154. return S_OK;
  155. }
  156. //////////////////////////////////////////////////////////////////////////
  157. //
  158. //
  159. //
  160. void CDataCallback::QueryStartTimes(LONG lStatus, LONG lPercentComplete)
  161. {
  162. if (lStatus & IT_STATUS_TRANSFER_FROM_DEVICE &&
  163. (lPercentComplete == 0 || m_TimeDeviceBegin.QuadPart == 0))
  164. {
  165. QueryPerformanceCounter(&m_TimeDeviceBegin);
  166. }
  167. if (lStatus & IT_STATUS_PROCESSING_DATA &&
  168. (lPercentComplete == 0 || m_TimeProcessBegin.QuadPart == 0))
  169. {
  170. QueryPerformanceCounter(&m_TimeProcessBegin);
  171. }
  172. if (lStatus & IT_STATUS_TRANSFER_TO_CLIENT &&
  173. (lPercentComplete == 0 || m_TimeClientBegin.QuadPart == 0))
  174. {
  175. QueryPerformanceCounter(&m_TimeClientBegin);
  176. }
  177. }
  178. void CDataCallback::QueryStopTimes(LONG lStatus, LONG lPercentComplete)
  179. {
  180. if (lStatus & IT_STATUS_TRANSFER_FROM_DEVICE && lPercentComplete == 100)
  181. {
  182. QueryPerformanceCounter(&m_TimeDeviceEnd);
  183. }
  184. if (lStatus & IT_STATUS_PROCESSING_DATA && lPercentComplete == 100)
  185. {
  186. QueryPerformanceCounter(&m_TimeProcessEnd);
  187. }
  188. if (lStatus & IT_STATUS_TRANSFER_TO_CLIENT && lPercentComplete == 100)
  189. {
  190. QueryPerformanceCounter(&m_TimeClientEnd);
  191. }
  192. }
  193. void CDataCallback::PrintTimes()
  194. {
  195. LARGE_INTEGER Freq;
  196. QueryPerformanceFrequency(&Freq);
  197. double nTimeDevice =
  198. (double) (m_TimeDeviceEnd.QuadPart - m_TimeDeviceBegin.QuadPart) /
  199. (double) Freq.QuadPart;
  200. double nTimeProcess =
  201. (double) (m_TimeProcessEnd.QuadPart - m_TimeProcessBegin.QuadPart) /
  202. (double) Freq.QuadPart;
  203. double nTimeClient =
  204. (double) (m_TimeClientEnd.QuadPart - m_TimeClientBegin.QuadPart) /
  205. (double) Freq.QuadPart;
  206. OutputDebugStringF(
  207. _T("TRANSFER_FROM_DEVICE = %.02lf secs\n")
  208. _T("PROCESSING_DATA = %.02lf secs\n")
  209. _T("TRANSFER_TO_CLIENT = %.02lf secs\n")
  210. _T("\n"),
  211. nTimeDevice,
  212. nTimeProcess,
  213. nTimeClient
  214. );
  215. }