// DWBS ------------------------------------------------------------------ DWBS
//
// PLATFORM		: ALL
// PRODUCT		: BIT_DEMON
// VISIBILITY	: PUBLIC
//
// DWBS ------------------------------------------------------------------ DWBS

// PURPOSE: A handle to keep track of a Matchmaking+ remote task.

#ifndef BD_REMOTE_TASK_H
#define BD_REMOTE_TASK_H

#include <bdCore/bdCore.h>


BD_REFERENCE(bdBitBuffer);

/// A handle to keep track of a Matchmaking+ remote task.
/// A remote task handles the communication to the LSG and processes any
/// available results. The game code should pump the status of the remote task
/// until it has entered a 'complete' state.
class bdRemoteTask
{
	public:

		BD_DECLARE_NEW_AND_DELETE_OPERATORS

		enum bdStatus
		{
			BD_EMPTY,
			BD_PENDING,
			BD_DONE,
			BD_TIMED_OUT,
			BD_MAX_STATUS
		};

		/// Default Constructor
		bdRemoteTask();

		/// Destructor.
		~bdRemoteTask();

		/// Closes a task. A task has to be closed after it has been
		/// handled in order to make it available for subsequent usage.
		void close();		

		/// Gets the current status of the task
		/// \return The task's status
		bdStatus getStatus();	

		/// Gets the result set of a task 
		/// \return A bitbuffer containing any results returned from the server
		bdBitBufferRef getResults() const;		

		bdFloat32 getTimeout() const;

		void setTimeout(const bdFloat32 timeout);

		/// \return the transaction ID of the task (or 0 if status!=BD_DONE)
		bdUInt64 getTransactionID() const;

	protected:

		friend class bdRemoteTaskManager;

		void start(const bdFloat32 timeout);

		void stop(const bdBitBufferRef results, const bdUInt64 id);

	protected:

		bdStopwatch m_timer;
		bdFloat32 m_timeout;
		bdStatus m_status;
		bdBitBufferRef m_results;
		bdUInt64 m_transactionID;
};

#endif // BD_REMOTE_TASK_H
