///////////////////////////////////////////////////////////////////////////////
//
// File: Asura_Platform_Qos_System.cpp
//
// Created by Martin G.Harris (9/4/2009)
// 
// Copyright (C) 2009 Rebellion, All Rights Reserved.
//
// Description: System for measuring the upload bandwidth of machines in the
//				lobby of online games. This information can then be used to
//              help determine which machine would make the best game server.
//
///////////////////////////////////////////////////////////////////////////////

#include "Core/Asura.h"
#include "Network/Asura_Qos_System.h"

#ifdef ASURA_ENABLE_QOS_SYSTEM

// Includes
#include <Winsock2.h>

#include "Debugging/Asura_Assert.h"
#include "Debugging/Asura_Logfile.h"
#include "Network/Asura_QosSocket_BSD.h"
#include "Network/Steamworks/Asura_PC_Steamworks.h"
#include "Network/Steamworks/Asura_PC_SteamworksQosSocket.h"


///////////////////////////////////////////////////////////////////////////////
// Asura_Qos_System
///////////////////////////////////////////////////////////////////////////////

void Asura_Qos_System::Platform_Initialise()
{
	// Startup WinSock
	WSADATA wsaData;
	const int iResult = WSAStartup(MAKEWORD(1,1), &wsaData);
	if (iResult != NO_ERROR)
	{
		Asura_Assertf(0, ("Error %d at WSAStartup()", iResult));
		s_bInitialised = false;
	}
}


void Asura_Qos_System::Platform_Shutdown()
{
	// Cleanup WinSock
	const int iResult = WSACleanup();
	if (iResult != NO_ERROR)
	{
		Asura_Assertf(0, ("Error %d at WSACleanup()", WSAGetLastError()));
	}
}

Asura_QosSocket* Asura_Qos_System::Platform_CreateSocket(bool bIsHost)
{
#ifdef ASURA_PC_SUPPORT_STEAMWORKS
	if ( Asura_PC_Steamworks::IsSteamworksEnabled() )
	{
		if (bIsHost)
		{
			return new Asura_QosSocket_Steamworks_Server;
		}
		else
		{
			return new Asura_QosSocket_Steamworks_Client;
		}
	}
#endif // ASURA_PC_SUPPORT_STEAMWORKS

	return new Asura_QosSocket_BSD;
}


#endif //#ifdef ASURA_ENABLE_QOS_SYSTEM
