/***************************************************************************

    supportware
    Copyright (C) 2001-2008 by c.holzheuer
    c.holzheuer@sourceworx.org

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

***************************************************************************/
#ifndef DDTHREADRUNNABLE_H
#define DDTHREADRUNNABLE_H


#include <ddbaseobject.h>

class ddthread;

/// ddthreadrunnable: basisklasse für prozesse die von einen thread ausgeführt werden.
/**
	Geklaut aus irgendeiner library, basiert konzeptionell auf java.

*/

class ddthreadrunnable : public ddbasenamedobject
{

friend class ddthread;

public:

	ddthreadrunnable();
	ddthreadrunnable( const ddstring& name );
	virtual ~ddthreadrunnable();

	virtual void run();
	
	void  wait();
	int   wait( unsigned secs );
	void  exit();  
	void	notify();
	void	start_thread();	
	void	cancel_thread();

	
	/**
		Jedes runnable hat einen Besitzer-Thread.
	*/

	ddthread* get_thread() const
	{
		return _owner;
	}	
	

private:

	inline void set_thread( ddthread *owner )
	{
		_owner = owner;
	}
	
	ddthread *_owner;

};


#endif
