//--------------------- CSPTransaction.h ----------------------

//*************************************************************
//*****       Copyright ©2002 - 2004 Micronovae Ltd       *****
//*****                All rights reserved                *****
//*************************************************************


#ifndef CSPTRANSACTION
#define CSPTRANSACTION

//#import "CSPTxObject\Debug\CSPTxObject.dll" raw_interfaces_only, raw_native_types, no_namespace, named_guids
#include "CSPConf.h"
#include "CSPLib.h"
#include "CSPTxObject.h"

#include <TRANSACT.H>
#include <TXCTX.H>

////////////////////////////

class CSPLIB_CLASS_EXPORT CSPTxContext : public CSPObject
{
public:
	CSPTxContext();
	CSPTxContext( const CSPTxContext& TxCtx );
	virtual ~CSPTxContext();
	bool Commit();
	bool Abort();
	bool CreateInstance( REFCLSID refCLSID, REFIID refIID, void** ppvObj ) const;

protected:
	ITransactionContextEx* pTxCtx;
};

/////////////////////////


class CSPLIB_CLASS_EXPORT CSPTxObject : public CSPObject
{
public:

	CSPTxObject();
	CSPTxObject( const CSPTxObject& TxObj );
	CSPTxObject( const CSPTxContext& TxCtx );	
	virtual ~CSPTxObject();

protected:
	ITransaction* GetTransaction();
	bool CreateInstance( REFCLSID refCLSID, REFIID refIID, void** ppvObj ) const;
	bool Commit();
	bool Abort();
	

private:
	ITxObject* pObjCtx;	
	bool bInit;
};


/*

////////////////////////////////////

class CTxLocalContext
{
	friend class CTxObject;
	friend class CTxResource;
public:
	CTxLocalContext();
	virtual ~CTxLocalContext();

	bool Commit();
	bool Abort();

protected:
private:
	bool Add( CTxObject& TxObj );	
	bool Add( CTxResource& TxRes );
	CSPList<int> ObjectStateList;
	CSPList<CTxResource> ResourceList;
};


///////////////////////////

class CTxObject
{
	friend class CTxLocalContext;
public:
	enum{ TX_STATE_NO_COMMIT = 0, TX_STATE_COMMIT, TX_STATE_ABORT };

	CTxObject();
	CTxObject( const CTxObject& ObjCtx );
	CTxObject( const CTxContext& TxCtx );
	CTxObject( CTxLocalContext& TxCtx );
	virtual ~CTxObject();

	ITransaction* GetTransaction();

protected:
	bool CreateInstance( REFCLSID refCLSID, REFIID refIID, void** ppvObj ) const;
	bool Commit();
	bool Abort();
	

private:
	ITxContext* pObjCtx;
	CTxLocalContext* pTxLocalCtx;
	bool bInit;
	int iTxState;
};


//////////////////////////

class CTxResource
{
	friend class CTxLocalContext;
	friend class CTxContext;

public:
	CTxResource();
	CTxResource( CTxResource& ObjCtx );
	CTxResource( CTxLocalContext& TxCtx );
	CTxResource( CTxContext& TxCtx );
	virtual ~CTxResource();

protected:

	virtual bool OnAbort();		// To be overloaded
	virtual bool OnCommit();	// To be overloaded	

	bool Commit();
	bool Abort();
	
	CTxLocalContext* pTxLocalCtx;
	bool bInit;
};



*/


#endif
