///////////////////////////////////////////////////////////////////////////////
/// @file deConnectionBin.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	_DECONNECTIONBIN_HPP
#define _DECONNECTIONBIN_HPP

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

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

#include	<WINDOWS.H>

#include	<VECTOR>

class deThread;
class deConnection;
typedef	std::vector< deConnection* > aConnections;
typedef	std::vector< bool > aBools;

class DENET_API deConnectionBin
{
public:
	deConnectionBin(void);
	virtual ~deConnectionBin(void);

	eNetError			AddConnection( deConnection * pConn );
	eNetError			RemoveConnection( deConnection * pConn );

	HANDLE				GetNewConnectionEvent( void );
	DWORD				GetNumConnections( void );
	deConnection *		GetConnectionAt( DWORD pIndex );
	deSynchObject *		GetSynchObject(void);
	void				SetConnectionActivated( DWORD pIndex, bool pValue );
	bool				IsConnectionActivated( DWORD pIndex );
	bool				IsEmpty( void )	;
	bool				IsRunning( void );
	
	eNetError			Run( void );
	void				Stop( void );
	virtual eNetError	OnWorkerThread( deConnectionBin * pBin )	= 0;

	static void			SetMaxConnections( DWORD pNum );
	static DWORD		GetNumMaxConnections(void);

private:

	deThread *		m_ServiceThread;
	bool			m_bIsRunning;
	DWORD			m_iNumConnections;
	aConnections	m_aConnections;
	aBools			m_aConnectionsActivated;
	deSynchObject	m_SynchObject;
	HANDLE			m_NewConnectionEvent;

	static DWORD	m_iNumMaxConnections;
};

#endif