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.

187 lines
7.4 KiB

  1. /*++
  2. Copyright (C) 1999- Microsoft Corporation
  3. Module Name:
  4. camera.h
  5. Abstract:
  6. This module declares CPTPCamera class
  7. Author:
  8. William Hsieh (williamh) created
  9. Revision History:
  10. --*/
  11. #ifndef CAMERA__H_
  12. #define CAMERA__H_
  13. //
  14. // Reserve 8KB of memory as a re-usable transaction buffer
  15. //
  16. const UINT TRANSFER_BUFFER_SIZE = 0x2000;
  17. //
  18. // Hack models
  19. //
  20. typedef enum tagHackModel
  21. {
  22. HACK_MODEL_NONE = 0,
  23. HACK_MODEL_DC4800,
  24. HACK_MODEL_NIKON_E2500,
  25. //
  26. // Right now, Sony cameras do not provide model in DeviceInfo. m_HackVersion is used to
  27. // differentiate newer and older firmware of Sony cameras
  28. //
  29. HACK_MODEL_SONY
  30. } HACK_MODEL;
  31. //
  32. // Camera is always in one of these phases. Constants are fixed and documented in DDK, see ptpusd.h
  33. //
  34. typedef enum tagCameraPhase
  35. {
  36. CAMERA_PHASE_NOTREADY,
  37. CAMERA_PHASE_IDLE,
  38. CAMERA_PHASE_CMD,
  39. CAMERA_PHASE_DATAIN,
  40. CAMERA_PHASE_DATAOUT,
  41. CAMERA_PHASE_RESPONSE
  42. }CAMERA_PHASE, *PCAMERA_PHASE;
  43. //
  44. // Definition for function to call when event occurs
  45. //
  46. typedef HRESULT (*PTPEventCallback)(LPVOID pCallbackParam, PPTP_EVENT pEvent);
  47. //
  48. // Definition for function to call while data is transferred
  49. //
  50. typedef HRESULT (*PTPDataCallback)(LPVOID pCallbackParam, LONG lPercentComplete,
  51. LONG lOffset, LONG lLength, BYTE **ppBuffer, LONG *plBufferSize);
  52. //
  53. // CPTPCamera - generic PTP camera
  54. //
  55. class CPTPCamera
  56. {
  57. public:
  58. CPTPCamera();
  59. virtual ~CPTPCamera();
  60. virtual HRESULT Open(LPWSTR DevicePortName, PTPEventCallback pPTPEventCB,
  61. PTPDataCallback pPTPDataCB, LPVOID pEventParam, BOOL bEnableEvents = TRUE);
  62. virtual HRESULT Close();
  63. HRESULT GetDeviceInfo(CPtpDeviceInfo *pDeviceInfo);
  64. HRESULT OpenSession(DWORD SessionId);
  65. HRESULT CloseSession();
  66. HRESULT GetStorageIDs(CArray32 *pStorageIds);
  67. HRESULT GetStorageInfo(DWORD StorageId, CPtpStorageInfo *pStorageInfo);
  68. HRESULT GetNumObjects(DWORD StorageId, WORD FormatCode,
  69. DWORD ParentObjectHandle, UINT *pNumObjects);
  70. HRESULT GetObjectHandles(DWORD StorageId, WORD FormatCode,
  71. DWORD ParentObjectHandle, CArray32 *pObjectHandles);
  72. HRESULT GetObjectInfo(DWORD ObjectHandle, CPtpObjectInfo *pObjectInfo);
  73. HRESULT GetObjectData(DWORD ObjectHandle, BYTE *pBuffer, UINT *pBufferLen, LPVOID pCallbackParam);
  74. HRESULT GetThumb(DWORD ObjectHandle, BYTE *pBuffer, UINT *pBufferLen);
  75. HRESULT DeleteObject(DWORD ObjectHandle, WORD FormatCode);
  76. HRESULT SendObjectInfo(DWORD StorageId, DWORD ParentObjectHandle, CPtpObjectInfo *pObjectInfo,
  77. DWORD *pResultStorageId, DWORD *pResultParentObjectHandle, DWORD *pResultObjectHandle);
  78. HRESULT SendObjectData(BYTE *pBuffer, UINT BufferLen);
  79. HRESULT InitiateCapture(DWORD StorageId, WORD FormatCode);
  80. HRESULT FormatStore(DWORD StorageId, WORD FilesystemFormat);
  81. HRESULT ResetDevice();
  82. HRESULT SelfTest(WORD SelfTestType);
  83. HRESULT SetObjectProtection(DWORD ObjectHandle, WORD ProtectionStatus);
  84. HRESULT PowerDown();
  85. HRESULT GetDevicePropDesc(WORD PropCode, CPtpPropDesc *pPropDesc);
  86. HRESULT GetDevicePropValue(WORD PropCode, CPtpPropDesc *pPropDesc);
  87. HRESULT SetDevicePropValue(WORD PropCode, CPtpPropDesc *pPropDesc);
  88. HRESULT ResetDevicePropValue(WORD PropCode);
  89. HRESULT TerminateCapture(DWORD TransactionId);
  90. HRESULT MoveObject(DWORD ObjectHandle, DWORD StorageId, DWORD ParentObjectHandle);
  91. HRESULT CopyObject(DWORD ObjectHandle, DWORD StorageId, DWORD ParentObjectHandle, DWORD *pResultObjectHandle);
  92. HRESULT GetPartialObject(DWORD ObjectHandle, UINT Offset, UINT *pLength, BYTE *pBuffer,
  93. UINT *pResultLength, LPVOID pCallbackParam);
  94. HRESULT InitiateOpenCapture(DWORD StorageId, WORD FormatCode);
  95. HRESULT VendorCommand(PTP_COMMAND *pCommand, PTP_RESPONSE *pResponse,
  96. UINT *pReadDataSize, BYTE *pReadData,
  97. UINT WriteDataSize, BYTE *pWriteData,
  98. UINT NumCommandParams, int NextPhase);
  99. //
  100. // Camera state functions
  101. //
  102. BOOL IsCameraOpen() { return m_Phase != CAMERA_PHASE_NOTREADY; }
  103. BOOL IsCameraSessionOpen() { return m_SessionId != PTP_SESSIONID_NOSESSION; }
  104. PBOOL CameraWasReset() { return &m_bCameraWasReset; }
  105. //
  106. // Model identification for model-specific handling
  107. //
  108. HRESULT SetupHackInfo(CPtpDeviceInfo *pDeviceInfo);
  109. HACK_MODEL GetHackModel() { return m_HackModel; }
  110. double GetHackVersion() { return m_HackVersion; }
  111. //
  112. // Member access functions (for the event thread)
  113. //
  114. PPTP_EVENT GetEventBuffer() { return &m_EventBuffer; }
  115. PTPEventCallback GetPTPEventCallback() { return m_pPTPEventCB; }
  116. LPVOID GetEventCallbackParam() { return m_pEventCallbackParam; }
  117. //
  118. // This function must be overriden by a transport-specific subclass
  119. //
  120. virtual HRESULT ReadEvent(PTP_EVENT *pEvent) = 0;
  121. virtual HRESULT RecoverFromError() = 0;
  122. protected:
  123. //
  124. // These functions must be overriden by a transport-specific subclass
  125. //
  126. virtual HRESULT SendCommand(PTP_COMMAND *pCommand, UINT NumParams) = 0;
  127. virtual HRESULT ReadData(BYTE *pData, UINT *pBufferSize) = 0;
  128. virtual HRESULT SendData(BYTE *pData, UINT BufferSize) = 0;
  129. virtual HRESULT ReadResponse(PTP_RESPONSE *pResponse) = 0;
  130. virtual HRESULT AbortTransfer() = 0;
  131. virtual HRESULT SendResetDevice() = 0;
  132. //
  133. // Member variables
  134. //
  135. HANDLE m_hEventThread; // Event thread handle
  136. DWORD m_SessionId; // Current session ID
  137. CAMERA_PHASE m_Phase; // Current camera phase
  138. DWORD m_NextTransactionId; // Next transaction ID
  139. PTPEventCallback m_pPTPEventCB; // Event callback function pointer
  140. PTPDataCallback m_pPTPDataCB; // Data callback function pointer
  141. LPVOID m_pEventCallbackParam; // Pointer to pass to event callback functions
  142. LPVOID m_pDataCallbackParam; // Pointer to pass to data callback functions
  143. BOOL m_bEventsEnabled; // GetDeviceInfo is used to query camera for its name. We don't want to start up entire eventing just for this.
  144. BOOL m_bCameraWasReset; // Device was successfully reset, WIA server was not notified about that yet
  145. HACK_MODEL m_HackModel; // Indicator for model-specific hacks
  146. double m_HackVersion; // Indicator for model and version specific hacks
  147. private:
  148. HRESULT ExecuteCommand(BYTE *pReadData, UINT *pReadDataSize, BYTE *pWriteData, UINT WriteDataSize,
  149. UINT NumCommandParams, CAMERA_PHASE NextPhase);
  150. DWORD GetNextTransactionId();
  151. BYTE *m_pTransferBuffer; // Re-usable buffer for small transfers
  152. PTP_COMMAND m_CommandBuffer; // Re-usable buffer for commands
  153. PTP_RESPONSE m_ResponseBuffer; // Re-usable buffer for responses
  154. PTP_EVENT m_EventBuffer; // Re-usable buffer for events
  155. };
  156. #endif // CAMERA__H_