///////////////////////////////////////////////////////////////////////////////
//
// File      : Asura_PS3_GameData.h
// Author    : Philip Hall
// Created   : 14/12/2007
//
// Copyright (C) 2007 Rebellion. All Rights Reserved
//
///////////////////////////////////////////////////////////////////////////////

#if !defined __ASURA_PS3_GAMEDATA_H__
#define __ASURA_PS3_GAMEDATA_H__

// Asura PS3 headers
#include "core/Asura_PS3_Semaphore.h"
#include "fileaccess/Asura_PS3_FileSystem.h"

// platform specific headers
#include <sys/ppu_thread.h>
#include <sysutil/sysutil_gamedata.h>

////PGH////////////////////////////////////////////////////////////////////////
// How to use 'Asura_PS3_GameData'
//
// To check that data exists, use synchronously without callbacks
//
//    Asura_PS3_GameData xDataQuery(ASURA_PS3_PROJECT_PRODUCT_CODE);
//    xDataQuery.Begin();
//    xDataQuery.WaitComplete(5000);
//
// Then extract information directly from the object.
//
// To update/recreate data, use asynchronously with callbacks
//
//    Asura_PS3_GameData* pxDataInstall = new Asura_PS3_GameData(ASURA_PS3_PROJECT_PRODUCT_CODE, true);
//    pxDataInstall->Begin(&Some_PS3_InstallDataCheck, &Some_PS3_InstallDataCreate);
//
// The callbacks will be called in the order DataCheck, DataCreate. If you
// return false from the DataCheck callback it won't call the DataCreate 
// callback.
// Callbacks are called on a thread, and you can use the filesystem functions
// to access the 'info' and 'data' directories returned by the game data 
// object. Do NOT use directories other than this as it is a TRC violation.
//
///////////////////////////////////////////////////////////////////////////////

class Asura_PS3_GameData;

typedef void (*Asura_PS3_DataCreateCallback)(const Asura_PS3_GameData* pGameData);
typedef bool (*Asura_PS3_DataCheckCallback)(const Asura_PS3_GameData* pGameData, int& iKBRequired);


////PGH/////////////////////////////////////////
// PS3 game data API wrapper
////////////////////////////////////////////////
class Asura_PS3_GameData
{
protected:

public:
	Asura_PS3_GameData(const char* szProductCode, bool bAutoDelete = false);
	virtual ~Asura_PS3_GameData();

	bool Begin(Asura_PS3_DataCheckCallback pfnCheck=NULL, Asura_PS3_DataCreateCallback pfnCreate=NULL);
	bool WaitComplete(int iTimeoutMS);

	const char* GetInfoPath() const        { return m_szInfoPath; }
	const char* GetDataPath() const        { return m_szDataPath; }
	bool        ShouldRecreateData() const { return m_bRecreateData; }
	bool        IsEnoughSpace() const      { return m_bEnoughSpace; }
	int         SpaceRequiredKB() const    { return m_iSpaceRequiredKB; }

protected:
	static void ThreadGameData(uint64_t uParam);
	static void GameDataStatusCallback( CellGameDataCBResult* pResult, CellGameDataStatGet* pGet, CellGameDataStatSet* pSet );

protected:
	Asura_PS3_Semaphore          m_xCompleted;
	sys_ppu_thread_t             m_xThreadID;
	bool                         m_bAutoDeleteThis;

	char                         m_szProductCode[CELL_GAMEDATA_DIRNAME_SIZE];
	char                         m_szInfoPath[CELL_GAMEDATA_PATH_MAX];
	char                         m_szDataPath[CELL_GAMEDATA_PATH_MAX];
	bool                         m_bRecreateData;
	bool                         m_bEnoughSpace;
	int                          m_iSpaceRequiredKB;
	Asura_PS3_DataCreateCallback m_pfnRecreateData;
	Asura_PS3_DataCheckCallback  m_pfnCheckData;
};



#endif


