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) 00019 : Thread(), delay(initial), period(freq), startTime(0L), trackPollTime(countPollTime), initialPoll(true) 00020 {} 00021 //! destructor 00022 ~PollThread() { 00023 if(isStarted()) { 00024 stop(); 00025 join(); 00026 } 00027 } 00028 00029 virtual void start(); 00030 00031 virtual bool getTrackPollTime() { return trackPollTime; } //!< returns #trackPollTime 00032 virtual void setTrackPollTime(bool countPollTime) { trackPollTime=countPollTime; } //!< sets #trackPollTime 00033 00034 protected: 00035 //! this is the function which will be called at the specified frequency, override it with your own functionality 00036 /*! @return true if run() should continue, false to stop the thread. 00037 * The default implementation calls runloop() and sets #period to its return value if that value is not -1U. 00038 * If the value is -1U, it returns false. Feel free to override this directly, instead of runloop(), 00039 * particularly if you don't intend to change period dynamically. */ 00040 virtual bool poll(); 00041 00042 //! called if a signal is sent while sleeping, should reset #delay to indicate remaining sleep time, relative to startTime 00043 /*! On return, #delay should be set such that #delay-startTime.Age() is remaining sleep time. In other words, 00044 * simply set #delay to the #period to maintain previously requested timing. 00045 * 00046 * This default implementation will set #delay to the remaining time needed to maintain current period setting. 00047 * Feel free to override and reset #period (or other member variables) if you need to change timing dynamically. 00048 * If the period is shortened such that poll() should have already occurred based on time of previous 00049 * call and the new period (plus any delay value), then poll() will be called immediately upon return. */ 00050 virtual void interrupted(); 00051 00052 virtual void * run(); 00053 //virtual void cancelled(); 00054 00055 //! called if a SIGALRM is sent (generally, by a call to interrupt()) 00056 static void handleInterrupt(int signal); 00057 00058 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 00059 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()) 00060 TimeET startTime; //!< the time at which start() was called or the current period began 00061 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 00062 bool initialPoll; //!< set to true after start until after first call to poll has completed 00063 }; 00064 00065 #endif //Aperios check 00066 00067 /*! @file 00068 * @brief 00069 * @author Ethan Tira-Thompson (ejt) (Creator) 00070 */ 00071 00072 #endif |
Tekkotsu v5.1CVS |
Generated Mon May 9 04:58:49 2016 by Doxygen 1.6.3 |