//-----------------------------------------------------------------------------
#ifndef CaptureThreadH
#define CaptureThreadH CaptureThreadH
//-----------------------------------------------------------------------------
#include "DevData.h"
#include <deque>
#include <mvIMPACT_CPP/mvIMPACT_acquire.h>
#include <wx/thread.h>
#include <wx/string.h>

class wxEvtHandler;
class wxWindow;
struct RequestInfoData;

typedef std::deque<int> RequestContainer;

//------------------------------------------------------------------------------
class CaptureThread : public wxThread
//------------------------------------------------------------------------------
{
	static unsigned int						m_activeInstance;
	volatile bool							m_boLive;
	volatile bool							m_boRecord;
	volatile bool							m_boContinuousRecording;
	volatile bool							m_boForwardIncompleteFrames;
	mutable wxCriticalSection				m_critSect;
	mutable wxCriticalSection				m_critSectConfig;
	mutable int								m_currentRequest;
	int										m_discardedImages;
	static unsigned int						m_instanceCnt;
	unsigned int							m_instanceNr;
	wxString								m_lastErrorMessage;
	wxString								m_lastRequestResult;
	mutable int								m_nextPendingRequest;
	int										m_parentWindowID;
	mvIMPACT::acquire::Device*				m_pDev;
	mvIMPACT::acquire::FunctionInterface*	m_pFuncInterface;
	mvIMPACT::acquire::ImageRequestControl	m_ImageRequestControl;
	wxEvtHandler*							m_pParentWindowEventHandler;
	RequestContainer						m_recordedSequence;
	size_t									m_currentSequenceIndexToDisplay;
	size_t									m_currentCountToRecord;
	size_t									m_totalCountToRecord;
	size_t									m_SkippedImageCount;
	int										m_captureQueueDepth;
	int										m_currentlyActiveRequests;
	int										RequestImages( int* pFramesRequested = 0 );
	int										ExchangeLastSnapResult( int newResult ) const;
	void									FreeSequence( void );
	void									FreeLastRequestFromSequence( int& requestNotToUnlock );
	int										InternalSetLiveMode( bool boOn, bool boInformUserOnRecordStart = true );
	int										InternalSetRecordMode( bool boOn );
	void									UnlockRequest( int nr ) const;
	bool									CheckSequenceRestart( bool boInformUserOnRecordStart ) const;
protected:
	void*									Entry( void );
public:
	CaptureThread( mvIMPACT::acquire::FunctionInterface* pFuncInterface, mvIMPACT::acquire::Device* pDev, wxWindow* pParentWindow );
	~CaptureThread();
	mvIMPACT::acquire::TRequestResult		GetImageData( RequestData& requestData, bool boFillInfoVector, std::vector<wxString>& infoStrings ) const;
	int										GetLastSnapResult( void ) const;
	wxString								GetLastRequestResult( void ) const;
	int										SetLiveMode( bool boOn, bool boInformUserOnRecordStart = true );
	bool									GetLiveMode( void ) const { return m_boLive; }
	void									SetContinuousRecording( bool boContinuous );
	bool									GetContinuousRecording( void ) const { return m_boContinuousRecording; }
	void									SetCaptureQueueDepth( int queueDepth );
	int										GetCaptureQueueDepth( void ) const { return m_captureQueueDepth; }
	int										SetRecordMode( bool boOn );
	bool									GetRecordMode( void ) const { return m_boRecord; }
	void									SetRecordSequenceSize( size_t sequenceSize );
	size_t									GetRecordSequenceSize( void ) const { return m_totalCountToRecord; }
	void									SetActive( void );
	void									SetCaptureMode( bool boForwardIncompleteFrames );
	int										RequestSingle( bool boInformUserOnRecordStart );
	size_t									DisplaySequenceRequest( size_t nr = 0 );
	size_t									DisplaySequenceRequestNext( void );
	size_t									DisplaySequenceRequestPrev( void );
	int										RecordSequence( void );
	const RequestContainer&					GetRecordedSequence( void ) const { return m_recordedSequence; }
	size_t									GetCurrentSequenceIndex( void ) const { return m_currentSequenceIndexToDisplay; }
	size_t									GetSkippedImageCount( void ){ size_t res = m_SkippedImageCount; m_SkippedImageCount=0; return res; }
};

#endif // CaptureThreadH
