//////////////////////////////////////////////////////////////////////////////
//
// Asura_PS3_Trophies_System.h
//
// Copyright (c) 2009 Rebellion. All rights reserved.
//
// Description:
//
//     Wrapper class for PS3 trophy SDK. Called via Asura_Rewards_System, do
//     not use directly
//
//////////////////////////////////////////////////////////////////////////////

// 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_TROPHIES_SYSTEM_H___
#define ASURA_PS3_TROPHIES_SYSTEM_H___ 1

#ifdef ASURA_USE_REWARDS

#include "Core/Asura_Multithread.h" // for Asura_Semaphore

#include <np.h>

class Asura_ProducerConsumerQueue;

class Asura_PS3_Trophies_System
{
public:
	static void Initialise();

	static void Shutdown();

	static void Reset();

	static bool IsInitialised();

	static bool IsInitComplete();

	static bool DiskSpaceCheckPassed() {return s_bDiskSpaceCheckPassed;}

	static bool DiskSpaceErrorOccured() {return s_bDiskSpaceErrorOccured;}

	static u_int DiskSpaceTotalKRequired() {return s_uDiskSpaceTotalKRequired;}

	static u_int DiskSpaceExtraKRequired() {return s_uDiskSpaceExtraKRequired;}

	static bool GeneralErrorOccured() {return s_bGeneralErrorOccured;}

	static int GetGeneralErrorCode() {return s_iGeneralErrorCode;}

	static int Project_ConvertReward(u_int uRewardIndex); //project function to map independent reward index to trophy id. return -1 if no trophy mapped (none ps3 reward)

	static void UnlockTrophy(int iTrophy);	//Wrapper for SDK code to unlock a reward.

	static bool IsTrophyUnlocked(int iTrophy);	//Possibly wrapper for SDK code to query if a reward is unlocked, but this is time consuming for some platforms, so the list will need to be enumerated and stored at initialisation.

private:
	static u_long SizeInK(u_long ulBytes);
	static void Threaded_Init(void* pData, u_int uSize);

	static void Threaded_Unlock(void* pData, u_int uTrophy);

	static int StatusCallback(SceNpTrophyContext uContext, SceNpTrophyStatus eStatus, int iCompleted, int iTotal, void* pArg);

	static Asura_ProducerConsumerQueue* s_pxWorkerThread;
	static Asura_Semaphore s_xInitCompleteSemaphore;
	static bool s_bInitComplete;
	static bool s_bDiskSpaceCheckPassed;
	static bool s_bDiskSpaceErrorOccured;
	static u_int s_uDiskSpaceTotalKRequired;
	static u_int s_uDiskSpaceExtraKRequired;
	static bool s_bGeneralErrorOccured;
	static int s_iGeneralErrorCode;
	static u_int s_uNumTrophies;
	static SceNpTrophyFlagArray s_xTrophiesUnlocked;

	static SceNpTrophyContext s_uNPTrophyContext;
	static SceNpTrophyHandle s_uNPTrophyHandle;

	static const SceNpCommunicationId* Project_GetCommunicationID();
	static const SceNpCommunicationSignature* Project_GetCommunicationSig();
	static u_int Project_GetRequiredSpaceInK();

};
#endif // #ifdef ASURA_USE_REWARDS

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

#endif // #ifndef ASURA_PS3_TROPHIES_SYSTEM_H___
