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

	Program:		Range Imaging Toolkit (RITK)
	Module:			ritkThreadedWorker.h
	Version:		$Revision: 1761 $
	Date:			$Date: 2011-09-23 17:25:41 +0200 (Fr, 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 THREADEDWORKER_H__
#define THREADEDWORKER_H__

#include "ritkCore.h"
#include "ritkThreadedEventProcessor.h"
#include "ritkThreadedJob.h"

namespace ritk
{


/**	@ingroup	Core
 *	@class		ThreadedWorker
 *	@author		Sebastian Bauer / Jakob Wasza
 *	@brief		Simple worker that runs in a separate thread
 *
 *	@details
 *	This class provides a worker that runs in its own thread.
 *	Jobs can be sent to this worker and are executed sequentially
 *	in the order they have been added. 
 */
class CORE_EXPORT ThreadedWorker : public ThreadedEventProcessor
{
    Q_OBJECT
	Q_INTERFACES(ritk::ThreadedEventProcessor)

public:
	/// Constructor
    ThreadedWorker();
	/// Destructor
    virtual ~ThreadedWorker();

	/**	@brief	Add a job for single execution
	 *	@param	job		The job
	 *
	 *	@details
	 *	Add a job for single execution. Note that jobs
	 *	should not contain massive work. If the delete flag
	 *	inside the job is set, the object will be deleted 
	 *	after execution.
	 */
    virtual void AddNewJob(ThreadedJob *job);

protected:
	/// Must be provided
	virtual void ProcessEvent(Event::Pointer Event);
};


/**	@ingroup	Core
 *	@class		ThreadedJobEvent
 *	@author		Jakob Wasza
 *	@brief		Event wrapper for a job event
 *
 *	@details
 */
class CORE_EXPORT ThreadedJobEvent : public Event
{
public:
	/// Constructor
	ThreadedJobEvent();
	/// Destructor
	virtual ~ThreadedJobEvent();

public:
	typedef QSharedPointer<ThreadedJobEvent> Pointer;
	/// The event type
	static QEvent::Type EventType;

	/**	@name The range image */
	//@{
	ThreadedJob *m_Job;
	//@}
};

} // end namespace ritk

#endif // THREADEDWORKER_H__