
#ifndef _StreamHandler_H_
#define _StreamHandler_H_

#include "STL.h"

/////////////////////////////////////////////////////////////////////////////////////////
//	Àü¹æ ÂüÁ¶

class CStreamBuffer;

typedef unsigned long	DWORD;
typedef void *			HANDLE;


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

class IStreamHandler
{
public:
	virtual ~IStreamHandler() {}

	virtual void	Create() = 0;
	virtual void	Destroy() = 0;
	virtual void	Add( CStreamBuffer & ) = 0;
	virtual void	Remove( CStreamBuffer & ) = 0;
	virtual void	Update() = 0;
};

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

class CStreamHandler : public IStreamHandler
{
public:
	typedef vector<HANDLE>			HANDLES;
	typedef vector<CStreamBuffer*>	STREAMBUFFERS;

protected:
	HANDLES	*		m_pHandles;
	STREAMBUFFERS *	m_pStreamBuffers;
	DWORD			m_dwNotifyThreadID;
	HANDLE			m_hNotifyThread;

	friend DWORD __stdcall NotificationProc( void * );

	void			UpdateStreamHandles();

public:
	CStreamHandler();
	~CStreamHandler();

	void	Create();
	void	Destroy();

	void	Add( CStreamBuffer & );
	void	Remove( CStreamBuffer & );
	void	Update() {}
};

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

class CStreamUpdater : public IStreamHandler
{
public:
	typedef vector<HANDLE>			HANDLES;
	typedef vector<CStreamBuffer*>	STREAMBUFFERS;

protected:
	HANDLES	*		m_pHandles;
	STREAMBUFFERS *	m_pStreamBuffers;

public:
	CStreamUpdater();
	~CStreamUpdater();

	void	Create();
	void	Destroy();

	void	Add( CStreamBuffer & );
	void	Remove( CStreamBuffer & );

	void	Update();
};


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

#endif