#pragma once

#include "..\\global\\iblock.h"

// CBlockItem command target
/*
#include <map>

typedef struct{
	DWORD dwDataLen;
	LPVOID pData;
}REVDATA, *LPREVDATA;

typedef std::map<DWORD, REVDATA> REVDATAMAP, *LPREVDATAMAP;

typedef struct{
	VOID ***pDataArrayArray;	// pouziti: ppDataArray[port][vrstva]
	DWORD *dwLayersArray;		// pocet vrstev v jednotlivych portech
}BLOCKDATA, *LPBLOCKDATA;
*/
class CSchemeDoc;
class CBlockItem_Virtual;

class CBlockItem : public CObject
{
	DECLARE_SERIAL(CBlockItem);
protected:
	CBlockItem();
	virtual ~CBlockItem();

public:
	ULONG AddRef();
	ULONG Release();
	CBlockItem* Clone() const;
	virtual CString GetName() const;
	virtual CString GetDescription() const;
	virtual CString GetStatus() const;
	virtual CString GetInputPortName(DWORD dwPort) const;
	virtual CString GetOutputPortName(DWORD dwPort) const;

	virtual BOOL InitInstance();
	virtual BOOL ExitInstance();

	virtual BOOL Start();
	virtual BOOL Stop();

	DWORD GetInputCount() const;
	DWORD GetOutputCount() const;

	VOID SetPos(const POINTF *pPoint);
	VOID GetPos(POINTF *pPoint) const;

	BOOL GetInConnectorTarget(DWORD dwPort, CBlockItem** ppTargetBlock, LPDWORD pdwTargetPort, BOOL bAddRef = FALSE);
	BOOL SetInConnectorTarget(DWORD dwPort, CBlockItem* pTargetBlock, DWORD dwTargetPort);
	BOOL DeleteReferencesToBlock(CBlockItem* ptr);

	virtual BOOL SetDocPtr(CSchemeDoc* ptr);

	virtual BOOL ShowProperties(BOOL bTest = FALSE);

private:
	CRITICAL_SECTION m_csProcess;

	LONG m_refCount;
	float m_fX, m_fY;
	CBlockItem **m_pConnectorTargetBlockArray;
	DWORD *m_pConnectorTargetPortArray;
	DWORD m_dwInputPortCount;
	DWORD m_dwOutputPortCount;
	CBlockItem_Virtual* m_pParentBlock;
	double m_dLastProcessTime;
	virtual BOOL ProcessRev(const DWORD dwProcessId, REVDATAMAP &rRevDataMap);
	virtual BOOL ClearRevMap(REVDATAMAP &rRevDataMapClean);
	virtual BOOL ProcessData(const LPBLOCKDATA pInputData);
public:
	virtual const PORTDATA GetOutputPortData(DWORD dwPort) const;
	virtual LPCRITICAL_SECTION GetOutputCriticalSectionPtr(DWORD dwPort) const;

	virtual BOOL SetInputCount(const DWORD dwPorts);
	virtual BOOL SetOutputCount(const DWORD dwPorts);
	double GetLastProcessingTime() const;
	CSchemeDoc *m_pDocument;
	DWORD m_dwLastProcessId;

	virtual BOOL GetModifiedFlag();					// vraci, zda byl nektery z podrizenych realnych bloku zmenen
	virtual VOID SetModifiedFlag(BOOL bModified);	// vraci, zda byl nektery z podrizenych realnych bloku zmenen

public:
	virtual void Serialize(CArchive& ar);
	BOOL SetParentBlock(CBlockItem_Virtual *ptr);
	CBlockItem_Virtual* GetParentBlock() const;
	virtual BOOL Process(DWORD dwProcessId, REVDATAMAP &rRevDataMap);
};