Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CAT/CATThread.h Source File

CATThread.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------
00002 /// \file    CATThread.h
00003 /// \brief   Base Thread Class
00004 /// \ingroup CAT
00005 ///
00006 /// Copyright (c) 2003-2008 by Michael Ellison.
00007 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00008 ///
00009 // $Author: mikeellison $
00010 // $Date: 2008-01-23 08:59:02 -0600 (Wed, 23 Jan 2008) $
00011 // $Revision:   $
00012 // $NoKeywords: $
00013 //---------------------------------------------------------------------------
00014 
00015 #ifndef CATThread_H
00016 #define CATThread_H
00017 #include "CATInternal.h"
00018 
00019 /// \class   CATThread
00020 /// \brief   Base Thread Class
00021 /// \ingroup CAT
00022 ///
00023 /// CATThread is your basic thread class.  You can derive classes from it or
00024 /// use as-is with a user-defined CATTHREADPROC
00025 class CATThread
00026 {
00027     public:
00028         typedef  void (*CATTHREADPROC)(void *param, CATThread* theThread);
00029 
00030         /// Thread construction
00031         CATThread();
00032 
00033         /// Thread destruction
00034         virtual ~CATThread();
00035         
00036         /// Start a thread. This is the one used if you're deriving from
00037         /// CATThread for your own threaded class.  Override ThreadFunction()
00038         /// for your subclass...
00039         virtual  bool Start(void *param);
00040 
00041         /// Start a thread procedure.  You can use this directly w/o deriving
00042         /// just by creating your procedure from the CATTHREADPROC prototype.
00043         virtual  bool StartProc(CATTHREADPROC proc, void* param);
00044         
00045         /// Wait until the thread stops or the timer times out.
00046         /// If successful, clears the thread handle. Start or StartProc must
00047         /// be called before other thread commands are used.
00048         virtual  bool WaitStop(CATUInt32  timeout  = (CATUInt32)-1,
00049                                CATUInt32* exitCode = 0);
00050 
00051         /// Forces a thread to stop - use sparingly.  As WaitStop does, this
00052         /// one clears the thread handle.  Start or StartProc must be called
00053         /// prior to calling other commands after ForceStop is issued.
00054         virtual  void ForceStop();
00055 
00056         /// Pause the thread. Thread must have been started before use.
00057         virtual  bool Pause();
00058 
00059         /// Resume the thread. Thread must have been started before use.
00060         virtual  bool Resume();
00061         
00062     protected:
00063         /// Thread function - either override this if you are deriving
00064         /// from the class, or leave as is and it will call the CATTHREADPROC
00065         /// procedure from a StartProc, then exit.
00066         virtual void ThreadFunction();
00067 
00068         /// OS specific thread - note, the param is NOT the user param, 
00069         /// rather it is a pointer to the thread object....
00070         static unsigned int _stdcall W32ThreadProc(void *param);
00071 
00072         CATUInt32       fThreadId;          ///< thread id
00073         HANDLE          fThreadHandle;      ///< Thread handle
00074         CATTHREADPROC   fCallback;          ///< Callback
00075         void*           fUserParam;         ///< User parameter for thread
00076 };
00077 
00078 #endif //CATThread_H

Generated on Mon Feb 11 04:09:49 2008 for Game Accessibility Suite by doxygen 1.5.4