Tekkotsu Homepage | Demos | Overview | Downloads | Dev. Resources | Reference | Credits |
PollThread.hGo to the documentation of this file.00001 //-*-c++-*- 00002 #ifndef INCLUDED_PollThread_h_ 00003 #define INCLUDED_PollThread_h_ 00004 00005 #ifdef PLATFORM_APERIOS 00006 # warning PollThread class is not Aperios compatable 00007 #else 00008 00009 #include "Thread.h" 00010 #include "Shared/TimeET.h" 00011 00012 //! description of PollThread 00013 class PollThread : public Thread { 00014 public: 00015 //! constructor 00016 PollThread() : Thread(), delay(0L), period(0L), startTime(0L), trackPollTime(false), initialPoll(false) {} 00017 //! constructor 00018 explicit PollThread(const TimeET& initial, const TimeET& freq, bool countPollTime, bool autostart=true) 00019 : Thread(), delay(initial), period(freq), startTime(0L), trackPollTime(countPollTime), initialPoll(true) 00020 { 00021 if(autostart) 00022 start(); 00023 } 00024 //! destructor 00025 ~PollThread() { 00026 if(isStarted()) { 00027 stop(); 00028 join(); 00029 } 00030 } 00031 00032 virtual void start(); 00033 00034 virtual bool getTrackPollTime() { return trackPollTime; } //!< returns #trackPollTime 00035 virtual void setTrackPollTime(bool countPollTime) { trackPollTime=countPollTime; } //!< sets #trackPollTime 00036 00037 protected: 00038 //! this is the function which will be called at the specified frequency, override it with your own functionality 00039 /*! @return true if run() should continue, false to stop the thread. 00040 * The default implementation calls runloop() and sets #period to its return value if that value is not -1U. 00041 * If the value is -1U, it returns false. Feel free to override this directly, instead of runloop(), 00042 * particularly if you don't intend to change period dynamically. */ 00043 virtual bool poll(); 00044 00045 //! called if a signal is sent while sleeping, should reset #delay to indicate remaining sleep time, relative to startTime 00046 /*! On return, #delay should be set such that #delay-startTime.Age() is remaining sleep time. In other words, 00047 * simply set #delay to the #period to maintain previously requested timing. 00048 * 00049 * This default implementation will set #delay to the remaining time needed to maintain current period setting. 00050 * Feel free to override and reset #period (or other member variables) if you need to change timing dynamically. 00051 * If the period is shortened such that poll() should have already occurred based on time of previous 00052 * call and the new period (plus any delay value), then poll() will be called immediately upon return. */ 00053 virtual void interrupted(); 00054 00055 virtual void * run(); 00056 //virtual void cancelled(); 00057 00058 //! called if a SIGALRM is sent (generally, by a call to interrupt()) 00059 static void handleInterrupt(int signal); 00060 00061 TimeET delay; //!< amount of time to delay between call to start() and first call to poll(), or if interrupt occurs after first poll(), amount of time to re-sleep 00062 TimeET period; //!< amount of time between calls to poll() -- if zero or negative, no delay will be made between calls (other than a call to testCancel()) 00063 TimeET startTime; //!< the time at which start() was called or the current period began 00064 bool trackPollTime; //!< if true, the time spent in poll() is subtracted from the next sleep time so frequency is fixed; if false, #period is added onto whatever time poll() takes 00065 bool initialPoll; //!< set to true after start until after first call to poll has completed 00066 }; 00067 00068 #endif //Aperios check 00069 00070 /*! @file 00071 * @brief 00072 * @author Ethan Tira-Thompson (ejt) (Creator) 00073 * 00074 * $Author: ejt $ 00075 * $Name: tekkotsu-4_0 $ 00076 * $Revision: 1.8 $ 00077 * $State: Exp $ 00078 * $Date: 2007/10/12 16:55:04 $ 00079 */ 00080 00081 #endif |
Tekkotsu v4.0 |
Generated Thu Nov 22 00:54:55 2007 by Doxygen 1.5.4 |