//////////////////////////////////////////////////////////////////////////////
//
// Asura_GameSpy_PersistentStorage.h
//
// Copyright (c) 2005 Rebellion. All rights reserved.
//
// Description:
//
//     interface for GameSpy persistent storage SDK
//
//////////////////////////////////////////////////////////////////////////////

// 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_GAMESPY_PERSISTENTSTORAGE_H___
#define ___ASURA_GAMESPY_PERSISTENTSTORAGE_H___ 1

// E N U M S /////////////////////////////////////////////////////////////////
enum ASURA_GSPS_STATE
{
	ASURA_GSPS_STATE_NOT_INITIALISED,
	ASURA_GSPS_STATE_CONNECTING,
	ASURA_GSPS_STATE_AUTHENTICATING,
	ASURA_GSPS_STATE_AUTHENTICATED,
	ASURA_GSPS_STATE_AUTH_FAILED,
	ASURA_GSPS_STATE_GETTINGDATA,
	ASURA_GSPS_STATE_SETTINGDATA,
};

// corresponds to persisttype_t
enum ASURA_GSPS_DATATYPE
{
	ASURA_GSPS_DATATYPE_PRIVATE_READONLY,
	ASURA_GSPS_DATATYPE_PRIVATE_READWRITE,
	ASURA_GSPS_DATATYPE_PUBLIC_READONLY,
	ASURA_GSPS_DATATYPE_PUBLIC_READWRITE,
};

// T Y P E D E F S ///////////////////////////////////////////////////////////
typedef void (*Asura_GSPS_DataReceivedCallback)( bool bSuccess, const char* pcData, u_int uDataLength, void* pInstance );
typedef void (*Asura_GSPS_DataStoredCallback)( bool bSuccess, void* pInstance );

// C L A S S E S /////////////////////////////////////////////////////////////
class Asura_GameSpy_PersistentStorage
{
	friend class Asura_GSPS_Internal;
public:

	// you must be logged in to GP before calling initialise
	static bool Initialise();
	static bool Update();	// Update returns false iff the connection to the server is lost.
	static void Shutdown();

	static ASURA_GSPS_STATE GetState() { return s_eState; }
	static bool IsIdle() { return s_eState == ASURA_GSPS_STATE_AUTHENTICATED; }
	
	// A profile can have multiple data blocks stored (each one has an index which is any integer).
	// Each block is either binary data or a set of key/value pairs e.g. "key1\value1\key2\value2"
	// If you use key/value pairs you can get/set subsets of the entire block and also get the 
	// entire set of key/value pairs using GetDataBlock(). 
	// If you set a key which doesn't already exist it is created, otherwise the value is updated.
	// Currently, you can only have one outstanding call to this class. Your callback will be 
	// called with success or failure so you know when you can do another call (or use IsIdle()).
	static bool GetDataBlock(int iIndex, Asura_GSPS_DataReceivedCallback pfnCallback, ASURA_GSPS_DATATYPE eDataType, void* pInstance = 0);
	static bool GetDataBlockValues(int iIndex, const char* szKeys, Asura_GSPS_DataReceivedCallback pfnCallback, ASURA_GSPS_DATATYPE eDataType, void* pInstance = 0);
	static bool SetDataBlock(int iIndex, char* pcData, u_int uDataLength, Asura_GSPS_DataStoredCallback pfnCallback, ASURA_GSPS_DATATYPE eDataType, void* pInstance = 0);
	static bool SetDataBlockValues(int iIndex, const char* szKeysValues, Asura_GSPS_DataStoredCallback pfnCallback, ASURA_GSPS_DATATYPE eDataType, void* pInstance = 0);

private:

	static ASURA_GSPS_STATE s_eState;
};


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

#endif // #ifndef ___ASURA_GAMESPY_PERSISTENTSTORAGE_H___
