/*
 * Copyright (c) 2005-2006 Tom N Harris.
 *
 *     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.
 *
 *     A copy of the GNU General Public License can be found at
 *     http://www.gnu.org/
 *
 * Written by Tom N Harris <telliamed@whoopdedo.org>
 *
 */

#ifndef SETUP_THREAD_H
#define SETUP_THREAD_H

#include "win32.h"

namespace Setup
{

class Thread
{
private:
	HANDLE m_handle;
	DWORD m_threadId;

	static unsigned __stdcall thread_callback(void* data);

public:
	Thread();
	virtual ~Thread();

	bool operator!() const
		{ return m_handle == 0; };

protected:
	virtual void run() = 0;

public:
	virtual void start();
	virtual void stop(DWORD exit_code = 0);
	virtual void suspend();
	virtual void resume();

protected:
	virtual void exit(DWORD exit_code = 0);

public:
	bool isCurrentThread() const;
	bool isAlive() const;
	DWORD getExitCode() const;

	int getPriority() const;
	void setPriority(int);

	bool waitForExit(DWORD time = 0);

	static void sleep(DWORD time = 0);
	static void wait(DWORD time = 0);
};

};

#endif
