#pragma once

//#define DF_PACKET_LOG
#pragma comment(lib, "ws2_32.lib")

#include "NetBridge_EventObj.h"

typedef void (*pfOutPutCB)( char* szOut );

class CNetBridge
{
public:
	CNetBridge( void ){}
	virtual ~CNetBridge( void ){}

	virtual int			Init				()=0;

	virtual	int			Host				( DWORD dwIP , WORD wPort, CEventObj* pEventObj, BOOL bCompress = false , BOOL bEncryption = false )=0;
	virtual int			Connect				( DWORD dwIP , WORD wPort, CEventObj* pEventObj )=0;

	virtual void		_Send				( DWORD dwNetID, DWORD dwSize, PVOID pBuffer, DWORD dwPriority =0, DWORD dwFlag =0 ) = 0;
	virtual void		Send				( DWORD dwNetID, DWORD dwSize, PVOID pBuffer, DWORD dwPriority =0, DWORD dwFlag =0 );
	virtual void		SendToAll			( DWORD dwSize, PVOID pPacket, DWORD dwPriority =0 )=0;
	virtual void		Flush				()=0;
	virtual DWORD		Wait				( DWORD dwTime )=0;
	virtual void		Close				( DWORD dwNetID )=0;

	virtual void		GetConnectInfo		( DWORD dwNetID, DWORD* pdwIP, WORD* pwPort ) =0;

	virtual void		SetOutPutCB			( pfOutPutCB pFun ) =0;
	virtual void		GetStatusInfo		( char* pszOut ) = 0;

	virtual	bool		Shutdown			() =0;

	static  DWORD		WaitAll				( DWORD dwTime );

	static	CNetBridge*	m_pNetPoint[ MAXIMUM_WAIT_OBJECTS ];
	static	HANDLE		m_pNetEventHandle[ MAXIMUM_WAIT_OBJECTS ];

	static	DWORD		m_dwNetHandleIndex;
	static	DWORD		m_dwEnterTime;

#ifdef DF_PACKET_LOG
	static	DWORD		m_dwPacketLog;
#endif

};

CNetBridge*				CreateNetBridge		();
void					DeleteNetBridge		( CNetBridge* pBridge );

DWORD					ConvertIP			( const char* pszIP );
void					ConvertIPtoString	( DWORD dwIP, char* pszIP );

struct Struct_PacketLog
{
	DWORD dwID;
	DWORD dwTime;
	DWORD dwPacketID;
};




//typedef priority_queue< CNetSocket*, vector< CNetSocket* >, CompareCloseTime > PQCLOSEQUEUE;
//#define DF_DEBUG_RECVMSG
//#define DF_DEBUG_SENDMSG


