///////////////////////////////////////////////////////////////////////////////
/// @file deConnectionProvider.hpp
///
/// @brief 
///
/// @author trajar
///
/// This file is the intellectual property of Novus Delta, LLC.. Usage of the
/// contents of this file is subject to the Destiny3D Member License which
/// can be found at http://www.destiny3d.com.  Any other usage is prohibited.
///
/// This file is distributed "AS IS" without warranty of any kind.  Novus
/// Delta, LLC. does not guarantee the fitness of the contents of this file
/// for any particular purpose.
///
/// Copyright (C) 2001-2003 Novus Delta, LLC. All Rights Reserved.
///
/// <hr>
///                                 Change History
/// <hr>
///
/// @date Jun 2002
/// @author trajar
/// @remarks Creation
///
///////////////////////////////////////////////////////////////////////////////

#ifndef	_DECONNECTIONPROVIDER_HPP
#define	_DECONNECTIONPROVIDER_HPP

#include	<WINDOWS.H>

#ifndef		_DENET_HPP
 #include	"deNet.hpp"
#endif

#ifndef		_DESYNCHOBJECT_HPP
 #include	"deSynchObject.hpp"
#endif

class deConnection;
class deConnectionBin;

typedef class DENET_API deConnectionProvider
{
public:

	deConnectionProvider(void);
	virtual ~deConnectionProvider(void);

	eNetError			AddConnectionToBins( deConnection * pConn );
	eNetError			Init( DWORD dwFlags = NULL);
	eNetError			Shutdown( DWORD dwFlags = NULL );
	eNetError			CreateConnection( deConnection ** pOut, void * pProviderInfo = NULL, DWORD dwFlags = NULL );
	eNetError			CloseConnection ( deConnection ** pConn, DWORD dwFlags = NULL );

	WORD				GetNumTotalConnectionBins(void);
	WORD				GetNumProvidedConnectionBins(void);
	DWORD				GetNumTotalConnections(void)	const	{ return m_iNumTotalConnections; }
	DWORD				GetNumProvidedConnections(void)	const	{ return m_iNumConnections; }
	bool				IsReady(void)					const	{ return m_bReady; }
	deSynchObject *		GetSynchObject(void)			  { return &m_SynchObject; }

	virtual deConnection *		GetConnectionAt( DWORD pIndex )								= 0;

protected:

	virtual eNetError	OnInit( DWORD dwFlags = NULL )										= 0;
	virtual eNetError	OnShutdown( DWORD dwFlags = NULL )									= 0;
	virtual	eNetError	OnCreateConnection( deConnection ** pOut, void * pProviderInfo = NULL, DWORD dwFlags = NULL )	= 0;
	virtual eNetError	OnCloseConnection ( deConnection ** pConn, DWORD dwFlags = NULL )		= 0;

	virtual deConnectionBin *	GetAvailableBin(void)				= 0;
	virtual deConnection *		GetUnusedConnection(void)			= 0;

	deConnectionBin *	m_aConnectionBins;
	deConnection *		m_aConnections;
	deSynchObject		m_SynchObject;

private:

	static DWORD		m_iNumTotalConnections;
	DWORD				m_iNumConnections;
	static WORD			m_iNumTotalConnectionBins;
	WORD				m_iNumConnectionBins;
	bool				m_bReady;

} deConnectionProvider, *pdeConnectionProvider;

#endif