#ifndef PkgTakeUndo_2L_INCLUDED
	#define PkgTakeUndo_2L_INCLUDED

#include <bncs_script_helper.h>

#ifdef WIN32
	#ifdef DOEXPORT_SCRIPT
		#define EXPORT_SCRIPT __declspec(dllexport) 
	#else
		#define EXPORT_SCRIPT 
	#endif
#else 
	#define EXPORT_SCRIPT
#endif
 
#define MAX_MATRIX_DEST 201

class PkgTakeUndo_2L : public bncs_script_helper
{
public:
	PkgTakeUndo_2L(bncs_client_callback* parent, const char* path);
	virtual ~PkgTakeUndo_2L();

	void buttonCallback(buttonNotify *b);
	int revertiveCallback(revertiveNotify * r);
	void databaseCallback(revertiveNotify * r);
	bncs_string parentCallback(parentNotify *p);
	void timerCallback(int);
	
private:
	bncs_string m_instance;				// The instance entry that defines the names driver id
	bncs_string m_matrixobject;			// The object name that tells us the level drivers and crosspoint lists
	bncs_string m_uselevels;			// Holds the level identification comma delimited string.
	bncs_string m_srcpkg;				// The text form of the source package number sent by source selector component
	bncs_string m_destpkg;				// The text form of the destination package number sent by source selector component
	bncs_string m_srcnamesdatabase;		// Database number to use when extracting source names for each level
	bncs_string m_destnamesdatabase;	// Database number to use when extracting destination names for each level
	bncs_string m_takelow;				// Statesheet name for state A of TAKE button flash
	bncs_string m_takehigh;				// Statesheet name for state B of TAKE button flash
	bncs_string m_mimicstate_L1;		// Statesheet name controlling Level 1 mimic look
	bncs_string m_mimicstate_L2;		// Statesheet name controlling Level 2 mimic look
	bncs_string m_takeundobgstate;		// Statesheet name for background panel of Take Undo component
	bncs_string m_unusedleveltext;		// Text to show in level mimic when level has no crosspoint assigned.

	int mySrcPkg;			// Souce package number
	int myDestPkg;			// Destination package number
	int srcNameDB;			// Database number to use for source name lookup
	int destNameDB;			// Database number to use for destination name lookup
	int PkgDriver;			// BNCS Driver ID for package names
	int XptDriver;			// BNCS Driver ID for crosspoint lists
	int L1_matrixID;		// BNCS Driver ID for level 1
	int L2_matrixID;		// BNCS Driver ID for level 2
	int myLevel1;			// Holds the user-set layer order data
	int myLevel2;			// Holds the user set layer order data
	int mySrcL1;			// Source number for level 1
	int mySrcL2;			// Source number for level 2
	int myDestL1;			// Destination number for level 1
	int myDestL2;			// Destination number for level 2
	int myUndoSrcL1;		// Level 1 source number for UNDO operation
	int myUndoSrcL2;		// Level 2 source number for UNDO operation
	int myUndoDestL1;		// Level 1 destination number for UNDO operation
	int myUndoDestL2;		// Level 2 destination number for UNDO operation
	int matrix_L1_Dests;	// Holds the number of destinations in the matrix used for level 1
	int matrix_L2_Dests;	// Holds the number of destinations in the matrix used for level 2
	int TakeCounter;		// Used in enabling TAKE button for finite period.

	bool Level_1_Enabled;	// Flag to control level 1 inclusion in TAKE
	bool Level_2_Enabled;	// Flag to control level 2 inclusion in TAKE
	bool TakeEnabled;		// Flag showing if Take Button is enabled
	bool UndoEnabled;		// Flag showing if Undo button is enabled
	bool takeTimerRunning;	// Flag that is active if the take timeout counter is active

	int revert_L1[MAX_MATRIX_DEST];	// Revertive store for level 1
	int revert_L2[MAX_MATRIX_DEST];	// Revertive store for level 2

	// Local methods
	void checkTakeReady(void);		// Called to see if we have a valid source and destination definition, and then enable the take button
	void noMatrixObject(void);		// Called when matrixobject string is null, or invalid value
	void parseMatrixObject(void);	// Called to process non-null matrixobject
	void clearSource(void);			// Called to deselect source data
	void clearDestination(void);	// Called to deselect destination data
	void disableTake(void);			// Called to disable the take button and other tidy ups
	void disableUndo(void);			// Called to disable the undo button
	void RegisterRouters(void);		// Register routers fro revertives, requires valid driver IDs before being called.
	void newSourcePackage(void);	// Called to process a new source package number
	void newDestinationPackage(void);	// Called to process a new destination package number
	void doTakeAction(void);		// Called to process a TAKE button pushed
	void doUndoAction(void);		// Called to process and UNDO button press
};


#endif // PkgTakeUndo_2L_INCLUDED