/*
 * See the files COPYING and README for copyright information and how to reach 
 * the author.
 *
 *  $Id: manager.h,v 1.3 2006/04/20 18:59:26 lordjaxom Exp $
 */

#ifndef VDR_BURN_MANAGER_H
#define VDR_BURN_MANAGER_H

#include "jobs.h"
#include "proctools/startable.h"
#include <vdr/thread.h>

namespace vdr_burn
{

	class manager: public cThread,
				   public proctools::startable<manager>
	{
	public:
		class lock
		{
		public:
			lock(void);
			~lock();

		private:
			cMutex* m_mutex;
		};

#ifdef STONEAGE_GCC
		friend class manager::lock;
#endif

		manager(void);
		virtual ~manager();

		static bool get_is_busy(void);

		// the following methods may only be called and their results only be 
		// used while manager is locked
		static void add_job(job* job_);
		static void del_job(job* job_);

		static job* get_active(void) { return m_instance->m_active; }
		static const job_queue& get_queued(void);
		static const job_queue& get_erroneous(void);
		static const job_queue& get_canceled(void);

	protected:
		virtual void Action(void);

		void start_if_idle(void);
		void check_rotate(void);

	private:
		cMutex    m_mutex;
		cCondVar  m_condition;

		job*      m_active;
		job_queue m_queued;
		job_queue m_erroneous;
		job_queue m_canceled;
	};

	inline
	const job_queue& manager::get_queued(void) 
	{ 
		return m_instance->m_queued; 
	}
	
	inline
	const job_queue& manager::get_erroneous(void) 
	{ 
		return m_instance->m_erroneous; 
	}
	
	inline
	const job_queue& manager::get_canceled(void) 
	{ 
		return m_instance->m_canceled; 
	}

}

#endif // VDR_BURN_MANAGER_H
