/*
*	This class runs on the SUT and receives transaction requests from drivers.
*
*	Written by Sergey Vasilevskiy, 2002-2003.
*/

#include "stdafx.h"

class CCEServer : public CBaseServer<TCEServerLocals>
{
	char*				m_szDBServer;
	char*				m_szDB;
	bool				m_bVerbose;	
	TMEEIndexTable		m_MEETable;
    TPCE::CMutex	    m_MEETableLock;	// to protect update from multiple UE's		
	eClientDriverType	m_eClientType;
	char				m_szMEEToUse[iMaxMEENameLen];

	virtual TCEServerLocals* InitializeLocal();
	// Main function executing transactions.
	//
	virtual int ProcessMessage(char *mes, DWORD iTotalBytesRecvd, TCEServerLocals* pLocal, int iThreadNum, PSUTReplyMessage pSUTReply);

    int DoBrokerVolume(TPCE::PBrokerVolumeTxnInput input, TPCE::TBrokerVolumeTxnOutput &Output, TPCE::CBrokerVolume &BV);
	int DoCheckpoint(PCheckpointInput pInput, CCheckpointDB &CH);
	int DoCustomerPosition(TPCE::PCustomerPositionTxnInput input, TPCE::TCustomerPositionTxnOutput &Output, TPCE::CCustomerPosition &CP);
	int DoDataMaintenance(TPCE::PDataMaintenanceTxnInput input, TPCE::TDataMaintenanceTxnOutput &Output, TPCE::CDataMaintenance &DM);
	int DoMarketWatch(TPCE::PMarketWatchTxnInput input, TPCE::TMarketWatchTxnOutput &Output, TPCE::CMarketWatch &MW);
	int DoSecurityDetail(TPCE::PSecurityDetailTxnInput input, TPCE::TSecurityDetailTxnOutput &Output, TPCE::CSecurityDetail &SD);
	int DoTradeLookup(TPCE::PTradeLookupTxnInput input, TPCE::TTradeLookupTxnOutput &Output, TPCE::CTradeLookup &TO);
	int DoTradeOrder(TPCE::PTradeOrderTxnInput input, TPCE::TTradeOrderTxnOutput &Output, TPCE::CTradeOrder &TO);
	int DoTradeStatus(TPCE::PTradeStatusTxnInput input, TPCE::TTradeStatusTxnOutput &Output, TPCE::CTradeStatus &TS);
	int DoTradeUpdate(TPCE::PTradeUpdateTxnInput input, TPCE::TTradeUpdateTxnOutput &Output, TPCE::CTradeUpdate &TU);
	int ReceiveMEETable(PMEEIndexTable input);

	void PrintBrokerVolumeParams(TPCE::PBrokerVolumeTxnInput input);
	void PrintCheckpointParams(PCheckpointInput pInput);
	void PrintCustomerPositionParams(TPCE::PCustomerPositionTxnInput input);
	void PrintDataMaintenanceParams(TPCE::PDataMaintenanceTxnInput input);
	void PrintMarketWatchParams(TPCE::PMarketWatchTxnInput input);
	void PrintSecurityDetailParams(TPCE::PSecurityDetailTxnInput input);
	void PrintTradeLookupParams(TPCE::PTradeLookupTxnInput input);
	void PrintTradeOrderParams(TPCE::PTradeOrderTxnInput input);
	void PrintTradeStatusParams(TPCE::PTradeStatusTxnInput input);
	void PrintTradeUpdateParams(TPCE::PTradeUpdateTxnInput input);
	void PrintMEETable(PMEEIndexTable input);
	void PrintTxnParams(PDriverMessage pTxn);

    void CleanUp(PDriverMessage pTxn, TCEServerLocals* pLocal, TPCE::CBaseErr *pErr);

    void PrintError(TPCE::CODBCERR* pODBCErr, TPCE::CDateTime& TimeNow);   // helper routine to display an error message

public:
	CCEServer(	char*				szDBServer, 
				char*				szDB, 
				short				shPort, 
				bool				bVerbose,
				HANDLE				hStopEvent, 
				eClientDriverType	eClientType,
				char*				szMEEToUse);
	~CCEServer();
};
