gxThread.h

Go to the documentation of this file.
00001 /*  Copyright (C) 2004  Guido Simone
00002  *
00003  *  This program is free software; you can redistribute it and/or modify
00004  *  it under the terms of the GNU General Public License as published by
00005  *  the Free Software Foundation; either version 2 of the License, or
00006  *  (at your option) any later version.
00007  *
00008  *  This program is distributed in the hope that it will be useful,
00009  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00010  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011  *  GNU General Public License for more details.
00012 
00013  *  You should have received a copy of the GNU General Public License
00014  *  along with this program; if not, write to the Free Software
00015  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00016  */
00017 
00018 #ifndef GXLIB_GXTHREADRUNNER_H
00019 #define GXLIB_GXTHREADRUNNER_H
00020 
00021 #include "../gx.h"
00022 #include "gxThreadSafeObject.h"
00023 
00028 class gxThreadRunnable
00029 {
00030 public:
00036    virtual void threadMain() = 0;
00037 
00042    virtual void onStopThreadRequest() = 0;
00043 };
00044 
00045 
00056 class gxThread : public gxThreadSafeObject
00057 {
00058 public:
00059 
00065    enum priority_t
00066    {
00067       PRIORITY_IDLE,
00068       PRIORITY_LOWEST,
00069       PRIORITY_BELOW_NORMAL,
00070       PRIORITY_NORMAL,
00071       PRIORITY_ABOVE_NORMAL,
00072       PRIORITY_HIGHEST,
00073       PRIORITY_TIME_CRITICAL,
00074    };
00075 
00076    enum states_t
00077    {
00078       STATE_STOPPED = 0,
00079       STATE_STARTING = 1,
00080       STATE_STARTED = 2,
00081       STATE_STOPPING = 3
00082    };
00083 
00084    gxThread( gxThreadRunnable * runnable, priority_t priority = PRIORITY_NORMAL );
00085 
00086    virtual ~gxThread();
00087 
00092    void start( bool wait = true );
00093 
00099    void stop();
00100 
00106    virtual void run();
00107 
00115    virtual void onStopThreadRequest();
00116 
00120    bool isStopping();
00121 
00125    states_t getState();
00126 
00130    static void sleep( long milliseconds );
00131 
00132 private:
00133    static unsigned int __stdcall threadFunc( void * );
00134    gxThreadRunnable * m_runnable;
00135    unsigned int m_threadid;
00136    void * m_hThread;
00137 
00138    states_t   m_state;
00139    priority_t m_priority;
00140 
00141    void setState( states_t newState );
00142 
00143 };
00144 #endif

Generated on Mon Nov 21 01:01:35 2005 for gxLib by  doxygen 1.4.5