#pragma once
#include"pch.h"
#include <vector>
#include "AbstractFSController.h"

using namespace std;
using namespace ZZ_MISCDEF::ZZ_RUNPARAMS;

class CMainDataGrabber :public QObject
{
	Q_OBJECT
public:
	CMainDataGrabber(QObject* parent = nullptr);
	~CMainDataGrabber();

private:
	vector<CAbstractFSController *> m_pControlThread;
	vector<QThread* >               m_pqThreadHolder;

	int *m_piFlagCaptureThreadStatus_Signal;
	int *m_piFlagCaptureThreadStatus_Dark;

	int m_iTotalThreads;

	int m_iFlagIsCapturing;
	int m_iFlagIsCapturing_Signal;
	int m_iFlagIsCapturing_Dark;

	
	FSContext           m_struDeviceContext;
	LSContext           m_struLinearShutterContext;
	AcqPosSettings      m_struAcqPosSetting;
	AcqTimeSettings     m_struAcqTime;


	//QTimer *m_GrabTimer;
private:
	void Delay_MSec(ZZ_U16 usMS);
public:
	//Call this first
	int SetGrabberParams(RunTimeGrabberParams struGrabberRTParams);

	int InitThreadStatus();
	int InitializeWorkers();
	int StartWorkers();
	int SetupMsgPipelines();

	int StartGrab();

public slots:
	int StartGrabTimer();
	//int OnTimeCounter();

	int HandleThreadEvent_Signal(int iThreadID, int iFlagStatus);
	int HandleThreadEvent_Dark(int iThreadID, int iFlagStatus);
	
	int GrabOnceFinished_Signal();
	int GrabOnceFinished_Dark();
	int GrabOnceFinished();
	
signals:
	void SignalStartGrabOnce_Signal();
	void SignalStartGrabOnce_Dark();

	void SignalGrabOnceFinished_Signal();
	void SignalGrabOnceFinished_Dark();
	void SignalGrabOnceFinished();


	void SignalStopGrab();
	void SignalStartGrab();
};