/*======================================================================================

	Program:		Range Imaging Toolkit (RITK)
	Module:			ritkCudaJob.h
	Version:		$Revision: 1761 $
	Date:			$Date: 2011-09-23 17:25:41 +0200 (Fri, 23 Sep 2011) $

	Copyright (c) 2010-2011
	Pattern Recognition Lab, 
    University Erlangen-Nuremberg, Germany
    All rights reserved.

	This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
	See RITKCopyright.txt for more information.

	http://www5.informatik.uni-erlangen.de/research/software/ritk

========================================================================================*/

#ifndef CUDAJOB__H__
#define CUDAJOB__H__

#include "ritkCuda.h"
#include "ritkThreadedJob.h"

#include <QMutex>
#include <QWaitCondition>

namespace ritk
{

/**	@ingroup	Cuda
 *	@class		CudaJob
 *	@author		Jakob Wasza
 *	@brief		A cuda job to be executed in the global cuda thread
 *
 *	@details
 *	This class implements the execution of a cuda job in the global
 *	cuda thread via the callback design pattern.
 */
class CUDA_EXPORT CudaJob : public ThreadedJob, public QWaitCondition, public QMutex
{
public:
	/// Constructor
	CudaJob();
	/// Destructor
	~CudaJob();

	/// Returns true
	bool DeleteAfterExecution();

	/**	@name	Set the callback function */
	//@{
	void SetCallbackFunction(void* Object, void(*Callback)(void*));
	void SetConstCallbackFunction(const void* Object, void(*Callback)(const void*)) const;
	//@}

	/// Execute the job. This will invoke the callback
	void Execute();

protected:
	/// Const qualifier
	mutable bool m_ConstQualifier;
	/// The pointer to the object that holds the static callback function
	//@{
	void *m_CallbackObject;
	mutable const void *m_ConstCallbackObject;
	//@}
	/// Pointer to the objects static callback function
	//@{
	void (*m_CallbackFunction)(void*);
	mutable void (*m_ConstCallbackFunction)(const void*);
	//@}
};

} // end namespace ritk

#endif // CUDAJOB__H__