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

	Program:		Range Imaging Toolkit (RITK)
	Module:			ritkCudaJob.cxx
	Version:		$Revision: 2883 $
	Date:			$Date: 2012-04-02 17:01:22 +0200 (Mo, 02 Apr 2012) $

	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

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

#include "ritkCudaJob.h"

namespace ritk
{

//----------------------------------------------------------------------------
CudaJob::CudaJob()
{
	m_ConstQualifier = false;
}


//----------------------------------------------------------------------------
CudaJob::~CudaJob()
{
}


//----------------------------------------------------------------------------
bool
CudaJob::DeleteAfterExecution()
{
	return false;
}


//----------------------------------------------------------------------------
void 
CudaJob::SetCallbackFunction(void* Object, void(*Callback)(void*))
{
	m_CallbackObject = Object;
	m_CallbackFunction = Callback;
}


//----------------------------------------------------------------------------
void 
CudaJob::SetConstCallbackFunction(const void* Object, void(*Callback)(const void*)) const
{
	m_ConstQualifier = true; 
	m_ConstCallbackObject = Object;
	m_ConstCallbackFunction = Callback;
}


//----------------------------------------------------------------------------
void 
CudaJob::Execute()
{
	// Lock ourself
	QMutexLocker locker(this);

	// Execute the static callback function
	if ( !m_ConstQualifier )
		m_CallbackFunction(m_CallbackObject);
	else
		m_ConstCallbackFunction(m_ConstCallbackObject);

	// Wake objects that wait on us
	QWaitCondition::wakeAll();
}

} // end namespace ritk
