/**
 * @file
 * $Id$
 * $Revision$
 * $Author$
 * $Date$
 *
 * This file is part of The iWear Framework.
 *
 * The iWear Framework 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 as in version 2 of the License.

 * 
 * The iWear Framework 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 the GNU General Public License for
 * more details.
 * 
 * You should have received a copy of the GNU General Public License along with
 * The iWear Framework; if not, write to the Free Software Foundation, Inc., 59
 * Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __IWEAR_THREADEXECUTOR_H
#define __IWEAR_THREADEXECUTOR_H

#ifndef __IWEAR_THREAD_H
#include <iwear/thread.h>
#endif

#ifndef __IWEAR_FUNCTOR_H
#include <iwear/functor.h>
#endif

namespace iwear
{

/**
 * The ThreadExecutor can execute a Functor<void> in another thread.
 */
class ThreadExecutor
{
private:
    /**
     * Internal self-deleting helper Thread class that will be used to do the
     * actual call to the functor in a thread.
     */
    class ExecutorThread : public Thread
    {
	private:
	    /**
	     * The functor to be executed.
	     */
	    Functor<void>& func;
	protected:
	    virtual void Run( void );
	    virtual void Final( void );
	public:
	    virtual ~ExecutorThread( );
	    ExecutorThread( Functor<void>&, EventDispatcher& );
    };
public:
    /**
     * To easily execute a Functor<void> in another thread, you can pass it to
     * this function. It will internally execute the functor in a thread.
     */
    static void execute( Functor<void>& func, EventDispatcher& );
};    
}

#endif
