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


#ifndef	__ENETNETWORK__
#define __ENETNETWORK__


		#include <enet/enet.h>
		#include "network/network_interface.h"


namespace GS {
	namespace Network {

/*
	@short	Enet network.
	@author	Emmanuel Julien (ejulien@gsworks.fr)
*/
class	Enet : public INetwork
{
protected:

		ENetHost	*host;

public:

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

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

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

		bool		IsOpen() const { return asbool(host); }

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

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

		void		Close();

		Enet();
		~Enet();
};

	} // Network
} // GS


#endif	// __ENETNETWORK__
