/* -----------------------------------------------------------------------------
	GSFramework
	Copyright 2001-2013 Emmanuel Julien. All Rights Reserved.
----------------------------------------------------------------------------- */


#ifndef	__NETWORK_INTERFACE__
#define __NETWORK_INTERFACE__


		#include "container/narray.h"
		#include "ntypes.h"


namespace GS {
	class String;
	namespace Network {

//
struct	INetwork
{
enum Timeout
{
	TimeoutDefault	=	0,
	TimeoutLong,
	TimeoutVeryLong
};

virtual	bool		SendString(void *peer, const String &);
virtual	bool		BroadcastString(const String &);

struct	Statistics
{
		size_t	sent_data;
		size_t	received_data;
};

virtual	void		GetStatistics(Statistics &) = 0;
virtual	int			GetPeerPacketLossRatio(void *peer) = 0;

virtual	void		OnPeerConnection(void *peer) = 0;
virtual	void		OnPacketReceived(void *peer, const void *data, size_t size) = 0;
virtual	void		OnConnectionClosed(void *peer) = 0;

/*!
	@name	Communication interface.
	@{
*/
virtual	void		UpdateHost() = 0;

virtual	bool		Send(void *peer, const void *data, size_t size) = 0;
virtual	bool		Broadcast(const void *data, size_t size) = 0;
/// @}

virtual	bool		IsOpen() const  = 0;

virtual	bool		GetHostAddress(String &address) = 0;
virtual	bool		GetPeerAddress(void *peer, String &address) = 0;
virtual	void		SetPeerTimeout(void *peer, Timeout = TimeoutDefault) = 0;

virtual	bool		OpenServer(const char *address, int port) = 0;
virtual	bool		OpenClient(const char *address, int port) = 0;
virtual	void		Disconnect(void *peer) = 0;

virtual	void		Close() = 0;

virtual	~INetwork() {}
};

	} // Network
} // GS


#endif	// __NETWORK_INTERFACE__
