//////////////////////////////////////////////////////////////////////////////
//
// Asura_PS3_NP.h
//
// Copyright (c) 2008 Rebellion. All rights reserved.
//
// Description:
//
//     Asura wrapper for PSN Network Platform code
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef ASURA_PS3_NP_H___
#define ASURA_PS3_NP_H___ 1

// library headers
#include <np.h>

enum ASURA_PS3_NP_STATE
{
	ASURA_PS3_NP_STATE_OFFLINE,
	ASURA_PS3_NP_STATE_LOGGING_IN,
	ASURA_PS3_NP_STATE_GETTING_SERVERINFO,
	ASURA_PS3_NP_STATE_GETTING_WORLD,
	ASURA_PS3_NP_STATE_GETTING_MERIT,
	ASURA_PS3_NP_STATE_GETTING_GAMECOMPLETION,
	ASURA_PS3_NP_STATE_ONLINE,
	ASURA_PS3_NP_STATE_ERROR,
};

class Asura_PS3_NP
{
public:

	static void Initialise();
	static bool UpdateInitialisation();	// returns true when init is finished successfully
	static void Update();
	static void Shutdown();

	static bool IsInErrorState() { return s_eState == ASURA_PS3_NP_STATE_ERROR; }

	static SceNpMatching2ContextId GetContextID() { return s_xCtxId; }
	static SceNpMatching2WorldId GetWorldID() { return s_xWorld.worldId; }

	static const SceNpId& GetNpID() { return s_xNpId; }
	static const SceNpCommunicationId& GetCommunicationID() { return s_xProject_CommunicationId; }
	static const SceNpCommunicationPassphrase& GetCommunicationPassphrase() { return s_xProject_PassPhrase; }

private:

	static bool InitialiseMatching2();	// can only call this once logged in.
	static void ShutdownMatching2();

	static void UpdateGettingServerInfo();
	static bool GetWorlds();
	static void UpdateGettingWorld();
	static bool GetMerit();
	static bool UpdateGettingMerit();
	static bool GetGameCompletion();
	static bool UpdateGettingGameCompletion();

	// project functions
	static void Project_GetCommIDAndPassphrase( const SceNpCommunicationId** ppxCommId, 
												const SceNpCommunicationPassphrase** ppxPassPhrase );
	
	// callback functions
	static void ConnectionStatusCallback(int iEvent, int iResult, void* pArg );
	static void ContextCallback( SceNpMatching2ContextId xCtxId, SceNpMatching2Event usEvent, 
		SceNpMatching2EventCause ucEventCause, int iErrorCode, void* pArg );
	static void GetServerInfoCallback(SceNpMatching2ContextId xCtxId,
		SceNpMatching2RequestId xReqId, SceNpMatching2Event usEvent,
		SceNpMatching2EventKey xEventKey, int iErrorCode, size_t uDataSize, void* pArg);
	static void GetWorldInfoCallback(SceNpMatching2ContextId xCtxId,
		SceNpMatching2RequestId xReqId, SceNpMatching2Event usEvent,
		SceNpMatching2EventKey xEventKey, int iErrorCode, size_t uDataSize, void* pArg);

	// static class data
	static ASURA_PS3_NP_STATE s_eState;
	static void* s_pPool;
	static int s_iConnectionStatus;
	static SceNpId s_xNpId;
	static SceNpMatching2ContextId s_xCtxId;
	static SceNpMatching2ServerId* s_pxServerIDs;
	static SceNpMatching2World s_xWorld;
	static u_int s_uNumServers;
	static u_int s_uCurrentServer;


	static const SceNpCommunicationId s_xProject_CommunicationId;
	static const SceNpCommunicationPassphrase s_xProject_PassPhrase;
};

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

#endif // #ifndef ASURA_PS3_NP_H___
